<div dir="ltr">Mary,<div><br></div><div>Attached is the test script that I used to reproduce Xiaobin&#39;s original results with NCL 6.3.0.  Please comment out the addition of 0.01 seconds to see the original behavior with the 60 seconds bug.  I think this should work the same for you as for me.  Look at the output labeled &quot;TEST1.1&quot; and ignore the rest.</div><div><br></div><div>Note that it was important to add &quot;d&quot; suffixes inside the array constructor.</div><div><br></div><div>--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 21, 2017 at 4:33 PM, Mary Haley <span dir="ltr">&lt;<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:small">Xiaobin,</div><div style="font-size:small"><br></div><div style="font-size:small">As Dave said, we should have a potential fix for this in the next release, but I wanted to test this first.</div><div style="font-size:small"><br></div><div style="font-size:small">I can&#39;t quite seem to reproduce the same results as you.  Could you write the time array to a netCDF file and send to to me? You should be able to just temporarily add these two lines of code:</div><div style="font-size:small"><br></div><div style="font-size:small">fout = addfile(&quot;<a href="http://marytime.nc" target="_blank">marytime.nc</a>&quot;,&quot;c&quot;)</div><div style="font-size:small">fout-&gt;time = time</div><div style="font-size:small"><br></div><div style="font-size:small">and then send me the &quot;<a href="http://marytime.nc" target="_blank">marytime.nc</a>&quot; file.</div><div style="font-size:small"><br></div><div style="font-size:small">Thanks!</div><div style="font-size:small"><br></div><div style="font-size:small">--Mary</div><div style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 19, 2017 at 3:14 PM, Dave Allured - NOAA Affiliate <span dir="ltr">&lt;<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Xiaobin,</div><div><br></div><div>There is a known <span style="font-size:14px">bug in the cd_calendar function in NCL version 6.3.0.  For time values that are extremely close to 0 or 60 seconds, the function sometimes outputs 60 seconds, and fails to increment the number of minutes.  Notice in your original message, some of the output values for minutes were incorrect, as well as values for seconds.  </span><span style="font-size:14px">This bug should be fixed in the next NCL release.</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">In the </span><span style="font-size:14px">meantime, you may be able to</span><span style="font-size:14px"> avoid the bug by adding a small fraction of one minute to your time values.  This should work because it seems like your intended values are even minutes with zero seconds:</span></div><div><span style="font-size:14px"><br></span></div><div>  time(:) = time(:) + (0.01 / 3600)     ; add 0.01 seconds to &quot;hours since...&quot;<br></div><div>  print (sprintf (&quot;%24.11f&quot;, time))<br></div><br>(0)     3615141.00000277767<br>(1)     3615141.08333611069<br>(2)     3615141.16666944465<br>(3)     3615141.25000277767<br>(4)     3615141.33333611069<br>(5)     3615141.41666944465<br>(6)     3615141.50000277767<br>(7)     3615141.58333611069<br>(8)     3615141.66666944465<br>(9)     3615141.75000277767<br>(10)    3615141.83333611069<br>(11)    3615141.91666944465<br>(12)    3615142.00000277767<br>(13)    3615142.08333611069<br>(14)    3615142.16666944465<br>(15)    3615142.25000277767<div><br></div><div><div>Now your code to compute hours, minutes, seconds, etc. with cd_calendar seems to work okay.  When you use &quot;tointeger&quot;, the extra 0.01 seconds is removed safely:</div><div><br></div><div><div>second = tointeger (utc_date(:,5))</div><div>etc.</div><div><br></div><div>  print (date_str)<br></div><br>(0) 2013_05_31_21_00_00<br>(1) 2013_05_31_21_05_00<br>(2) 2013_05_31_21_10_00<br>(3) 2013_05_31_21_15_00<br>(4) 2013_05_31_21_20_00<br>(5) 2013_05_31_21_25_00<br>(6) 2013_05_31_21_30_00<br>(7) 2013_05_31_21_35_00<br>(8) 2013_05_31_21_40_00<br>(9) 2013_05_31_21_45_00<br>(10) 2013_05_31_21_50_00<br>(11) 2013_05_31_21_55_00<br>(12) 2013_05_31_22_00_00<br>(13) 2013_05_31_22_05_00<br>(14) 2013_05_31_22_10_00<br>(15) 2013_05_31_22_15_00<br><br>Please check all output values to make sure this fix works for all cases in your data.<span class="m_9091447658529567603m_4272270880189560205HOEnZb"><font color="#888888"><br><div><br></div><div>--Dave</div></font></span><div><div class="m_9091447658529567603m_4272270880189560205h5"><div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 19, 2017 at 1:55 AM, <a href="http://qiuxiaobin.tj" target="_blank">qiuxiaobin.tj</a> <span dir="ltr">&lt;<a href="mailto:qiuxiaobin.tj@qq.com" target="_blank">qiuxiaobin.tj@qq.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><b>Dear all</b><div><b><br></b></div><div><b>I met a bug when use cd_calendar. Some times it return second = 60.</b></div><div><b>Here is the input time:</b></div><div><div>Variable: time</div><div>Type: double</div><div>Total Size: 680 bytes</div><div>            85 values</div><div>Number of Dimensions: 1</div><div>Dimensions and sizes:<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>[time | 85]</div><div>Coordinates:</div><div>Number Of Attributes: 3</div><div>  _FillValue :<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>9.969209968386869e+36</div><div>  calendar :<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>gregorian</div><div>  units :<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>hours since 1601-01-01 00:00:0.0</div><div>(0)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141</div><div>(1)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.083333333</div><div>(2)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.166666667</div><div>(3)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.25</div><div>(4)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.333333333</div><div>(5)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.416666667</div><div>(6)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.5</div><div>(7)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.583333333</div><div>(8)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.666666667</div><div>(9)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.75</div><div>(10)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.833333333</div><div>(11)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615141.916666667</div><div>(12)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615142</div><div>(13)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615142.083333333</div><div>(14)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615142.166666667</div><div>(15)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>3615142.25</div><div>..............</div><div style="font-weight:bold"><br></div></div><div><b>Here is the scripts:</b></div><div><br></div><div><div>utc_date = cd_calendar(time, 0)</div><div>;</div><div>; Store return information into more meaningful variables.</div><div>;</div><div>year   = tointeger(utc_date(:,0))    ; Convert to integer for</div><div>month  = tointeger(utc_date(:,1))    ; use sprinti </div><div>day    = tointeger(utc_date(:,2))</div><div>hour   = tointeger(utc_date(:,3))</div><div>minute = tointeger(utc_date(:,4))</div><div>second = tointeger(utc_date(:,5))</div><div><br></div><div>; Write out strings in the format &quot;hhZ dd mmm yyyy&quot;.</div><div><br></div><div>date_str = sprinti(&quot;%0.4i&quot;,year) + &quot;_&quot; + sprinti(&quot;%0.2i&quot;,month) + &quot;_&quot; + sprinti(&quot;%0.2i&quot;,day) + &quot;_&quot; + sprinti(&quot;%0.2i&quot;,hour) + &quot;_&quot; + sprinti(&quot;%0.2i&quot;,minute) + &quot;_&quot; + sprinti(&quot;%0.2i&quot;,second)</div><div><br></div><div>print(date_str) </div></div><div><br></div><div><b>Here is the output:</b></div><div><div>Variable: date_str</div><div>Type: string</div><div>Total Size: 680 bytes</div><div>            85 values</div><div>Number of Dimensions: 1</div><div>Dimensions and sizes:<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>[85]</div><div>Coordinates:</div><div>(0)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_00_00</div><div>(1)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_05_00</div><div>(2)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_<b>09_60</b></div><div>(3)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_15_00</div><div>(4)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_20_00</div><div>(5)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_<b>24_60</b></div><div>(6)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_30_00</div><div>(7)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_35_00</div><div>(8)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_<b>39_60</b></div><div>(9)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_45_00</div><div>(10)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_50_00</div><div>(11)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_21_<b>54_60</b></div><div>(12)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_22_00_00</div><div>(13)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_22_05_00</div><div>(14)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_22_<b>09_60</b></div><div>(15)<span class="m_9091447658529567603m_4272270880189560205m_3980191363636836275gmail-m_-3681583063865376995m_-2339671146012345534Apple-tab-span" style="white-space:pre-wrap">        </span>2013_05_31_22_15_00</div><div style="font-weight:bold"><br></div></div><div><b>How to overcome this? Thanks a lot.</b></div><div><b><br></b></div><div><b>Best,</b></div><div><b>Xiaobin</b></div></blockquote></div></div></div></div></div></div></div></blockquote></div></div></blockquote></div></div></div>