To start out we will need two files to work with. For simplicity we will use two files with the same spatial dimensions and variables. Before we start, since we are dealing with more than one file in this tutorial, we will use the 'reinit' command to close all of our current files as to not get ourselves tripped up. Then, we'll start by opening these two files.
Once our two files are open, we will use the 'q files' (not to be confused with q file) command, to list our open files.
File 1 : GFS half degree (0.5x0.5) fcst starting from 00Z04june2013, downloaded June 04 04:32 UTC
File 2 : GFS half degree (0.5x0.5) fcst starting from 12Z04june2013, downloaded June 04 16:33 UTC
So basically, you just get a little information regarding your open files, the most relevant of which is your file number. Since GrADS only works with one file at a time, you need to specify which file you are working with. This is best done using the 'set dfile' command. This changes your default file around. So:
'set dfile 1' - Points to file 1, in this case 00z GFS
'set dfile 2' - Points to file 2, in this case 12z GFS
Once your dfile is set, you treat GrADS as you normally would with just one file. So, we will continue this example by plotting CAPE from the GFS output, we will start with file 1.
'set dfile 1'
'set gxout shaded'
'set lat 22 50'
'set lon 230 295'
'set mpdset hires'
'set t 5'
Now, lets move on to file 2, and plot CAPE at the same time as a model comparison. However, since the time of the model initialization has switched, when we work with file 2, we will point to the actual time, not the timestep as we did in file one. So our command will be 'set time', not 'set t' First, we will need to get our time though, and we will do that with the 'q dims' command.
By doing that, we get our time is equal to: 12Z13MAY2013. Now we simply switch files:
'set dfile 2'
'set time 12Z04JUN2013'
'set gxout contour'
|CAPE at 12Z June 4th from 00z GFS (shaded) and 12z GFS contoured|
Now, we have our comparison map, since these files were identical spatially, we did not need to change the lat/lon dimensions around. However, I will mention that in general it is not a bad practice to reset all of your space and time dimensions every time you switch from one file to the next, just to ensure that you are plotting everything correctly.
Now, this brings me into the special case: If both of your files have the same spatial/time dimensions (for example if you were comparing two runs of the WRF, or different GFS ensemble members), you can short cut without having to go through the 'set dfile' commands.
Similar to the GrADS array syntax you can simply put a '.filenumber' at the end of your plotted variable:
'd var.1' - Plots var from file 1
'd var.2' - Plots var from file 2
Again, only use this shortcut if your model dimensions, are identical, e.g., grid spacing, timestep, etc. The main problem you will run into handling multiple files in GrADS is an "Entire Grid Undefined" error. This is simply because you didn't reset the dimensions to fit with your file. If you get this error, simply do a 'q dims' command, see where x,y,z,t fall outside of your file dimensions.
So that is all for the basics of file handling in GrADS. Hope you found it useful!
Download Example Script