<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>Hi Arne,</div><div><br></div><div>Thanks a lot for the information! I will probably use "integer" to solve the problem. 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; 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:arne.melsom@met.no">Arne Melsom</a></div><div><b>Date:</b> 2015-07-20 17:27</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>Hi Danghy,</div>
<div> </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> </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 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></blockquote>
</body></html>