[Thread Prev][Thread Next][Index]

Re: [ferret_users] write missing value into output netcdf



Hi,

2^100 is a poor choice for a large floating point number in either
single or double precision. You can't evaluate it exactly. You are
relying on the underlying software to make a conversion and will get
different bit patterns depending on how the expression is evaluated. For
instance, if the expression 2^100 is evaluated using integer arithmetic
and then converted to a float then you have a nonsensical intermediate
result unless 128 bit integers are used. I think this is what is
happening in the case that writes a bad value of 2.

Try the following Fortran snippet.

program test_power
xint=2**100    ! calculate using integer arithmetic then convert to real
xr4=2.0**100   ! all done in real.
write(*,*) 'Integer',xint,'Real(4)',xr4
end program test_power

The intel ifort compiler returns 0 for xint.
 

If you specify an explicit constant (eg 1E30) then the correct and (more
importantly) consistent bit pattern according to the floating point
model will be used.

Russ


On Wed, 2011-11-30 at 08:56 +1100, Haoping Yang wrote:
> Hello,
> 
> I have a little trouble when I try to write missing values (2**100) into 
> an output netcdf file. For example,
> 
> yes? use old.nc
> yes? show data
> name     title                                I              J         
>    K         L
> var1                                       1:2000    1:1000        
> ...        ...
> yes? let largenum=2^100
> yes? list/precision=7 largenum
>         1.267651E+30
> yes? set variable/bad=largenum var1      (this attempt failed)
> yes? set variable/bad=2^100 var1           (this attempt passes but the 
> missing value is 2 not 2^100)
> yes? save/file=new.nc var1
> 
> Any trick here? I can directly set variable/bad to 1.267651E+30 but 
> again that's not exactly equal to 2^100.
> Thanks,
> Haoping
> 




[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement