[Thread Prev][Thread Next][Index]

[ferret_users] strange arithmetic behavior in ferret



Hi all,

I've been dealing with some strange arithmetic behavior in ferret, and I wanted to see if anyone has insight.  I made a netcdf data file with four dimensions: latitude, longitude, months, and years.  Afterwards, in a ferret script, I multiply the months dimension by an array which has 12 values.  Essentially, I am weighting each month by a custom amount.  Here's a simplified version of what I'm doing:

use [dataset]
let A = zsequence({1,2,3,4,5,6,7,8,9,10,11,12})
let quantity = variable[d=1]*A

Here's the problem:

When I use the command below, the answer is correct:
list quantity[d=1,x=0,y=0,l=1,k=1:12]

However, if I leave off the "k=1:12", the answer is wrong.  Instead of multiplying the 12 elements of "variable" with the 12 elements of "A", all 12 value of "variable" get multiplied by only the last value of "A".

Even more strangely, the order of commands affects the answer.  If I put the correct version first (see the two commands below), both commands output the right answer.
list quantity[d=1,x=0,y=0,l=1,k=1:12]
list quantity[d=1,x=0,y=0,l=1]

However, if I swap those two lines, both commands give the wrong answer.  Why would one answer be dependent on the other?

I've discovered that specifying the range of k in the original definition (let quantity = variable[d=1,k=1:12]*A[k=1:12]) fixes the problem, and makes all results consistent and correct.  However, the behavior I described above is very strange to me.  I haven't been able to replicate this behavior using coads_climatology, however.  Does this behavior sound familiar to anyone?  Is something wrong with my netcdf?

Michael

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

Privacy Policy | Disclaimer | Accessibility Statement