[gradsusr] Utilizing data from text file to make calculation in GrADS

Charles Seman - NOAA Federal charles.seman at noaa.gov
Thu Feb 21 14:49:54 EST 2013


Phil,

 From http://grads.iges.org/grads/gadoc/script.html#intrinsic
---
read (filename)
This functions reads individual records from file filename. Repeated 
calls must be made to read consecutive records. The result is a string 
containing two lines: the first line is the return code, the 2nd line is 
the record read from the file. The record may be a maximum of 80 
characters. Use the sublin function to separate the result. Return codes 
are:

     0 - ok
     1 - open error
     2 - end of file
     8 - file open for write
     9 - I/O error

Files are opened when the first call to read is made for a particular 
file name. Files are closed when the execution of the script file 
terminates (note that files remain open between function calls, etc).
---

Try something like this in your script:
...
res = read(input)
rc = sublin(res,1)
if ( rc != 0 )
   say 'return code is: 'rc
   exit
endif
rec = sublin(res,2)
...

also, check on "looptime" vs "time" for loop counter...

Hope this helps,
Chuck


On 02/21/2013 01:03 PM, Phil Klotzbach wrote:
> Hi everyone,
>
> I am currently running GrADS 2.0.1 on my Windows 7 laptop.  What I have
> is a simple text file with three columns, a longitude, a latitude, and a
> time (since 1979 at 0Z).  When I attempt to run the code in GrADS, I get
> the following error message:
>
> Set error: Missing or invalid arguments for LON option
> Non-numeric args to numeric operations
> Error occurred on line 18
> In file /cygdrive/c/OPENGR~1/Contents/Resources/Scripts/readfile.gs
>
> The strange thing is, I can check and see that latitude has been set
> correctly by GrADS.  It just has problems with longitude and time. I
> used the three say commands to verify that it has read in the variables
> correctly (which it has).
>
> The following is my code as currently written:
>
> input = 'c:\test.txt'
> 'open c:\500mbtemp.ctl'
> looptime = 1
> while (looptime < 3)
> rec = read(input)
> pointlon = substr(rec, 2, 7)
> pointlat = substr(rec, 10, 7)
> pointtime = substr(rec, 17, 2)
> say pointlon
> say pointlat
> say pointtime
> 'set lat 'pointlat''
> 'set lon 'pointlon''
> 'set t 'pointtime''
> 'd temp'
> answer=result
> res=write("c:\500mbtemp.txt",answer)
> time=time+1
> endwhile
>
> Here are the contents of c:\test.txt
>
> 150.00 -16.75 5
> 149.25 -22.50 7
>
> Lastly c:\500mbtemp.ctl is an ERA-Interim 500 mb temperature file. I
> have verified manually that the file opened correctly and is working
> properly.   I know the GrADS treats all variables read from text files
> as strings, and I'm guessing that this is what is causing the problem
> here.  Any insights into how this problem can be solved are much
> appreciated!  Thanks!
>
> Phil
>

-- 

Please note that Charles.Seman at noaa.gov should be considered my NOAA
email address, not cjs at gfdl.noaa.gov.

********************************************************************
  Charles Seman                                Charles.Seman at noaa.gov
  U.S. Department of Commerce / NOAA / OAR
  Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
  201 Forrestal Road                              fax: (609) 987-5063
  Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not reflect any
official or unofficial position of the United States Federal Government,
the United States Department of Commerce, or NOAA."



More information about the gradsusr mailing list