help needed with ascii output

Eric Tiong eric at OFFSHOREWEATHER.COM.AU
Thu Sep 1 17:43:53 EDT 2005


Hi Matt,

First, to remove "Unknown command: 0" error (which is harmless), use rs=write(filename,variable [,append]). Write has a return value! I have a script below that write text outputs in columns. If you are using Window XP, You need to use Wordpad to see the columns and line breaks. Otherwise use unix2dos to convert the file to DOS format.
 
Cheers,
Eric Tiong

*  extract GFS vertical wind profile for way points
*
*  tau=1(+00), 2(+03) 3(+06),...
*  lat/lon in nearest degree
*  fileName is output file name
function upper(site)
  if (site= '')
     say 'correct use is: mg [tau lat lon fileName]'
     return
  endif
  rcd = subwrd(site,1)
  lat = subwrd(site,2) 
  lon = subwrd(site,3)
   fl = subwrd(site,4)
  xi=lon - 94
  yj=lat + 11
  i=math_nint(xi)
  j=math_nint(yj)
  lcn = 'Site: ' % math_format('%5.1f',lat) % ' ' % math_format('%6.1f',lon)
 'set lat 'lat
 'set lon 'lon
 'set t 'rcd
 'q time'
  tds = subwrd(result,3)
  hdr = 'Level      wind'
  rs=write(fl,lcn)
  rs=write(fl,tds,append)
  rs=write(fl,hdr,append)
  fmt4 = '%3.0f'; fmt5 = '%02.0f'
* 925hPa 
 'set lev 925'
  lvl = "925mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
* 850hPa 
 'set lev 850'
  lvl = "850mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
* 700hPa 
 'set lev 700'
  lvl = "700mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
* 500hPa 
 'set lev 500'
  lvl = "500mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
* 400hPa 
 'set lev 400'
  lvl = "400mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
* 300hPa 
 'set lev 300'
  lvl = "300mb"
 'd u'
  v1 = subwrd(result,4)
 'd v'
  v2 = subwrd(result,4)
  sp = math_sqrt(v1*v1+v2*v2) * 1.95
  dw = math_atan2(-v1,-v2) * 180.0/3.1416  +360.0
  if (dw>360.0)
      dw=dw-360.0
  endif
  rr=lvl % '    ' % math_format(fmt4,dw) % '/' % math_format(fmt5,sp)
  rs=write(fl, rr, append)
  rs=close(fl)
return

----- Original Message ----- 
From: "M P Borkow" <mpborkow at NCSU.EDU>
To: <GRADSUSR at LIST.CINECA.IT>
Sent: Friday, September 02, 2005 5:38 AM
Subject: Re: help needed with ascii output


> Thanks for the response,
> 
> Your script as written didn't work for me.  I had this same problem
> yesterday when I tried to use the write command, I just get "Unknown
> command: 0".  Even if I don't get that working, I still am unsure of how
> to rewrite it to include a 'd lat' and 'd lon' command.
> 
> -Matt
> 
> 
> > Hi Matt
> >     I work extensively with grads writing text and have found that the
> > following method, while not elegant is for me most effective, have a
> > look at my old positing below and apply to your problem. essentially
> > what I posted is an idiots' version of Jennifer's' script but is
> > probably easier to understand.
> >     You will need to assign values to each variable then create the line
> > before writing the file.
> >     Have a look at the script then give me some specifics and I'll give
> > you a hand.
> >     Cheers
> >        JP
> >
> >
> >
> > Hi
> >    fwrite will produce a binary file, you need to write a script,
> > somthing like the following for ascii, using the write command:
> >
> > function main(args)
> > i = 1
> > while i <= 249
> > 'set t ' i
> > 'd htsgwsfc'
> > Val=subwrd(result,4)
> > write (Valuedir.txt,Val, append)
> > i = i + 1
> > endwhile
> >
> >
> > Good Luck
> >    Jean Pierre
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20050902/722e24c7/attachment.html 


More information about the gradsusr mailing list