<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Thanks, Dennis!</div><div><br></div><div>Actually the "degrees" is a mixture of integers and floats, that's why I wanted to use "sprintf" to read them all through one command:</div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;"> </span></div><div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">degrees = (/ \<br>210200051,121,36,43,38,58,26,\<br>210200052,121,33,54,38,57,04,\<br>210200053,121,33,50,38,53,06,\<br>210200054,121,37,59,38,54,43,\<br>210200055,121,37,30,38,51,22,\<br>210200056,121,31,05,38,51,22,\<br>210200057,121,15,10,38,48,22.3,\<br>210200058,121,44,53,39,07,52,\<br>210200059,121,46,37,39,03,04,\<br>210200060,121,58,37,39,03,47,\<br>21021001,121,59,21,39,37,30,\<br>21021002,122,00,41,39,37,01,\<br>21021003,121,58,55,39,24,07,\<br>21021004,121,58,41,39,24,18,\<br>21021005,122,57,29,39,41,54,\<br>21021006,122,58,00,39,40,40,\<br>21021007,122,35,00,39,16,11,\<br>21021008,121,28,17,39,37,48,\<br>21021009,121,24,35,39,26,15,\<br>21021010,121,35,06.11,38,54,04.52,\<br>21021011,121,33,24.13,38,53,56.08,\<br>21021012,121,34,</span><span style="background-color: rgba(0, 0, 0, 0);"><font color="#3366ff">29.99</font></span><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">,38,55,36.14,\<br>21021013,121,35,</span><span style="background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">44.81</font></span><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">,38,56,58.08,\<br>21021014,121,33,52.06,39,01,19.05/)<br><br></span></div>
<div>Only the first column "station IDs" are influenced. The rest integers return the correct value even though I used "sprintf". Since the dataset is not long, I can pick out those station IDs and save them in another array.</div><div><br></div><div>Best,</div><div>Hongyan</div><div><br></div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>danghy@gmail.com</div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:shea@ucar.edu">Dennis Shea</a></div><div><b>Date:</b> 2015-07-21 11:33</div><div><b>To:</b> <a href="mailto:danghy@gmail.com">danghy</a></div><div><b>CC:</b> <a href="mailto:ncl-talk@ucar.edu">ncl-talk</a></div><div><b>Subject:</b> Re: [ncl-talk] unexpected results from very simple code</div></div></div><div><div>ncl 0> degrees = (/210200051, 121, 36, 43,38,58,26/)</div>
<div>ncl 1> print(typeof(degrees)) ; integer</div>
<div> </div>
<div>Why did you use 'sprintf' to print an integer?</div>
<div> print(sprintf("%9.0f",degrees(0)))</div>
<div>Please note the documentation.</div>
<div>---</div>
<div>http://www.ncl.ucar.edu/Document/Functions/Built-in/sprintf.shtml</div>
<div>Converts floats or doubles into formatted strings.</div>
<div>---</div>
<div>http://www.ncl.ucar.edu/Document/Functions/Built-in/sprinti.shtml</div>
<div>Converts integers into formatted strings.</div>
<div>---</div>
<div> </div>
<div>ncl 2> print(sprinti("%10.0i",degrees(0)))</div>
<div> </div>
<div>(0) 210200051</div>
<div> </div>
<div>On Mon, Jul 20, 2015 at 9:19 PM, Rick Brownrigg <brownrig@ucar.edu> wrote:</div>
<div>> Hi Hongyan,</div>
<div>></div>
<div>> As Arne indicated, with 32-bit floating point, you can't expect more than 7</div>
<div>> significant digits (14 for double), and in your case, you are asking for</div>
<div>> precision 2 orders of magnitude beyond that.</div>
<div>></div>
<div>> For the truly curious, all the gory reality about computing and</div>
<div>> precision/accuracy is detailed in this doc:</div>
<div>></div>
<div>> http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf</div>
<div>></div>
<div>> HTH...</div>
<div>> Rick</div>
<div>></div>
<div>> On Mon, Jul 20, 2015 at 7:26 PM, danghy@gmail.com <danghy@gmail.com> wrote:</div>
<div>>></div>
<div>>> Hi Arne,</div>
<div>>></div>
<div>>> Thanks a lot for the information! I will probably use "integer" to solve</div>
<div>>> the problem. But I was really curious why the floating point number returns</div>
<div>>> "210200048", not "210200049"... the perfect case would be that it returns</div>
<div>>> "210200051".</div>
<div>>></div>
<div>>> Thanks again.</div>
<div>>></div>
<div>>> Hongyan</div>
<div>>> ________________________________</div>
<div>>> danghy@gmail.com</div>
<div>>></div>
<div>>></div>
<div>>> From: Arne Melsom</div>
<div>>> Date: 2015-07-20 17:27</div>
<div>>> To: danghy</div>
<div>>> CC: ncl-talk</div>
<div>>> Subject: Re: [ncl-talk] unexpected results from very simple code</div>
<div>>> Hi Danghy,</div>
<div>>></div>
<div>>> I think that you can't expect (4 byte) floating point numbers to deliver</div>
<div>>> the accuracy (no. digits) that you request. In your case, I suggest using</div>
<div>>> double precision or integer representation. Here's a part of your example</div>
<div>>> using the original representation and the two alternatives:</div>
<div>>></div>
<div>>> begin</div>
<div>>></div>
<div>>> a=210200051.</div>
<div>>> print("output / a :")</div>
<div>>> print(tostring(a))</div>
<div>>> print(sprintf("%9.0f",a))</div>
<div>>></div>
<div>>> ad=210200051.d</div>
<div>>> print("output / ad:")</div>
<div>>> print(tostring(ad))</div>
<div>>> print(sprintf("%9.0f",ad))</div>
<div>>></div>
<div>>> ai=210200051</div>
<div>>> print("output / ai:")</div>
<div>>> print(tostring(ai))</div>
<div>>> print(sprinti("%9i",ai))</div>
<div>>></div>
<div>>> end</div>
<div>>></div>
<div>>></div>
<div>>> ...which gives the following output:</div>
<div>>></div>
<div>>> (0) output / a :</div>
<div>>> (0) 210200048.000000</div>
<div>>> (0) 210200048</div>
<div>>> (0) output / ad:</div>
<div>>> (0) 210200051.000000</div>
<div>>> (0) 210200051</div>
<div>>> (0) output / ai:</div>
<div>>> (0) 210200051</div>
<div>>> (0) 210200051</div>
<div>>></div>
<div>>> Hope this helps!</div>
<div>>> Arne M.</div>
<div>>></div>
<div>>></div>
<div>>></div>
<div>>> ----- Original Message -----</div>
<div>>> > Dear all,</div>
<div>>> ></div>
<div>>> > I met a problem when reading "station ID" - I've simplified the code as</div>
<div>>> > follows:</div>
<div>>> ></div>
<div>>> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div>>> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>>> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div>>> > begin</div>
<div>>> ></div>
<div>>> > degrees = (/210200051, 121, 36, 43,38,58,26/)</div>
<div>>> ></div>
<div>>> > print(sprintf("%9.0f",degrees(0)))</div>
<div>>> > print(tostring(degrees(0)))</div>
<div>>> ></div>
<div>>> > a=210200051.</div>
<div>>> > print(tostring(a))</div>
<div>>> > print(sprintf("%9.0f",a))</div>
<div>>> ></div>
<div>>> > end</div>
<div>>> ></div>
<div>>> > The NCL output on screen is:</div>
<div>>> ></div>
<div>>> > ncl test.ncl</div>
<div>>> > Copyright (C) 1995-2015 - All Rights Reserved</div>
<div>>> > University Corporation for Atmospheric Research</div>
<div>>> > NCAR Command Language Version 6.3.0</div>
<div>>> > The use of this software is governed by a License Agreement.</div>
<div>>> > See http://www.ncl.ucar.edu/ for more details.</div>
<div>>> > (0) 210200048</div>
<div>>> > (0) 210200051</div>
<div>>> > (0) 210200048.000000</div>
<div>>> > (0) 210200048</div>
<div>>> ></div>
<div>>> > Only the second method "tostring" gives the correct station ID. Could</div>
<div>>> > you</div>
<div>>> > please give me a clue why is this happening?</div>
<div>>> ></div>
<div>>> > Appreciate!</div>
<div>>> ></div>
<div>>> ></div>
<div>>> > danghy@gmail.com</div>
<div>>> ></div>
<div>>> > _______________________________________________</div>
<div>>> > ncl-talk mailing list</div>
<div>>> > ncl-talk@ucar.edu</div>
<div>>> > List instructions, subscriber options, unsubscribe:</div>
<div>>> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk</div>
<div>>> ></div>
<div>>></div>
<div>>></div>
<div>>> _______________________________________________</div>
<div>>> ncl-talk mailing list</div>
<div>>> ncl-talk@ucar.edu</div>
<div>>> List instructions, subscriber options, unsubscribe:</div>
<div>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk</div>
<div>>></div>
<div>></div>
<div>></div>
<div>> _______________________________________________</div>
<div>> ncl-talk mailing list</div>
<div>> ncl-talk@ucar.edu</div>
<div>> List instructions, subscriber options, unsubscribe:</div>
<div>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk</div>
<div>></div>
</div></blockquote>
</body></html>