Re: divergence plot: execution issue

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Jul 29 2010 - 16:03:27 MDT

Hi Sahidul,

Nested "do" loops are going to be time-consuming in any scripted language like NCL. It's highly recommended to avoid them as much as possible, or to take us much code out of the do loop that you can.

I don't know what the nature is of your individual WRF files. Do you have one timestep per file or multiple timesteps? You might be able to read them all in at once with "addfiles", thus removing this from the do loop, and ending up with one big array of timesteps.

The other thing is that "wrf_user_getvar" is doing a lot of "if" checking, which is inside your do loop. You might be able to take the code for wrf_user_getvar, and make your own version of it that has a bare minimum of "if" checking in it. This may also enable you to pull whole variables off a file at a time, rather than inside a do loop.

Another possible issue is calling "systemfunc" inside the do loop. This is forking a shell process every time you call this. Instead of using the system "cut" command, you can probably use the "str_get_cols" function to get the columns of "times" that you want. On top of this, if you end up using "addfiles" as suggested above, then "times" will be an array of times, and you can do the day, yr, mon, hr initializations completely outside the do loop.

Finally, it is expensive to keep opening a new PS file for each single image that you create. Is there a reason each image needs to be in a separate file? You could draw all the images to the same "PS" file, and then after the whole looping section is done, use "psplit" to split the one PS file into individual PS files.

--Mary

On Jul 29, 2010, at 3:59 AM, Sahidul wrote:

> Hi NCL help/Users,
>
> I am trying to calculate divergence using WRF output files which are saved every 1 hour interval. I am having 88 files. The below mentioned script is working fine; but "it is taking a LOT of Time". please help me to sort this error. How to execute it faster?
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;this script calculates divergence for diff levels
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>
> begin
> datadir = "/WRF/output/2010062200/"
> FILES = systemfunc ("ls -1 " + datadir + "wrfout_d02* " )
> numFILES = dimsizes(FILES)
>
> res = True
> res@InitTime = False
> res@Footer = False
> res@cnFillOn = True
> res@cnLinesOn = False
> ;
> pltres = True
> mpres = True
> mpres@mpNationalLineThicknessF = 1.5
> mpres@mpNationalLineColor = "black"
> mpres@mpGeophysicalLineColor = "black"
> mpres@mpGeophysicalLineThicknessF = 1.5
>
> plevs = (/ 925./)
> nlevels = dimsizes(plevs)
>
> do ifil = 0,numFILES-1
> a = addfile(FILES(ifil)+".nc","r")
> times = wrf_user_list_times(a)
>
> ;;;===========================
> day = systemfunc("echo "+times +"|cut -c9-10")
> yr = systemfunc("echo "+times +"|cut -c1-4")
> mon = systemfunc("echo "+times +"|cut -c6-7")
> hr = systemfunc("echo "+times +"|cut -c12-13")
>
> if(mon .eq. "07")then
> mon="JUL"
> end if
> if(mon .eq. "08")then
> mon="AUG"
> end if
> ;;;===========================
>
> u = wrf_user_getvar(a,"ua",0)
> v = wrf_user_getvar(a,"va",0)
> p = wrf_user_getvar(a, "pressure",0)
>
> div = uv2dvG(u,v)
> div = div*10e5
>
> do level = 0,nlevels-1 ; LOOP OVER LEVELS
>
> pressure = plevs(level)
> wks = gsn_open_wks("ps","div_"+pressure+"hPa"+"_"+day+mon+yr+"_"+hr+"Z")
> gsn_define_colormap(wks,"gui_default")
>
> div_plane = wrf_user_intrp3d(div,p,"h",pressure,0.,False)
> divr = wrf_contour(a,wks,div_plane,res)
>
> if ( any(pressure.eq.plevs)) then
> plot = wrf_map_overlays(a,wks,divr,pltres,mpres)
> end if
>
> end do
> end do
> end
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> Thanking you,
>
> Sahidul
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jul 29 16:03:35 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 30 2010 - 13:45:56 MDT