<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>Thanks for your email.</p>
<p><br>
</p>
<p>Actually, this is the main part slowing me down, not the top part of the code with the addfiles.</p>
<p><br>
</p>
<p></p>
<blockquote type="cite" class="" style="color: rgb(33, 33, 33); font-size: 15px;">
<div class="">
<div id="x_divtagdefaultwrapper" class="" style="widows: auto; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif;">
<div class="" style="margin-top: 0px; margin-bottom: 0px;">cnt=0</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">do id=0,30</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">&nbsp; daily(:,:,:,:,id)=dim_avg(data(:,:,:,:,cnt:cnt&#43;23)) ; convert hourly to daily data &nbsp; &nbsp; ***** THIS PART IS SLOW *****</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">&nbsp; cnt=cnt&#43;24</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">end do</div>
</div>
</div>
</blockquote>
<div>
<div class="">
<div class="" style="widows: auto; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif;">
<div class="" style="margin-top: 0px; margin-bottom: 0px;"><br>
</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">Any way to perform this task quicker?</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;"><br>
</div>
<div class="" style="margin-top: 0px; margin-bottom: 0px;">Michael</div>
</div>
</div>
</div>
<br>
<p></p>
<p><br>
</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>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Guido Cioni &lt;guidocioni@gmail.com&gt;<br>
<b>Sent:</b> Tuesday, January 12, 2016 8:57 AM<br>
<b>To:</b> Michael Notaro<br>
<b>Cc:</b> ncl-talk@ucar.edu<br>
<b>Subject:</b> Re: [ncl-talk] Slow code</font>
<div>&nbsp;</div>
</div>
<div>Everyone here will tell you that using loops in NCL it&#8217;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.&nbsp;</div>
<div class="">Does creating a whole file and reading that in the beginning would change what you are trying to compute?&nbsp;<br class="">
<div class="">
<div class="" 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">
<br class="Apple-interchange-newline">
Guido Cioni</div>
<div class="" 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">
<a href="http://guidocioni.altervista.org" class="" id="LPlnk491663">http://guidocioni.altervista.org</a>&nbsp;</div>
<div id="LPBorder_GT_14526107474470.6079866306390613" style="margin-bottom: 20px; overflow: auto; width: 100%;">
<table id="LPContainer_14526107474430.5856938620563596" cellspacing="0" style="width: 90%; position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top-width: 1px; border-top-style: dotted; border-top-color: rgb(200, 200, 200); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(200, 200, 200); background-color: rgb(255, 255, 255);">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td id="ImageCell_14526107474450.18652741005644202" colspan="1" style="width: 250px; position: relative; display: table-cell; padding-right: 20px;">
<div id="LPImageContainer_14526107474450.17872207425534725" style="height: 145px; position: relative; margin: auto; display: table; width: 250px; background-color: rgb(255, 255, 255);">
<a id="LPImageAnchor_14526107474450.20952273532748222" href="http://guidocioni.altervista.org/" target="_blank" style="display: table-cell; text-align: center;"><img aria-label="Preview image with link selected. Double-tap to open the link." style="display: inline-block; margin-left: auto; margin-right: auto; max-width: 250px; max-height: 250px; height: 145px; width: 250px; border-width: 0px; vertical-align: bottom;" width="250" height="145" src="http://guidocioni.altervista.org/nuovosito/wp-content/uploads/2015/10/Screenshot.png"></a></div>
</td>
<td id="TextCell_14526107474460.666504209395498" colspan="2" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;">
<div id="LPRemovePreviewContainer_14526107474460.12307159579358995"></div>
<div id="LPTitle_14526107474460.9936456207651645" style="top: 0px; color: rgb(183, 1, 1); font-weight: normal; font-size: 21px; font-family: wf_segoe-ui_light, 'Segoe UI Light', 'Segoe WP Light', 'Segoe UI', 'Segoe WP', Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_14526107474460.3104995659086853" href="http://guidocioni.altervista.org/" target="_blank" style="text-decoration: none;">Guido Cioni</a></div>
<div id="LPMetadata_14526107474460.33306626812554896" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: normal; font-family: wf_segoe-ui_normal, 'Segoe UI', 'Segoe WP', Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
guidocioni.altervista.org</div>
<div id="LPDescription_14526107474460.04163848049938679" style="display: block; color: rgb(102, 102, 102); font-weight: normal; font-family: wf_segoe-ui_normal, 'Segoe UI', 'Segoe WP', Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
Le stazioni sono state riparate ed i dati vengono nuovamente aggiornati in tempo reale. Purtroppo a causa di numerosi malfunzionamenti i dati pluviometrici di Pisa e ...</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
</div>
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 12 Jan 2016, at 15:35, Michael Notaro &lt;<a href="mailto:mnotaro@wisc.edu" class="">mnotaro@wisc.edu</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div id="divtagdefaultwrapper" class="" 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; font-size:12pt; background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div class="" style="margin-top:0px; margin-bottom:0px">Does anyone have a recommendation to speed up my code?</div>
<div class="" style="margin-top:0px; margin-bottom:0px">It's been running for a day now. &nbsp;I put asterisks next to the real slow loop.</div>
<div class="" style="margin-top:0px; margin-bottom:0px">Basically, that part is converting a large array of hourly data into daily data.</div>
<div class="" style="margin-top:0px; margin-bottom:0px">Thanks, Michael</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<div class="" style="margin-top:0px; margin-bottom:0px">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;/)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">ndays=(/31,28,31,30,31,30,31,31,30,31,30,31/)</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px">data=new((/141,217,20,12,744/),float) ; hourly data</div>
<div class="" style="margin-top:0px; margin-bottom:0px">data@_FillValue=1e&#43;35</div>
<div class="" style="margin-top:0px; margin-bottom:0px">data=1e&#43;35</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px">cnt=0</div>
<div class="" style="margin-top:0px; margin-bottom:0px">do iyr=0,19</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; do im=0,11</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; prefix=(1980&#43;iyr)&#43;&quot;&quot;&#43;mns(im)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&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</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; iy=b-&gt;iy</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; jx=b-&gt;jx</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; xlat=b-&gt;xlat</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; xlon=b-&gt;xlon</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; snow=b-&gt;snv ; liquid equiv of snow on ground</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; dims=dimsizes(snow)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; nt=dims(0)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; data(:,:,iyr,im,0:nt-1)=snow(iy|:,jx|:,time|:)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; delete(snow)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; delete(b)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; delete(dims)</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; &nbsp; cnt=cnt&#43;1</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; end do</div>
<div class="" style="margin-top:0px; margin-bottom:0px">end do</div>
<div class="" style="margin-top:0px; margin-bottom:0px">data@_FillValue=1e&#43;20</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px">daily=new((/141,217,20,12,31/),float) ; daily data per month</div>
<div class="" style="margin-top:0px; margin-bottom:0px">daily@_FillValue=1e&#43;35</div>
<div class="" style="margin-top:0px; margin-bottom:0px">daily=1e&#43;35</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px">cnt=0</div>
<div class="" style="margin-top:0px; margin-bottom:0px">do id=0,30</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; daily(:,:,:,:,id)=dim_avg(data(:,:,:,:,cnt:cnt&#43;23)) ; convert hourly to daily data &nbsp; &nbsp; ***** THIS PART IS SLOW *****</div>
<div class="" style="margin-top:0px; margin-bottom:0px">&nbsp; cnt=cnt&#43;24</div>
<div class="" style="margin-top:0px; margin-bottom:0px">end do</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px">delete(data)</div>
<br class="">
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0px"><br class="">
</div>
<div id="Signature" class="">
<div id="divtagdefaultwrapper" class="" style="font-size:12pt; background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
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">&nbsp;</span><a href="mailto:mnotaro@wisc.edu" class="">mnotaro@wisc.edu</a><br class="">
</div>
</div>
</div>
</div>
<span class="" 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; float:none; display:inline!important">_______________________________________________</span><br class="" 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">
<span class="" 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; float:none; display:inline!important">ncl-talk
 mailing list</span><br class="" 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">
<a href="mailto:ncl-talk@ucar.edu" class="" 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">ncl-talk@ucar.edu</a><br class="" 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">
<span class="" 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; float:none; display:inline!important">List
 instructions, subscriber options, unsubscribe:</span><br class="" 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">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" class="" 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">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</body>
</html>