<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; }div.foxdiv20150721134150924111 { }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Thanks, Rick! &nbsp;I'll read the document.</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>&nbsp;</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>&nbsp;<a href="mailto:brownrig@ucar.edu">Rick Brownrigg</a></div><div><b>Date:</b>&nbsp;2015-07-21&nbsp;11:19</div><div><b>To:</b>&nbsp;<a href="mailto:danghy@gmail.com">danghy@gmail.com</a></div><div><b>CC:</b>&nbsp;<a href="mailto:arne.melsom@met.no">Arne Melsom</a>; <a href="mailto:ncl-talk@ucar.edu">ncl-talk</a></div><div><b>Subject:</b>&nbsp;Re: [ncl-talk] unexpected results from very simple code</div></div></div><div><div class="FoxDiv20150721134150924111"><div dir="ltr"><div>Hi Hongyan,<br><br></div>As Arne indicated, with 32-bit floating point, you can't expect more than 7 significant digits (14 for double), and in your case, you are asking for precision 2 orders of magnitude beyond that. <br><div><div><br></div><div>For the truly curious, all the gory reality about computing and precision/accuracy is detailed in this doc:<br></div><div><br><a href="http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf">http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf</a><br><br></div><div>HTH...<br></div><div>Rick<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 20, 2015 at 7:26 PM, <a href="mailto:danghy@gmail.com">danghy@gmail.com</a> <span dir="ltr">&lt;<a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.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;"><div>
<div><span></span>Hi Arne,</div><div><br></div><div>Thanks a lot for the information!&nbsp; I will probably use "integer" to solve the problem.&nbsp; But I was really curious why the floating point number returns "210200048", not "210200049"... the perfect case would be that it returns "210200051".</div><div><br></div><div>Thanks again.</div>
<div><br></div><div>Hongyan</div><hr style="width:210px;min-height:1px" align="left" color="#b5c4df" size="1">
<div><span><div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt"><div><a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.com</a></div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div>&nbsp;</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>&nbsp;<a href="mailto:arne.melsom@met.no" target="_blank">Arne Melsom</a></div><div><b>Date:</b>&nbsp;2015-07-20&nbsp;17:27</div><div><b>To:</b>&nbsp;<a href="mailto:danghy@gmail.com" target="_blank">danghy</a></div><div><b>CC:</b>&nbsp;<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk</a></div><div><b>Subject:</b>&nbsp;Re: [ncl-talk] unexpected results from very simple code</div></div></div><div><div>Hi Danghy,</div>
<div>&nbsp;</div>
<div>I think that you can't expect (4 byte) floating point numbers to deliver the accuracy (no. digits) that you request. In your case, I suggest using double precision or integer representation. Here's a part of your example using the original representation and the two alternatives:</div>
<div>&nbsp;</div>
<div>begin</div>
<div>&nbsp;</div>
<div>a=210200051.</div>
<div>print("output / a :")</div>
<div>print(tostring(a))</div>
<div>print(sprintf("%9.0f",a))</div>
<div>&nbsp;</div>
<div>ad=210200051.d</div>
<div>print("output / ad:")</div>
<div>print(tostring(ad))</div>
<div>print(sprintf("%9.0f",ad))</div>
<div>&nbsp;</div>
<div>ai=210200051</div>
<div>print("output / ai:")</div>
<div>print(tostring(ai))</div>
<div>print(sprinti("%9i",ai))</div>
<div>&nbsp;</div>
<div>end</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>...which gives the following output:</div>
<div>&nbsp;</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>&nbsp;</div>
<div>Hope this helps!</div>
<div>Arne M.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>----- Original Message -----</div>
<div>&gt; Dear all,</div>
<div>&gt; </div>
<div>&gt; I met a problem when reading "station ID" - I've simplified the code as</div>
<div>&gt; follows:</div>
<div>&gt; </div>
<div>&gt; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div>&gt; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>&gt; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div>&gt; begin</div>
<div>&gt; </div>
<div>&gt; degrees = (/210200051, 121, 36, 43,38,58,26/)</div>
<div>&gt; </div>
<div>&gt; print(sprintf("%9.0f",degrees(0)))</div>
<div>&gt; print(tostring(degrees(0)))</div>
<div>&gt; </div>
<div>&gt; a=210200051.</div>
<div>&gt; print(tostring(a))</div>
<div>&gt; print(sprintf("%9.0f",a))</div>
<div>&gt; </div>
<div>&gt; end</div>
<div>&gt; </div>
<div>&gt; The NCL output on screen is:</div>
<div>&gt; </div>
<div>&gt; ncl test.ncl</div>
<div>&gt; Copyright (C) 1995-2015 - All Rights Reserved</div>
<div>&gt; University Corporation for Atmospheric Research</div>
<div>&gt; NCAR Command Language Version 6.3.0</div>
<div>&gt; The use of this software is governed by a License Agreement.</div>
<div>&gt; See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</div>
<div>&gt; (0) 210200048</div>
<div>&gt; (0) 210200051</div>
<div>&gt; (0) 210200048.000000</div>
<div>&gt; (0) 210200048</div>
<div>&gt; </div>
<div>&gt; Only the second method "tostring" gives the correct station ID. Could you</div>
<div>&gt; please give me a clue why is this happening?</div>
<div>&gt; </div>
<div>&gt; Appreciate!</div>
<div>&gt; </div>
<div>&gt; </div>
<div>&gt; <a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.com</a></div>
<div>&gt; </div>
<div>&gt; _______________________________________________</div>
<div>&gt; ncl-talk mailing list</div>
<div>&gt; <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a></div>
<div>&gt; List instructions, subscriber options, unsubscribe:</div>
<div>&gt; <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div>
<div>&gt; </div>
</div></blockquote>
</div><br>_______________________________________________<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/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote>
</body></html>