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.

Mixing netCDF & HDF in same program

This is a report on the modifications I had to make so the netCDF library
had
no names the same as those in the HDF library. (Initially there were lots of
conflicts because
HDF includes all the netcdf-2 names.)  I only wanted to use netcdf-3 names
so it
seemed reasonable to try to suppress the netcdf-2 names in the netcdf
library. (I
could have modified HDF rather than netCDF, but it turned out to be just a
couple of hours
work to do it this way.)

I ran configure with
CPPFLAGS="-DNDEBUG -DNO_NETCDF_2" ./configure

I had hoped that this would suppress the generation of the version 2 stuff
in v2i.c, but I had
to insert several #ifndef commands to make this happen.  I found the only
code in v2i.c which 
needed to be retained was that for function nctypelen (which was supposed to
disappear from
version 3 if I remember correctly :-(  )

This left just ten conflicting names. So I changed these by inserting the
following into nc.h:

/*
 *    Redefine following names to avoid conflict with HDF names
 */

#define nctypelen nc_nctypelen
int nctypelen(nc_type type);

#define NC_begins nc_NC_begins
#define NC_check_id nc_NC_check_id
#define NC_computeshapes nc_NC_computeshapes
#define NC_endef nc_NC_endef
#define NC_findattr nc_NC_findattr
#define NC_lookupattr nc_NC_lookupattr
#define NC_lookupvar nc_NC_lookupvar
#define NC_var_shape nc_NC_var_shape
#define NC_varoffset nc_NC_varoffset

Finally, I found it useful to define a NULL data-type like the HDF type
DFNT_NONE.
So I added the following line defining dummy type NC_NAT to netcdf.h as
follows:

/*
 *  The netcdf external data types
 */
typedef enum {
        NC_NAT =         0,      /* NAT = 'Not A Type' (c.f. NaN) */
        NC_BYTE =       1,      /* signed 1 byte integer */
        NC_CHAR =       2,      /* ISO/ASCII character */
        NC_SHORT =     3,      /* signed 2 byte integer */
        NC_INT =           4,      /* signed 4 byte integer */
        NC_FLOAT =      5,      /* single precision floating point number */
        NC_DOUBLE =   6       /* double precision floating point number */
} nc_type;

I will send a copy of my modified code to Unidata.

Harvey Davies, CSIRO Atmospheric Research,
Private Bag No. 1, Aspendale 3195
E-mail: harvey.davies@xxxxxxxxxxxx
Phone: +61 3 9239 4556
  Fax: +61 3 9239 4444



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