Project

General

Profile

Comparing two N dimensions variable (N>2) ?

Added by Jean-Yves Peterschmitt almost 14 years ago

Dear all,

I have spent some time trying to see how I could make sure that a variable in 2 different netcf file is the same. Basically, I want an easy way to know that a new script is producing the expected output, but I can't do a simple unix 'diff' of the netcdf files, because the metadata in the files is not the same

I have tried
cdo diffv new_file.nc ref_file.nc
and cdo infov -sub new_file.nc ref_file.nc

This would probably be fine for a 2D (lat, lon) variable, but when you work with more dimensions, say (time, lev, lat, lon), the 2 previous commands give you information for each time/lev combinations. So, instead of getting one (min, max) pair, I have to scan nb_time*nb_lev lines of (min, max) information.

I have experimented with runmin/runmax, but it was not very convenient.

Is there a way with cdo to get the 'compact' output I'd like, with just one command line? I may have overlooked something about this in the manual, or missed some options.

I guess I would need some kind of 'collapse' or 'ravel/flat' (in the python Numeric/numpy) sense that would allow me to change a N dimensions variable to 1D
(e.g. cdo diffv -flat new_file.nc -flat ref_file.nc)

Thanks!

JY


Replies (2)

RE: Comparing two N dimensions variable (N>2) ? - Added by Matthias Cuntz almost 14 years ago

Dear Jean-Yves,

At the end of 'cdo diff' is the total number of records differing.
I use in bash:
testok=`cdo -diff ${file1} ${file2} | sed -n '/records differ$/p' | tr -s " " | cut -f2 -d" "`
if [ ${testok} -eq 0 ] ; then
echo 'All good.'
else
echo 'No good.'
fi

Cheers
Matthias

RE: Comparing two N dimensions variable (N>2) ? - Added by Jean-Yves Peterschmitt almost 14 years ago

Thanks Matthias, I'll try your 'testok'! I had not seen this 'records differ' info among all the output...

I would have preferred a 'cdo only' command for something usefull like this, but a line of pipes should be good enough :-)

JY
    (1-2/2)