<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Does anyone have a recommendation to speed up my code?</p>
<p>It's been running for a day now. I put asterisks next to the real slow loop.</p>
<p>Basically, that part is converting a large array of hourly data into daily data.</p>
<p>Thanks, Michael</p>
<p><br>
</p>
<p><br>
</p>
<p></p>
<p class="p1">mns=(/"01","02","03","04","05","06","07","08","09","10","11","12"/)</p>
<p class="p1">ndays=(/31,28,31,30,31,30,31,31,30,31,30,31/)</p>
<p class="p2"><br>
</p>
<p class="p1">data=new((/141,217,20,12,744/),float) ; hourly data</p>
<p class="p1">data@_FillValue=1e+35</p>
<p class="p1">data=1e+35</p>
<p class="p2"><br>
</p>
<p class="p1">cnt=0</p>
<p class="p1">do iyr=0,19</p>
<p class="p1"> do im=0,11</p>
<p class="p1"> prefix=(1980+iyr)+""+mns(im)</p>
<p class="p1"> b=addfile("/volumes/data1/yafang/Downscaling/ACCESS1-0/historical/output/ACCESS_SRF."+(1980+iyr)+""+mns(im)+"0100.nc","r") ; read hourly SRF data</p>
<p class="p1"> iy=b->iy</p>
<p class="p1"> jx=b->jx</p>
<p class="p1"> xlat=b->xlat</p>
<p class="p1"> xlon=b->xlon</p>
<p class="p1"> snow=b->snv ; liquid equiv of snow on ground</p>
<p class="p1"> dims=dimsizes(snow)</p>
<p class="p1"> nt=dims(0)</p>
<p class="p1"> data(:,:,iyr,im,0:nt-1)=snow(iy|:,jx|:,time|:)</p>
<p class="p1"> delete(snow)</p>
<p class="p1"> delete(b)</p>
<p class="p1"> delete(dims)</p>
<p class="p1"> cnt=cnt+1</p>
<p class="p1"> end do</p>
<p class="p1">end do</p>
<p class="p1">data@_FillValue=1e+20</p>
<p class="p2"><br>
</p>
<p class="p1">daily=new((/141,217,20,12,31/),float) ; daily data per month</p>
<p class="p1">daily@_FillValue=1e+35</p>
<p class="p1">daily=1e+35</p>
<p class="p2"><br>
</p>
<p class="p1">cnt=0</p>
<p class="p1">do id=0,30</p>
<p class="p1"> daily(:,:,:,:,id)=dim_avg(data(:,:,:,:,cnt:cnt+23)) ; convert hourly to daily data ***** THIS PART IS SLOW *****</p>
<p class="p1"> cnt=cnt+24</p>
<p class="p1">end do</p>
<p class="p2"><br>
</p>
<p class="p1">delete(data)</p>
<br>
<p></p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
Michael Notaro<br>
<div>Associate Director<br>
</div>
<div>Nelson Institute Center for Climatic Research<br>
</div>
<div>University of Wisconsin-Madison<br>
</div>
<div>Phone: (608) 261-1503<br>
</div>
<div>Email: mnotaro@wisc.edu<br>
</div>
</div>
</div>
</div>
</body>
</html>