<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. &nbsp;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=(/&quot;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;07&quot;,&quot;08&quot;,&quot;09&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;/)</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&#43;35</p>
<p class="p1">data=1e&#43;35</p>
<p class="p2"><br>
</p>
<p class="p1">cnt=0</p>
<p class="p1">do iyr=0,19</p>
<p class="p1">&nbsp; do im=0,11</p>
<p class="p1">&nbsp; &nbsp; prefix=(1980&#43;iyr)&#43;&quot;&quot;&#43;mns(im)</p>
<p class="p1">&nbsp; &nbsp; b=addfile(&quot;/volumes/data1/yafang/Downscaling/ACCESS1-0/historical/output/ACCESS_SRF.&quot;&#43;(1980&#43;iyr)&#43;&quot;&quot;&#43;mns(im)&#43;&quot;0100.nc&quot;,&quot;r&quot;) ; read hourly SRF data</p>
<p class="p1">&nbsp; &nbsp; iy=b-&gt;iy</p>
<p class="p1">&nbsp; &nbsp; jx=b-&gt;jx</p>
<p class="p1">&nbsp; &nbsp; xlat=b-&gt;xlat</p>
<p class="p1">&nbsp; &nbsp; xlon=b-&gt;xlon</p>
<p class="p1">&nbsp; &nbsp; snow=b-&gt;snv ; liquid equiv of snow on ground</p>
<p class="p1">&nbsp; &nbsp; dims=dimsizes(snow)</p>
<p class="p1">&nbsp; &nbsp; nt=dims(0)</p>
<p class="p1">&nbsp; &nbsp; data(:,:,iyr,im,0:nt-1)=snow(iy|:,jx|:,time|:)</p>
<p class="p1">&nbsp; &nbsp; delete(snow)</p>
<p class="p1">&nbsp; &nbsp; delete(b)</p>
<p class="p1">&nbsp; &nbsp; delete(dims)</p>
<p class="p1">&nbsp; &nbsp; cnt=cnt&#43;1</p>
<p class="p1">&nbsp; end do</p>
<p class="p1">end do</p>
<p class="p1">data@_FillValue=1e&#43;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&#43;35</p>
<p class="p1">daily=1e&#43;35</p>
<p class="p2"><br>
</p>
<p class="p1">cnt=0</p>
<p class="p1">do id=0,30</p>
<p class="p1">&nbsp; daily(:,:,:,:,id)=dim_avg(data(:,:,:,:,cnt:cnt&#43;23)) ; convert hourly to daily data &nbsp; &nbsp; ***** THIS PART IS SLOW *****</p>
<p class="p1">&nbsp; cnt=cnt&#43;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>