[gradsusr] Need Help with GrADS

James T. Potemra jimp at hawaii.edu
Wed Mar 6 22:00:52 EST 2019


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
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20190306/8b45399b/attachment-0001.html>


More information about the gradsusr mailing list