This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
> From: Greg Fall <address@hidden> > Subject: hdf/netcdf at odds > Keywords: 199710051545.JAA06812 netCDF HDF > > I am written a program in C to write HDF data to a NetCDF file. The > command I first used to compile and link was > > gcc -o /home/gmf/isccp/bin/d1_to_ncdf d1_to_ncdf.c -lm > - -I/usr/local/hdf-4.1r1/include /L/usr/local/hdf-4.1r1/lib -lmfhdf -ldf > - -ljpeg -lz -I/usr/local/netcdf-2.4.3/include -L/usr/local/netcdf-2.4.3/lib > - -g > > This version gives a warning: > > In file included from /usr/local/hdf-4.1r1/include/hdf.h:20, > from d1_to_ncdf.c:45: > /usr/local/hdf-4.1r1/include/hlimits.h:155: warning: `MAX_NC_OPEN' > redefined > /usr/local/hdf-4.1r1/include/netcdf.h:216: warning: this is the location > of the previous definition The hdf-4.1r1 package has a complete copy of some netcdf-2 distribution in it. Both of the include files mentioned in warnings above are from the hdf package. This is not a serious problem, so long as both definitions match. I've forwarded a copy of this message to the hdf folks. They've probably already addressed this problem. > The netcdf files that the resulting program writes cannot be read by the > version of ncdump in the netcdf distribution ("not a netcdf file") or by > IDL's netcdf routines. They can, however, be read by the version of > ncdump in the HDF distribution. As a result, I have to redirect the > output of HDF-ncdump to a cdl file, then use netcdf-ncgen to rewrite the > netcdf file so that it can be read properly. This is quite a nuisance, > and I suppose it is because some form of the netcdf function library is > included in the HDF library, and those libraries are not up-to-date. If I > use the following to compile and link (reversing the references to HDF and > NetCDF): The hdf-4 distribution includes support for reading and writing HDF files using the netcdf _interface_, as well as reading and writing netcdf files. There is some way to tell it what you really want to do, but you will have to refer to the hdf documentation to figure this out. > gcc -o /home/gmf/isccp/bin/d1_to_ncdf d1_to_ncdf.c -lm > - -I/usr/local/netcdf-2.4.3/include /L/usr/local/netcdf-2.4.3/lib -lnetcdf > - -I/usr/local/hdf-4.1r1/include -L/usr/local/hdf-4.1r1/lib -lmfhdf -ldf > - -ljpeg -lz -g > > Then the executable is not created at all. Here is the output: > > In file included from /usr/local/hdf-4.1r1/include/hdf.h:20, > from d1_to_ncdf.c:45: > /usr/local/hdf-4.1r1/include/hlimits.h:155: warning: `MAX_NC_OPEN' > redefined > /usr/local/hdf-4.1r1/include/netcdf.h:216: warning: this is the location > of the previous definition > bash % gcc -o d1_to_ncdf d1_to_ncdf.c -lm > - -I/usr/local/netcdf-2.4.3/include -L/usr/local/netcdf-2.4.3/lib -lnetcdf > - -I/usr/local/hdf-4.1r1/include -L/usr/local/hdf-4.1r1/lib -lmfhdf -ldf > - -ljpeg -lz -g > In file included from /usr/local/hdf-4.1r1/include/hdf.h:20, > from d1_to_ncdf.c:45: > /usr/local/hdf-4.1r1/include/hlimits.h:155: warning: `MAX_NC_OPEN' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:242: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/include/hlimits.h:162: warning: `MAX_NC_DIMS' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:249: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/include/hlimits.h:163: warning: `MAX_NC_ATTRS' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:250: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/include/hlimits.h:164: warning: `MAX_NC_VARS' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:251: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/include/hlimits.h:165: warning: `MAX_NC_NAME' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:252: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/include/hlimits.h:166: warning: `MAX_VAR_DIMS' > redefined > /usr/local/netcdf-2.4.3/include/netcdf.h:253: warning: this is the > location of the previous definition > /usr/local/hdf-4.1r1/lib/libmfhdf.a(error.o): In function `nc_serror': > error.o(.text+0x24): multiple definition of `nc_serror' > /usr/local/netcdf-2.4.3/lib/libnetcdf.a(error.o):/usr/local/netcdf-2.4.3/ > src/libsrc/error.c:121: > first defined here > ld: Warning: size of symbol `nc_serror' changed from 321 to 195 in error.o > /usr/local/hdf-4.1r1/lib/libmfhdf.a(error.o): In function `NCadvise': > error.o(.text+0xe8): multiple definition of `NCadvise' > /usr/local/netcdf-2.4.3/lib/libnetcdf.a(error.o):/usr/local/netcdf-2.4.3/ > src/libsrc/error.c:194: > first defined here > ld: Warning: size of symbol `NCadvise' changed from 197 to 118 in error.o Since the hdf package includes all of the netcdf-2, you don't need to link against /usr/local/netcdf-2.4.3/lib/libnetcdf.a. (You may need to link against /usr/local/hdf-4.1r1/lib/libnetcdf.a, if that is how things are organised.) Again, consult the hdf documentation. > > Any changes you might suggest would be great. Thanks, > > G.F. > > - --=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=-- > > Greg Fall > address@hidden > http://www-personal.engin.umich.edu/~gmfall -glenn