<div dir="ltr">Hi Dave,<div>Thanks for reporting this and for investigating the root cause. I have filed a JIRA ticket: NCL-2656. </div><div>Thanks again,</div><div>Adam</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 12, 2017 at 7:43 AM, Dave Macleod <span dir="ltr"><<a href="mailto:David.Macleod@physics.ox.ac.uk" target="_blank">David.Macleod@physics.ox.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt">Hi,<br>
<div style="font-family:Times New Roman;color:#000000;font-size:16px">
<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt"><br>
Long time user, first time emailer ... thanks for all the hard work on NCL! FYI, I believe I have found a bug in calculate_daily_values.<br>
<br>
The argument "nDim" is meant to identify the time dimension, but in fact the function only works correctly when nDim=0 (in the case of 2,3,4-dimensional data), and nDim=1 (in the case of 5D data).<br>
<br>
I have copied a MWE below to demonstrate. But I have traced the problem to point of the statistical operation in the function (e.g. line 18402 in /contributed.ncl, NCL v 6.4.0):<br>
<br>
> xStat(:,nt,:,:,:)  = dim_avg_n( x(:,it,:,:,:), nDim)<br>
<br>
Here "nDim" specifies the dimension on which to carry out the averaging and "it" is the index corresponding to day "nt" . Since "it" is hard-coded on dimension #1, any value of nDim not equal to 1 will not produce the correct result.
<br>
<br>
Similarly for the 2,3,4D case, <br>
> xStat(nt,:,:,:)  = dim_avg_n( x(it,:,:,:), nDim)<br>
<br>
...requires nDim=0.<br>
<br>
A quick fix would be to modify the 5D case such that it require nDim=0, then add a error condition that nDim=0. Or something more clever to preserve the functionality of nDim! (I think there is also an issue where the xStat is defined according to dimx).<br>
<br>
NB, from the code I think the same error may affect calculate_monthly_values and possibly calculate_segment_values, though I haven't tested this.<br>
<br>
All the best,<br>
Dave MacLeod<br>
------------------------------<wbr>-------<br>
Postdoctoral Research Scientist<br>
Atmospheric Oceanic and Planetary Physics, University of Oxford<br>
<br>
<br>
MWE demonstrating the problem described above:<br>
<div><font color="000000" size="2"><br>
</font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2"></font>
<div style="font-family:Tahoma;font-size:13px"><font color="000000" size="2">load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/contributed.<wbr>ncl"<br>
begin<br>
<br>
; 2D, 3D, 4D data: only works if nDim=0<br>
x4D=random_uniform(-1.0,1.0,(/<wbr>4,4,4,4/))        ; dummy data<br>
nDim=0                        <wbr>                  ; choose a dimension to be 'time' - CHANGE
<font color="000000">FROM A <font color="000000">V<font color="000000">ALUE DIFFERENT
<font color="000000">FROM </font></font></font>ZERO TO BREAK</font></font><br>
x4D!nDim="time"               <wbr>          ; add metadata; 4 points, over 2 days<br>
x4D&time=fspan(0.25,1.75,4)<br>
x4D&time@units="days since 2017-09-12"<br>
printVarSummary(x4D)<br>
x4DDay = calculate_daily_values (x4D, "avg",nDim, False)<br>
printVarSummary(x4DDay)<br>
<br>
<br>
; 5D data: only works if nDim=1<br>
x5D=random_uniform(-1.0,1.0,(/<wbr>4,4,4,4,4/))      ; dummy data<br>
nDim=1                        <wbr>                  ; choose a dimension to be 'time'<font color="000000" size="2"><font color="000000" size="2"><font color="000000">
</font>- CHANGE <font color="000000">T<font color="000000">O A VALUE <font color="000000">
DIFFERENT</font></font><font color="000000"> FROM ONE</font> TO BREAK<br>
</font></font>x5D!nDim="time"               <wbr>          ; add metadata; 4 points, over 2 days<br>
x5D&time=fspan(0.25,1.75,4)<br>
x5D&time@units="days since 2017-09-12"<br>
printVarSummary(x5D)<br>
x5DDay = calculate_daily_values (x5D, "avg",nDim, False)<br>
printVarSummary(x5DDay)<br>
end</font><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist,  </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br></font></span></div></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a>   </font></span><span><font color="#888888">303-497-1726 </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>
</div>