|
|
Graphics: NCL - Example
test_addfiles.ncl: An experimental example script to use multiple input files.
-If you have comments/suggestions about this script, please send an email to wrfhelp@ucar.edu
*Note that since this is experimental, the exact way this may be implemented in future may vary from the way it is presented here.
-To use this code, you also need to download and link to this new file WRFUserARW_add.ncl
In this script note:
- We are making a list of all the wrfout files we are interested in (lines in red below).
- Typically our wrfout files do not have a ".nc" attached. You do not have to add the ".nc" to all your files. We simply add it to the list of files in a 'do-loop.'
- If your files already have the ".nc" attached, then you can just create a list (i.e., comment out the red lines and use the blue line below).
DATADir = "./"
;FILES = systemfunc ("csh -c ' ls -1 " + DATADir + "wrfout_new?.nc'")
FILES = systemfunc ("csh -c ' ls -1 " + DATADir + "wrfout_d01_2000-*00'")
numFILES = dimsizes(FILES)
do ff = 0,numFILES-1
FILES(ff) = FILES(ff)+".nc"
end do
print("numFILES = " + numFILES)
print(FILES)
; We are opening 2 data streams
; "f" contains the split files - in this test case, we have 2 split files, the first containing 3 time stamps and the second containing 2
; "a" contains the same 5 time stamps in a single file
f = addfiles(FILES,"r")
a = addfile("./wrfout_d01_2000-01-24_12:00:00.nc","r")
; We now read the same information in a couple of different ways:
; var1 - this is read from file "a", and is read in the standard manner using wrf_user_getvar - we are only interested in time stamp 3
; var2 to var3 are all read from the split files - note we send in the list of files (FILES) and not the "f" files obtained from addfiles
; var2: we want all the times - so we ask of "-1" - note since the first file has 3 times and the second 2,
; the returning array will have 6 time dimensions, with the last one containing only zero's
; var3: set a start and end interval - we will only get times 1 and 3 here (so the time dimension will be 2)
; var4: we only want time 3
; Note I can get times in the same way
var1 = wrf_user_getvar(a,"T",3)
var2 = wrf_user_getvar_from_files(FILES,"T",-1,True)
var3 = wrf_user_getvar_from_files(FILES,"T",(/1,4,2/),True)
var4 = wrf_user_getvar_from_files(FILES,"T",3,True)
times = wrf_user_getvar_from_files(FILES,"times",(/0,4,1/),True) ; get all times
print(times)
var1@description = "Theta for var1"
var2@description = "Theta for var2"
var3@description = "Theta for var3"
var4@description = "Theta for var4"
; Plotting options
; I can now use times as the valid time on the plot - note I know that times(3) match all my plots
res@TimeLabel = times(3)
opts = res
opts@cnFillOn = True
; create plots
; Note that for var1, which comes from file "a", we can use "a" directly as reference information
; but for the split files we only send in a single file as reference information
; var1: it no longer contains a time dimension as we only asked for a single time
; var4: in this case we also asked for a single time, but the new function will always return a time dimension, even if it is 1
; var2: it contains 5 times, but for comparison, we want to plot the 3rd one
; var3: it only contains 2 timestamps, and we need to plot the second to have the model 3rd timestamp
contour_var1 = wrf_contour(a,wks,var1(0,:,:),opts) ; only have one time - plot it
contour_var2 = wrf_contour(f[0],wks,var2(3,0,:,:),opts) ; have all the times, plot 3rd
contour_var3 = wrf_contour(f[0],wks,var3(1,0,:,:),opts) ; only got 1,3, so we want to plot 1
contour_var4 = wrf_contour(f[0],wks,var4(0,0,:,:),opts) ; only got the 3rd - so plot it
; outputs the plots
; note the difference in reference information - same as above
plot = wrf_map_overlays(a,wks,(/contour_var1/),pltres,mpres)
plot = wrf_map_overlays(f[0],wks,(/contour_var2/),pltres,mpres)
plot = wrf_map_overlays(f[0],wks,(/contour_var3/),pltres,mpres)
plot = wrf_map_overlays(f[0],wks,(/contour_var4/),pltres,mpres)
Note: If you used this script as a test - make sure all three plots are identical
    |
|
|