[gradsusr] Need Help with GrADS

James T. Potemra jimp at hawaii.edu
Thu Mar 7 13:53:05 EST 2019


When you open more than one file, you'll need to address the variables 
in subsequent files explicitly, e.g., 'd t.1', 'd t.2', etc.  Try check out

http://gradsaddict.blogspot.com/2013/06/tutorial-tips-on-handeling-more-than-1.html

https://stackoverflow.com/questions/42464138/opening-multiple-file-in-grads

http://www.jamstec.go.jp/frsgc/research/iprc/nona/GrADS/use-two-files.html

Jim

On 3/7/19 8:34 AM, Yazeed Alsubhi wrote:
> Hello James,
>
> I have tried you suggestions and still have problems with this script. 
> Please see the following script as well as the figure produced by this 
> script, the figure is 2 by 2 but these plots are the same and the same 
> time series.
>
> 'reinit'
>
> rc = gsfallow("on")
>
> nrows=2
>
> ncols=2
>
> args=nrows%' '%ncols
>
> *'sdfopen air.2008.nc <http://air.2008.nc>'
>
> 'set mproj scaled'
>
> panels(args)
>
> *p is the panels number, p=1 means the first panel
>
> p = 1
>
> i = 1
>
> *ptot indicates the total number of panels (or virtual pages)
>
> ptot = nrows * ncols
>
> while (p <= ptot)
>
> while (i <= 4)
>
> *here is the loop, draw panel one by one
>
> *_vpg.p
>
> _vpg.p
>
> if ( i = 1 )
>
> 'sdfopen 
> C:\Users\yalsubhi\Desktop\EraInterim\cases\Case1\ggap200806090000.nc 
> <http://ggap200806090000.nc>'
>
> else
>
> 'q time'
>
> res=subwrd(result,3)
>
> hh=substr(res,1,3)
>
> dd=substr(res,4,2)
>
> mm=substr(res,6,3)
>
> yy=substr(res,9,4)
>
> endif
>
> if ( i = 2 )
>
> 'sdfopen 
> C:\Users\yalsubhi\Desktop\EraInterim\cases\Case1\ggap200806090600.nc 
> <http://ggap200806090600.nc>'
>
> else
>
> 'q time'
>
> res=subwrd(result,3)
>
> hh=substr(res,1,3)
>
> dd=substr(res,4,2)
>
> mm=substr(res,6,3)
>
> yy=substr(res,9,4)
>
> endif
>
> if ( i = 3 )
>
> 'sdfopen 
> C:\Users\yalsubhi\Desktop\EraInterim\cases\Case1\ggap200806091200.nc 
> <http://ggap200806091200.nc>'
>
> else
>
> 'q time'
>
> res=subwrd(result,3)
>
> hh=substr(res,1,3)
>
> dd=substr(res,4,2)
>
> mm=substr(res,6,3)
>
> yy=substr(res,9,4)
>
> endif
>
> if ( i = 4 )
>
> 'sdfopen 
> C:\Users\yalsubhi\Desktop\EraInterim\cases\Case1\ggap200806091800.nc 
> <http://ggap200806091800.nc>'
>
> else
>
> 'q time'
>
> res=subwrd(result,3)
>
> hh=substr(res,1,3)
>
> dd=substr(res,4,2)
>
> mm=substr(res,6,3)
>
> yy=substr(res,9,4)
>
> endif
>
> 'set parea 1 9.8 1 7.5'
>
> 'set grads off'
>
> 'set mpdset hires'
>
> 'set lat 10 45'
>
> 'set lon -60 65'
>
> 'set lev 850'
>
> 'set gxout shaded'
>
> 'set cint 2'
>
> 'd t'
>
> 'run cbar'
>
> 'set font 0'
>
> 'set strsiz 0.15 0.15'
>
> 'draw title ('hh' 'dd'/'mm'/'yy')'
>
> p = p + 1
>
> i = i + 1
>
> endwhile
>
> endwhile
>
> 'set vpage off'
>
> 'set strsiz 0.15'
>
> 'draw string 5.3 8.3 Air Temperature'
>
> 'printim AirTemperature.png x800 y600 white'
>
> 'c'
>
>
> Thanks,
>
> Yazeed
>
>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> 
> 	Virus-free. www.avg.com 
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> 
>
>
>
> On Wed, Mar 6, 2019 at 7:02 PM Yazeed Alsubhi <yalsubhi at nevada.unr.edu 
> <mailto:yalsubhi at nevada.unr.edu>> wrote:
>
>     Ok, I'll try that.
>
>     Thanks,
>     Yazeed
>
>     On Wed, Mar 6, 2019 at 7:00 PM James T. Potemra <jimp at hawaii.edu
>     <mailto:jimp at hawaii.edu>> wrote:
>
>         If you want to plot all the panels for one time, then do the
>         same thing for the next time, the "i loop" should be outside
>         the "p loop".  Alternately if you want all the time plots in
>         each panel, put the "i loop" within the "p loop".  Either way
>         you want two nested while loops.
>
>         On 3/6/19 4:46 PM, Yazeed Alsubhi wrote:
>>         Hi Jim,
>>
>>         Should I add this new loop in the same loop for the panel
>>         plots (while(p<=ptot)? Thanks for your help
>>
>>         Thanks,
>>         Yazeed
>>
>>         On Wed, Mar 6, 2019 at 6:40 PM James T. Potemra
>>         <jimp at hawaii.edu <mailto:jimp at hawaii.edu>> wrote:
>>
>>             Hi Yazeed,
>>
>>             You have two problems.  First, you have a single while
>>             loop (while (p <= ptot)), presumably for the different
>>             panels.  You will need another while loop over "i"
>>             (forecast time?).
>>
>>             Second, the file names have 4-character strings (0000,
>>             0600, 1200, and 1800).  Your variable "i" is an integer,
>>             so it will be 0, 6, 12 and 18. In other words, the script
>>             will be looking for files of the form ggap200806080.nc
>>             <http://ggap200806080.nc> ggap200806086.nc
>>             <http://ggap200806086.nc> ggap2008060812.nc
>>             <http://ggap2008060812.nc> and ggap200806081800.nc
>>             <http://ggap200806081800.nc>. You can either pad this
>>             out, or just explicitly give the file name:
>>
>>             i = 1
>>             while ( i <=4 )
>>               if ( i = 1 ); 'sdfopen C:\Users\yalsubhi\Desktop
>>             \EraInterim\cases\Case1\ggap200806080000.nc
>>             <http://ggap200806080000.nc>'; endif
>>               if ( i = 2 ); 'sdfopen C:\Users\yalsubhi\Desktop
>>             \EraInterim\cases\Case1\ggap200806080600.nc
>>             <http://ggap200806080600.nc>'; endif
>>               if ( i = 3 ); 'sdfopen C:\Users\yalsubhi\Desktop
>>             \EraInterim\cases\Case1\ggap200806081200.nc
>>             <http://ggap200806081200.nc>'; endif
>>               if ( i = 4 ); 'sdfopen C:\Users\yalsubhi\Desktop
>>             \EraInterim\cases\Case1\ggap200806081800.nc
>>             <http://ggap200806081800.nc>'; endif
>>               i = i + 1
>>             endwhile
>>
>>             or,
>>
>>             i = 1
>>             while ( i <= 18 )
>>               infile = 'ggap200806080'i'00.nc <http://00.nc>'
>>               if ( i > 9 ); infile = 'ggap20080608'i'00.nc
>>             <http://00.nc>'; endif
>>               'sdfopen C:\Users\yalsubhi\Desktop
>>             \EraInterim\cases\Case1\'infile
>>               i = i + 6
>>             endwhile
>>
>>
>>             Jim
>>
>>             On 3/6/19 11:14 AM, Yazeed Alsubhi wrote:
>>>
>>>             Hello James,
>>>
>>>             I am struggling with my GrADS scripts and I really need
>>>             your help. I have tried to draw multi-panel plots using
>>>             GrADS and I got the correct script, as following:
>>>
>>>             'reinit'
>>>
>>>             rc = gsfallow("on")
>>>
>>>             nrows=2
>>>
>>>             ncols=2
>>>
>>>             args=nrows%' '%ncols
>>>
>>>             'sdfopen air.2008.nc <http://air.2008.nc/>'
>>>
>>>             'set mproj scaled'
>>>
>>>             panels(args)
>>>
>>>             *p is the panels number, p=1 means the first panel
>>>
>>>             p = 1
>>>
>>>             *ptot indicates the total number of panels (or virtual
>>>             pages)
>>>
>>>             ptot = nrows * ncols
>>>
>>>             *here is the loop, draw panel one by one
>>>
>>>             while (p <= ptot)
>>>
>>>             *_vpg.p
>>>
>>>                  _vpg.p
>>>
>>>                  'set parea 1 9.8 1 7.5'
>>>
>>>                  'set t 'p
>>>
>>>                  'set grads off'
>>>
>>>                  'set mpdset hires'
>>>
>>>                  'set lat 10 45'
>>>
>>>                  'set lon -60 65'
>>>
>>>                  'set lev 850'
>>>
>>>                  'set gxout shaded'
>>>
>>>                  'set cint 2'
>>>
>>>                  'd air'
>>>
>>>                  'q time'
>>>
>>>              res=subwrd(result,3)
>>>
>>>              hh=substr(res,1,3)
>>>
>>>              dd=substr(res,4,2)
>>>
>>>              mm=substr(res,6,3)
>>>
>>>              yy=substr(res,9,4)
>>>
>>>                  'run cbar'
>>>
>>>                  'set font 0'
>>>
>>>                  'set strsiz 0.15 0.15'
>>>
>>>                  'draw title ('hh' 'dd'/'mm'/'yy')'
>>>
>>>             p = p + 1
>>>
>>>             endwhile
>>>
>>>                  'set vpage off'
>>>
>>>             'set strsiz 0.15'
>>>
>>>             'draw string 5.3 8.3 Air Temperature'
>>>
>>>             'printim AirTemperature.png x800 y600 white'
>>>
>>>             And the problem is that I am trying to do this for more
>>>             than on files in the same folder. And I am trying to
>>>             implement a while loop that will automatically insert
>>>             each file (0000, 0600, 1200, and 1800) and the names of
>>>             these files are: ggap200806080000.nc
>>>             <http://ggap200806080000.nc/> ggap200806080600.nc
>>>             <http://ggap200806080600.nc/> ggap200806081200.nc
>>>             <http://ggap200806081200.nc/> and ggap200806081800.nc
>>>             <http://ggap200806081800.nc/>
>>>
>>>             So I tried the same code but I added some lines:
>>>
>>>             'reinit'
>>>             rc = gsfallow("on")
>>>             nrows=2
>>>             ncols=2
>>>             args=nrows%' '%ncols
>>>
>>>             *This is the direction of these netcdf files:
>>>             *'sdfopen C:\Users\yalsubhi\Desktop
>>>             \EraInterim\cases\Case1\ggap200806080000.nc
>>>             <http://ggap200806080000.nc/>'
>>>             *'sdfopen C:\Users\yalsubhi\Desktop
>>>             \EraInterim\cases\Case1\ggap200806080600.nc
>>>             <http://ggap200806080600.nc/>'
>>>             *'sdfopen C:\Users\yalsubhi\Desktop
>>>             \EraInterim\cases\Case1\ggap200806081200.nc
>>>             <http://ggap200806081200.nc/>'
>>>             *'sdfopen C:\Users\yalsubhi\Desktop
>>>             \EraInterim\cases\Case1\ggap200806081800.nc
>>>             <http://ggap200806081800.nc/>'
>>>
>>>             'set mproj scaled'
>>>             panels(args)
>>>             *p is the panels number, p=1 means the first panel
>>>             p = 1
>>>             i = 0000
>>>             *ptot indicates the total number of panels (or virtual
>>>             pages)
>>>             ptot = nrows * ncols
>>>             *here is the loop, draw panel one by one
>>>             while (p <= ptot)
>>>             *_vpg.p
>>>                  _vpg.p
>>>                  'set parea 1 9.8 1 7.5'
>>>                  'set t 'p
>>>                  'set grads off'
>>>                  'set mpdset hires'
>>>                  'set lat 10 45'
>>>                  'set lon -60 65'
>>>                  'set lev 850'
>>>                  'set gxout shaded'
>>>                  'set cint 2'
>>>                  'sdfopen C:\Users\yalsubhi\Desktop
>>>             \EraInterim\cases\Case1\ggap20080608'i'.nc'
>>>                  'd t'
>>>                  'q time'
>>>                  res=subwrd(result,3)
>>>                  hh=substr(res,1,3)
>>>                  dd=substr(res,4,2)
>>>                  mm=substr(res,6,3)
>>>                  yy=substr(res,9,4)
>>>                  'run cbar'
>>>                  'set font 0'
>>>                  'set strsiz 0.15 0.15'
>>>                  'draw title ('hh' 'dd'/'mm'/'yy')'
>>>                  'reinit'
>>>             i = i + 0600
>>>             p = p + 1
>>>             endwhile
>>>                  'set vpage off'
>>>             'set strsiz 0.15'
>>>             'draw string 5.3 8.3 Air Temperature'
>>>             'printim AirTemperature.png x800 y600 white'
>>>
>>>             Thanks in advance for your time and cooperation on this
>>>             matter
>>>
>>>             Thanks,
>>>
>>>             Yazeed
>>>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> 
> 	Virus-free. www.avg.com 
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> 
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20190307/96a7237b/attachment-0001.html>


More information about the gradsusr mailing list