How do I fix this grads script?

345 Views Asked by At

This is my gs file.

'xloc = aminlocx(slp,lon=120,lon=135,lat=20,lat=30)'
'yloc = aminlocy(slp,lon=120,lon=135,lat=20,lat=30)'

'lonn = 39.58386 + 0.22522523*(xloc-1)'
'latt = -8.64826 + 0.22522523*(yloc-1)'

'lonmin = lonn-1'
'lonmax = lonn+1'
'latmin = latt-1'
'latmax = latt+1'

'q w2xy   'lonmin' 'latmin
xpos1=subwrd(result,3)
ypos1=subwrd(result,6)

'q w2xy  'lonmax' 'latmax
xpos2=subwrd(result,3)
ypos2=subwrd(result,6)

'set line 2 1 6'  
'draw rec 'xpos1' 'ypos1' 'xpos2' 'ypos2

And I got error like this

Query Error: Syntax is QUERY W2XY Lon Lat

Query Error: Syntax is QUERY W2XY Lon Lat

DRAW error: Syntax is DRAW REC xlo ylo xhi yhi

How do I fix it?

1

There are 1 best solutions below

0
binzo On

It should be noted that there are two types of variables in the GrADS script. One is a script variable and the other is a GrADS variable. The former variable must be outside of the quotes and the latter is referenced inside the quotes. For example, in the following line of your script

'q w2xy 'lonmin' 'latmin'

lonmin and latmin are treated as script variables. On the other hand, in the following line

'xloc = aminlocx(cmsk,lon=120,lon=135,lat=20,lat=30)' 

xloc is treated as a GrADS variable.

Now, if you want to get xloc as a script variable, you can write as the following.

'd aminlocx(cmsk,lon=120,lon=135,lat=20,lat=30)' 
xloc = subwrd(result,4)

Alternatively, for contexts where display is not allowed, you can also write as the following.

'xloc = aminlocx(cmsk,lon=120,lon=135,lat=20,lat=30)' 
'q defval xloc 1 1'
xloc = subwrd(result,3)

Finally, your script will be rewritten like this.

'd aminlocx(cmsk,lon=120,lon=135,lat=20,lat=30)' 
xloc = subwrd(result,4)
'd aminlocy(cmsk,lon=120,lon=135,lat=20,lat=30)'
yloc = subwrd(result,4)

lonn = 120.0 + 0.22522523*(xloc-1)
latt = 20.0 + 0.22522523*(yloc-1)

lonmin = lonn-1
lonmax = lonn+1
latmin = latt-1
latmax = latt+1

'q w2xy   'lonmin' 'latmin
xpos1=subwrd(result,3)
ypos1=subwrd(result,6)
'q w2xy   'lonmax' 'latmax
xpos2=subwrd(result,3)
ypos2=subwrd(result,6)

'set line 2 1 6'  
'draw rec 'xpos1' 'ypos1' 'xpos2' 'ypos2