[gradsusr] Writing to a world file as a text file

Stephen Woodbridge stephenwoodbridge37 at gmail.com
Fri Mar 26 21:43:14 EDT 2021


Ok, to answer my own question, I was able to get this to work using a 
script as follows:

$ cat t.gs
'reinit'

'sdfopen ./a.nc'

'set gxout print'
'set prnopts %0.6f 1 1'

region='altocn'

if(region = 'altocn');
   lat1=0.0
   lat2=55.0
   lon1=260.0
   lon2=310.0
   dx=lon2-lon1
   dy=lat2-lat1
   xpix=5000
   ypix=xpix/dx*dy
else;
   region='wcoast'
   lat1=25.0
   lat2=50.0
   lon1=210.0
   lon2=250.0
   dx=lon2-lon1
   lon2=250.0
   dx=lon2-lon1
   dy=lat2-lat1
   xpix=5000
   ypix=xpix/dx*dy
endif

* Create World File
latrange=lat2-lat1
lonrange=lon2-lon1
latpixelsize=-latrange/ypix
lonpixelsize=lonrange/xpix*2.0
xwld=lon1-360.0
ywld=lat2

say 'CREATING WORLD FILE:'
say lonpixelsize
say '0.0'
say '0.0'
say latpixelsize
say xwld
say ywld
say '---------------------'

rc=write('tmpprs.dat',lonpixelsize)
rc=write('tmpprs.dat',0.0,append)
rc=write('tmpprs.dat',0.0,append)
rc=write('tmpprs.dat',latpixelsize,append)
rc=write('tmpprs.dat',xwld,append)
rc=write('tmpprs.dat',ywld,append)

'reinit'

quit

$ cat tmpprs.dat
0.02
0.0
0.0
-0.01
-100
55.0

-Steve

On 3/26/2021 8:33 PM, Stephen Woodbridge wrote:
> Hi,
>
> I have a script that creates images and I want to create a *.wld file 
> to go with the image, but all the examples that I try interactively in 
> grads don't work. I currently just display the values from the script 
> like:
>
> say 'CREATING WORLD FILE:'
> say lonpixelsize
> say '0.0'
> say '0.0'
> say latpixelsize
> say xwld
> say ywld
> say '---------------------'
>
> But testing interactively with:s
>
> grads -bl
> sdfopen ./a.nc
> Scanning self-describing file:  ./a.nc
> SDF file ./a.nc is open as file 1
> LON set to -100 -50
> LAT set to 0 55
> LEV set to 0 0
> Time values set: 2021:3:25:18 2021:3:25:18
> E set to 1 1
> ga-> say '0.0'
> Unknown command: say
> ga-> set gxout print
> ga-> set prnopts %10.6f 1 1
> ga-> d 10.1
> Printing Grid -- 1 Values -- Undef = -9.99e+08
>  10.100000
> ga-> write(test.txt,result,append)
> Unknown command: write(test.txt,result,append)
> ga-> write('test.txt',result,append)
> Unknown command: write('test.txt',result,append)
>
> My idea here is to create the world file which in basically 6 floats 
> written one per line in the file.
>
> I'm obviously not doing something wrong here.
>
> Thanks,
>   -Steve


-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the gradsusr mailing list