<div dir="ltr">Mary,<div>It works just the right,4th option is most optimised. thanks! <br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br><div><br></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 28, 2018 at 8:49 PM Mary Haley <<a href="mailto:haley@ucar.edu">haley@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Kim,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You could be correct that this is a memory issue. Are you getting any errors from NCL before it quits?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You can save on memory by not creating so many local variables. Below are four possible scenarios you can try:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">[1] You can delete a variable after you no longer need it, which will free up some memory. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default">no = aa[:]->no</div><div class="gmail_default">no_avg=dim_avg_n(no,0)</div><div class="gmail_default">delete(no)</div><div class="gmail_default">no2 = aa[:]->no2</div><div class="gmail_default">no2_avg=dim_avg_n(no2,0)</div><div class="gmail_default">delete(no2)</div><div class="gmail_default">oli = aa[:]->oli</div><div class="gmail_default">oli_avg=dim_avg_n(oli,0)</div><div class="gmail_default">delete(oli)</div><div class="gmail_default"><br></div><div class="gmail_default">[2] You can use [/.../] to delete several variables at once, if you don't need to free them individually:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default">no = aa[:]->no</div><div class="gmail_default">no_avg=dim_avg_n(no,0)</div><div class="gmail_default">no2 = aa[:]->no2</div><div class="gmail_default">no2_avg=dim_avg_n(no2,0)</div><div class="gmail_default">oli = aa[:]->oli</div><div class="gmail_default">oli_avg=dim_avg_n(oli,0)</div><div class="gmail_default">delete([/no,no2,oli/])</div><div class="gmail_default"><br></div><div class="gmail_default">[3] Even better, if there's no reason that variables like "no", "no2", and "oli" need to exist, then there's no need to save them to a local variable before taking the average:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default">no_avg = dim_avg_n(aa[:]->no,0)<br></div><div class="gmail_default">no2_avg= dim_avg_n(aa[:]->no2,0)<br></div><div class="gmail_default">oli_avg = dim_avg_n(aa[:]->oli,0)<br></div><div class="gmail_default"><br>[4] Since you are doing the same operation repeatedly, you can use a do loop and save yourself some more memory.</div></div></div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default">vars_to_avg = (/"no","no2","oli","csl","olt","xyl","ald","hc8",\</div><div class="gmail_default"> "hcho","ol2","tol","hc5","hc3","ket"/)</div><div class="gmail_default">nvars = dimsizes(vars_to_avg)</div><div class="gmail_default"><br></div><div class="gmail_default">;---Average the first one and store to variable</div><div class="gmail_default">Mpan_avg = dim_avg_n(aa[:]->$vars_to_avg(0)$,0)</div><div class="gmail_default"><br></div><div class="gmail_default">;---Loop thru rest of vars and sum their averages</div><div class="gmail_default">do nv=1,nvars-1</div><div class="gmail_default"> Mpan_avg = Mpan_avg + dim_avg_n(aa[:]->$vars_to_avg(nv)$,0)</div><div class="gmail_default">end do </div><div class="gmail_default">Mpan_avg=Mpan_avg*1000</div><div class="gmail_default">Mpan_avg2D=Mpan_avg(0,:,:)</div><div class="gmail_default">. . .</div><div class="gmail_default"><br></div><div class="gmail_default">The above is not tested, so hopefully there are no syntax errors in it.</div><div class="gmail_default"><br></div><div class="gmail_default">--Mary</div><div class="gmail_default"><br></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 28, 2018 at 2:49 AM Komal Shukla <<a href="mailto:komalshukla1992@gmail.com" target="_blank">komalshukla1992@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<br><br>I am trying to add a variable from netcdf files, and make an average plot. My scripts is mentioned below, but the process gets killed. Maybe because of memory. <br><br>Can you please suggest a "efficient" way of writing this? Please help.<br><br>Script ----------<br>begin<br>a = addfile("../wrfout_d01_2012-05-01_00:00:<a href="http://00.nc" target="_blank">00.nc</a>","r")<br><br> it = 0 ; first time step<br> hgt = wrf_user_getvar(a,"HGT_M",it) ; Terrain elevation<br> hgt@lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude<br> hgt@lon2d = wrf_user_getvar(a,"XLONG",it) ; required for plotting<br><br> wks = gsn_open_wks("png","try1")<br><br> FILES = systemfunc ("ls ../wrfout_d01_2012-05*") ; file paths<div><br> numFILES = dimsizes(FILES)<br> aa = addfiles (FILES+".nc", "r") ;add multiple files<br>;;;;;;;;;;;;<br><br>no = aa[:]->no<br>no_avg=dim_avg_n(no,0)<br>no2 = aa[:]->no2<br>no2_avg=dim_avg_n(no2,0)<br>oli = aa[:]->oli<br>oli_avg=dim_avg_n(oli,0)<br>csl = aa[:]->csl<br>csl_avg=dim_avg_n(csl,0)<br>olt = aa[:]->olt<br>olt_avg=dim_avg_n(olt,0)<br>xyl = aa[:]->xyl<br>xyl_avg=dim_avg_n(xyl,0)<br>ald = aa[:]->ald<br>ald_avg=dim_avg_n(ald,0)<br>hc8 = aa[:]->hc8<br>hc8_avg=dim_avg_n(hc8,0)<br>hcho = aa[:]->hcho<br>hcho_avg=dim_avg_n(hcho,0)<br>ol2 = aa[:]->ol2<br>ol2_avg=dim_avg_n(ol2,0)<br>tol = aa[:]->tol<br>tol_avg=dim_avg_n(tol,0)<br>hc5= aa[:]->hc5<br>hc5_avg=dim_avg_n(hc5,0)<br>hc3= aa[:]->hc3<br>hc3_avg=dim_avg_n(hc3,0)<br>ket= aa[:]->ket<br>ket_avg=dim_avg_n(ket,0)<br><br>Mpan_avg=no_avg+no2_avg+oli_avg+csl_avg+olt_avg+xyl_avg+ald_avg+hc8_avg+hcho_avg+ol2_avg+tol_avg+hc5_avg+hc3_avg+ket_avg<br>Mpan_avg=Mpan_avg*1000<br>Mpan_avg2D=Mpan_avg(0,:,:)<br>Mpan_avg2D@lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude<br>Mpan_avg2D@lon2d = wrf_user_getvar(a,"XLONG",it) ; required for plotting<br>--some plotting options here--<br>contour = gsn_csm_contour_map(wks,Mpan_avg2D,res)<br>draw(contour)<br> frame(wks)<br> <div>Thanks<div>Kim</div></div></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>
</blockquote></div>