[ncl-talk] unexpected results from very simple code

Arne Melsom arne.melsom at met.no
Mon Jul 20 03:27:35 MDT 2015


Hi Danghy,

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:

begin

a=210200051.
print("output / a :")
print(tostring(a))
print(sprintf("%9.0f",a))

ad=210200051.d
print("output / ad:")
print(tostring(ad))
print(sprintf("%9.0f",ad))

ai=210200051
print("output / ai:")
print(tostring(ai))
print(sprinti("%9i",ai))

end


...which gives the following output:

(0)	output / a :
(0)	210200048.000000
(0)	210200048
(0)	output / ad:
(0)	210200051.000000
(0)	210200051
(0)	output / ai:
(0)	210200051
(0)	210200051

Hope this helps!
Arne M.



----- Original Message -----
> Dear all,
> 
> I met a problem when reading "station ID" - I've simplified the code as
> follows:
> 
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> begin
> 
> degrees = (/210200051, 121, 36, 43,38,58,26/)
> 
> print(sprintf("%9.0f",degrees(0)))
> print(tostring(degrees(0)))
> 
> a=210200051.
> print(tostring(a))
> print(sprintf("%9.0f",a))
> 
> end
> 
> The NCL output on screen is:
> 
> ncl test.ncl
> Copyright (C) 1995-2015 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.3.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0) 210200048
> (0) 210200051
> (0) 210200048.000000
> (0) 210200048
> 
> Only the second method "tostring" gives the correct station ID. Could you
> please give me a clue why is this happening?
> 
> Appreciate!
> 
> 
> danghy at gmail.com
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> 


More information about the ncl-talk mailing list