[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #OKU-828902]: big endian, little endian question



Hi Emily,

Sorry to have taken so long to respond to your question ...
> I'm using a fortran code to convert my data file to netcdf.  The data values 
> going in to the fortran code are sensible, but the netcdf output is quite 
> wonky.  I'm thinking it could be a big endian vs. little endian problem.  Is 
> there an easy way to correct the netcdf file?

The netCDF classic format or 64-bit offset variant always stores the data in 
XDR (Big Endian)
form, and the library takes care of the conversions on reading or writing, so 
that programs
using the library alsways deal with the data in native form.  That's one of the 
purposes of
the netCDF library, to insulate programmers from having to know anything about 
characterisitics of the computer on which the data was written.

The netCDF-4 format by default stores the data in native format of the writing 
machine, and
the library converts this to native form of the reading machine when the data 
is read, so
again the library insulates you from differences in endian-ness, in this case 
with a "reader
makes right" approach.

If the data looks "wonky", could it be that it's packed with "scale_factor" and 
"add_offset"
attributes, that you have to apply after reading to reverse the packing?  You 
can see such
attributes in the output of "ncdump -c" on the netCDF file.  ncdump without the 
"-c" option
should also show you the packed values, so you can verify your Fortran program 
is reading the
same values as seen by the C library.  If packing is the problem, the formulas 
for unpacking
the data are here:

  http://www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html#Packed 
Data Values

If you're still having problems, try compiling and linking one of the example 
Fortran programs
to see if those work OK with your netCDF library:

  http://www.unidata.ucar.edu/software/netcdf/examples/programs/index.html

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: OKU-828902
Department: Support netCDF
Priority: High
Status: Closed