`max_diff_nc`

You are here: home page →
`max_diff_nc`

.

## What is it?

This is a program which compares two NetCDF files.
Only NetCDF variables with type `nf90_float`

or
`nf90_double`

are compared. The program either compares
variables with the same NetCDF ID (`varid`

) or variables
with the same name. Compared variables are assumed to have the same
type and shape. For each such couple of variables, the program
computes the maximum of the absolute value of the difference, and the
maximum of the absolute value of the relative difference. The program
also tells you at what location (the subscript list of the array) the
maximum difference is reached.

## Remarks

Maximum memory used will normally be:

- without computation of average order of magnitude: about 5 times
the memory occupied by the largest variable;
- with computation of average order of magnitude: about 7 times
the memory occupied by the largest variable.

But memory used may increase with the optimization level you choose
when you compile `max_diff_nc`

.
There is a known problem in older versions of Gfortran, fixed in
version `4.4.5`

of Gfortran. The program
`max_diff_nc`

prints differences with the Fortran format
`1pg7.1`

. Older versions of Gfortran produce wrong results
with this format. For example, according to the Fortran 95 standard,
printing the number 0.96 with the format `1pg7.1`

should
give the same result than with format `f3.0`

. Thus, the
result should be `1.`

, but Gfortran produces the surprising
result `0.`

If you cannot use another compiler, a
work-around is to change `1pg7.1`

to `1pg8.2`

in
the file `compare.f90`

.

## Changes

- April 8th, 2014.
`max_diff_nc`

now reads NetCDF float
variables into real Fortran variables and NetCDF double variables
into double precision Fortran variables. (For the sake of lower
memory usage.)
- May 10th, 2013. The default behaviour of
`max_diff_nc`

is now to read NetCDF variables into double precision Fortran
variables. It is now easy to switch to another real precision (just
modify the definition of `wp`

in
`max_diff_nc.f90`

).
- June 12th, 2012. When comparing variables with the same name, if a
name is not found in the second file, the program now just skips the
comparison, instead of stopping.
- September 8th, 2011. Added option
`-v`

for comparison
of a given variable. Generalized installation process to accomodate
version 4 of NetCDF.
- April 28th, 2010. Added comparison by
variable name. Comparison by variable ID, which was the only choice
before, is now selected by option
`-i`

.