<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Everyone here will tell you that using loops in NCL it’s not efficient :)<div class="">But from my experience I think that the main thing slowing you down is that you are using addfile at every iteration. </div><div class="">Does creating a whole file and reading that in the beginning would change what you are trying to compute? <br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">Guido Cioni</div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://guidocioni.altervista.org" class="">http://guidocioni.altervista.org</a> </div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 12 Jan 2016, at 15:35, Michael Notaro <<a href="mailto:mnotaro@wisc.edu" class="">mnotaro@wisc.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="divtagdefaultwrapper" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 12pt; background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class="">Does anyone have a recommendation to speed up my code?</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">It's been running for a day now. I put asterisks next to the real slow loop.</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Basically, that part is converting a large array of hourly data into daily data.</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Thanks, Michael</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><p style="margin-top: 0px; margin-bottom: 0px;" class=""></p><div style="margin-top: 0px; margin-bottom: 0px;" class="">mns=(/"01","02","03","04","05","06","07","08","09","10","11","12"/)</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">ndays=(/31,28,31,30,31,30,31,31,30,31,30,31/)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">data=new((/141,217,20,12,744/),float) ; hourly data</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">data@_FillValue=1e+35</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">data=1e+35</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">cnt=0</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">do iyr=0,19</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> do im=0,11</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> prefix=(1980+iyr)+""+mns(im)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> b=addfile("/volumes/data1/yafang/Downscaling/ACCESS1-0/historical/output/ACCESS_SRF."+(1980+iyr)+""+mns(im)+"0100.nc","r") ; read hourly SRF data</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> iy=b->iy</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> jx=b->jx</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> xlat=b->xlat</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> xlon=b->xlon</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> snow=b->snv ; liquid equiv of snow on ground</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> dims=dimsizes(snow)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> nt=dims(0)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> data(:,:,iyr,im,0:nt-1)=snow(iy|:,jx|:,time|:)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> delete(snow)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> delete(b)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> delete(dims)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> cnt=cnt+1</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> end do</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">end do</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">data@_FillValue=1e+20</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">daily=new((/141,217,20,12,31/),float) ; daily data per month</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">daily@_FillValue=1e+35</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">daily=1e+35</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">cnt=0</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">do id=0,30</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> daily(:,:,:,:,id)=dim_avg(data(:,:,:,:,cnt:cnt+23)) ; convert hourly to daily data ***** THIS PART IS SLOW *****</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""> cnt=cnt+24</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">end do</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">delete(data)</div><br class=""><p style="margin-top: 0px; margin-bottom: 0px;" class=""></p><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div id="Signature" class=""><div id="divtagdefaultwrapper" style="font-size: 12pt; background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;" class="">Michael Notaro<br class=""><div class="">Associate Director<br class=""></div><div class="">Nelson Institute Center for Climatic Research<br class=""></div><div class="">University of Wisconsin-Madison<br class=""></div><div class="">Phone: (608) 261-1503<br class=""></div><div class="">Email:<span class="Apple-converted-space"> </span><a href="mailto:mnotaro@wisc.edu" class="">mnotaro@wisc.edu</a><br class=""></div></div></div></div><span style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">ncl-talk mailing list</span><br style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:ncl-talk@ucar.edu" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">ncl-talk@ucar.edu</a><br style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">List instructions, subscriber options, unsubscribe:</span><br style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div></blockquote></div><br class=""></div></body></html>