TOTAL gives totally different result on identical array [message #76904] |
Fri, 08 July 2011 03:22 |
M. Suklitsch
Messages: 12 Registered: August 2008
|
Junior Member |
|
|
Hi everybody,
I don't exactly know how to start this question, so I'll probably just
tell you the workflow which leads to a very disturbing result.
I have a netCDF file which contains temperature data for a decade on
daily time resolution. And I have two different versions of an IDL
based evaluation tool which should read in the data and do some stuff
with it.
Now, although I read in exactly the same data (the data array has the
same size in both IDL sessions with both versions of my tool), TOTAL
and MEAN give completely different results. And I do not understand
how that can be, since the data does not contain any NaN values, and
MIN and MAX of the array are identical in both IDL sessions. The only
difference between the two IDL sessions are different source codes
that lead to the point where I do the stuff below. Here is what I get:
Session 1:
=======
IDL> ncid=NCDF_OPEN('my_input_file.nc')
IDL> ncdf_varget, ncid, 'tas', testa
IDL> help, mean(testa), min(testa), max(testa)
<Expression> FLOAT = 270.284
<Expression> FLOAT = 232.614
<Expression> FLOAT = 317.723
IDL> print, total(testa)/n_elements(testa)
270.284
IDL> print, n_elements(testa)
127124400
IDL> print, total(testa)
3.43597e+10
IDL> idx=where(testa lt 275., countidx, ncomplement=countnidx)
IDL> help, countidx, countnidx
COUNTIDX LONG = 22074445
COUNTNIDX LONG = 105049955
Session 2:
=======
IDL> ncid=NCDF_OPEN('my_input_file.nc')
IDL> ncdf_varget, ncid, 'tas', testa
IDL> help, mean(testa), min(testa), max(testa)
<Expression> FLOAT = 67.5711
<Expression> FLOAT = 232.614
<Expression> FLOAT = 317.723
IDL> print, total(testa)/n_elements(testa)
67.5711
IDL> print, n_elements(testa)
127124400
IDL> print, total(testa)
8.58993e+09
IDL> idx=where(testa lt 275., countidx, ncomplement=countnidx)
IDL> help, countidx, countnidx
COUNTIDX LONG = 22074445
COUNTNIDX LONG = 105049955
So, the values within the arrays seem to be the same (since the
counting gives the identical number of elements), yet the TOTAL (and
MEAN) deviate completely from each other. How can that be? I am really
confused right now. And insecure about any results I got so far.
Regards,
Martin
|
|
|