GRADSUSR Digest - 25 Jun 2009 to 26 Jun 2009 (#2009-161)

Javier G. Corripio Javier.Corripio at UIBK.AC.AT
Sat Jun 27 03:43:49 EDT 2009


>
>
> I ran the following script but got the error - Data request
> warning: Request
> beyond file limits.
>
> Can anyone point out where the mistake is?
>
> Muhammad Rahiz
> GrADS v1.9b4 @ Fedora 10
> ---------------------------
>
> 'open rf.tmp.ctl'
> 'set lon 46.25 114.26'
> 'set lat -5.07 45.6'
> 'set t 1'
> 'set gxout fwrite'
> * total number of months
> mtot = 353
> * month index
> m = 1
> while(m<=mtot)
> res = read('timeseries.txt')
> say t1' 't2
> t1 = sublin(res,1)
> t2 = sublin(res,2)
> * calculate the four digit year
> yyyy = 1960
> * calculate the two digit month
> mm = 10
> fout = 'tmp.'yyyy''mm'.bin'
> 'set fwrite 'fout
> 'define tmon = ave(t,t='t1',t='t2')'
> 'disable fwrite'
> m = m + 1
> endwhile
>
> -----------------------------
> DSET ^rf.tmp
> UNDEF -1.e34
> XDEF 303 LINEAR 46.25 0.225198675496689
> YDEF 226 LINEAR -5.07 0.2252
> ZDEF 1 LEVELS 1008.23
> TDEF 42985 LINEAR 06Z01OCT1960 360mn
> VARS 1
> t 0 99 t
> ENDVARS
>

Muhammad,

Firts, you are "saying" t1 and t2 before defining them.
Second, the first line of a read command is the return code, not the
content of the file

You probably want to write something like this:

fname='timeseries.txt'
rec = read(fname)
IO = sublin(rec,1)
if (IO = 1) ; say fname ' file open error' ; return ; endif
record = sublin(rec,2)
if (IO = 0)
   field1 = subwrd(record,1)
   field2 = subwrd(record,2)
......
endif


-------------
http://www.iges.org/grads/gadoc/script.html

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).
--------------------------------------------------------

Best,

Javier

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20090627/45170750/attachment.html 


More information about the gradsusr mailing list