NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Packing data: scale_factor add_offset

Hi

I'm a relatively new netCDF user.  Having read the netCDF guide plus
some entries in the support and user forum, I have a burning question
regarding data packing using 'scale_factor' and 'add_offset'.  I've seen
fortran code which implement the packing with code like the following
sample snippet:

        INTEGER*2 X_PACKED
        REAL X, OFFSET, SCALE

        X = 10.23456
        OFFSET = 9.0
        SCALE = 0.23123

        X_PACKED = (X-OFFSET)*SCALE
        ! Then proceed to store X_PACKED in netCDF form.
        . . .

What I don't understand is how this can be "correct".  When you assign a
REAL to an INTEGER, the value of the REAL gets truncated before being
stored in the INTEGER.  Thus, the original value of X cannot be
'reconstructed' from the corresponding INTEGER*2 variable (X_PACKED) in
the netCDF file.

I understand the intent is to store only the 2 bytes that represents the
scaled-down REAL value.  But as far as I know, this is not possible in
Fortran -- as far as simply assigning values to variables is concerned.

Or is the above fortran implementation of packing in netCDF completely
off track?  Am I missing anything?
What is the common practice of netCDF packing in Fortran?  
Any sample Fortran code for netCDF data packing?

Thanks for any explanations or tips.

-Kek
Tropical Marine Sc Institute
Singapore

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: