<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Systemfunc can do this, but it would be messy.  Let's try something in native NCL.</div><div><br></div><div>It would be helpful to have a custom function to make fixed length strings.  There are enough tricks and nuances that it is easier to just write this up, rather than explain how to do it.  You can put this function into your private library, and use it any time you need more fixed length strings.</div><div><br></div><div><div><div>undef ("fixed_left")</div><div>function fixed_left (str, length)</div><div>local blanks</div><div>begin</div><div>   blanks = new (length, "character")</div><div>   blanks = tochar (" ")</div><div>   return (str_get_cols (str+tostring(blanks), 0, length-1))</div><div>end</div></div><div><br></div><div>begin</div><div>   longi   = -104.67</div><div>   lati      =   39.85</div><div>   string1 = "DENVER/STAPLETON INT., CO. / U.S.A."</div><div>   string2 = sprintf ("%20.5f", longi) \</div><div>              + sprintf ("%20.5f", lati) \</div><div>              + fixed_left (string1, 40)</div><div>   print ("[" + string2 + "]")</div><div>end</div></div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jan 17, 2021 at 8:22 PM 时光足迹 via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div>Hi, <br></div><div>  I have trouble writing formatted string using NCL. <br></div><div><br></div><div>  As I typed: system("printf "+dq+"%-40s"+dq+" "+ dq+"DENVER/STAPLETON INT., CO. / U.S.A."+dq), output showed DENVER/STAPLETON INT., CO. / U.S.A. ;</div><div><br></div><div>  I wanted to store the output to a variable, so I changed the command to: print(systemfunc("printf "+dq+"%-40s"+dq+" "+ dq+"DENVER/STAPLETON INT., CO. / U.S.A."+dq)), however, I got missing. <br></div><div><br></div><div>  What the matter with 'systemfunc' here?  <br></div><div><br></div><div> ---------------------------------------------------------------------</div><div><br></div><div>  Here are Fortran codes to write formatted string: <br></div><div> </div><div>       WRITE(fout, '(2f20.5,A40)') longi, lati, STRING1</div><div><br></div><div>  I tried write_table to write, but spaces will be automaticlly inserted between different kind of varibles.</div><div><br></div><div>  Is there any efficient way to write formatted string the same as Fortran? </div><div><br></div><div>  Thanks,</div><div><br></div><div>  HUANG</div></blockquote></div></div></div></div>