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.
>cc: <address@hidden> >From: "Angeline Ngo" <address@hidden> >Subject: netCDF variable, attribute and dimension limits >Organization: ? >Keywords: 200010130749.e9D7mx428799 netCDF variable dimension limits Hi Angeline, > [1] I am looking for the maximum number of netCDF variables, > attributes(global and variable) and dimensions allowed in a netCDF file. Is > there any section in your web page where I can find these limits ? It's not on the web page, but it is in the User's Guide and in the netcdf.h file that defines the C interface: /* * These maximums are enforced by the interface, to facilitate writing * applications and utilities. However, nothing is statically allocated to * these sizes internally. */ #define NC_MAX_DIMS 100 /* max dimensions per file */ #define NC_MAX_ATTRS 2000 /* max global or per variable attributes */ #define NC_MAX_VARS 2000 /* max variables per file */ #define NC_MAX_NAME 128 /* max length of a name */ #define NC_MAX_VAR_DIMS NC_MAX_DIMS /* max per variable dimensions */ The Fortran interface defines analogous maximums in the netcdf.inc file: ! ! advisory maximums: ! parameter(maxncdim = 100) parameter(maxncatt = 2000) parameter(maxncvar = 2000) ! not enforced parameter(maxncnam = 128) parameter(maxvdims = maxncdim) As the C comment (and the User's Guide) says, these limits are defined purely for the convenience of application writers. In particular, Fortran programmers would have a harder time writing generic netCDF applications if there weren't some such limits, because it is difficult to allocate arbitrarily large arrays in Fortran at run time. If you change these limits for your local library, you will be able to create and use netCDF files with more than 2000 attributes or variables or more than 100 dimensions, but those files may not be readable by applications or utilities at other sites linked against libraries compiled with the original limits. Hence you might lose some portability of your data. > [2] I have the netCDF V3.4 of March 06 2000 09:55:48 (FORTRAN binding). > > I am designing a program to add (extra data) to an exisitng netCDF > binary file. For no apparent reason, one of the netCDF variable appears to > be re-written wrongly (information lost and repeated). However, when I > reduced the number of variable attributes the problem goes away. It is > possible this may have been the result of having too many variable > attributes. You might want to try netCDF 3.5 beta, available from ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-beta.tar.Z because it contains a fix for a bug that sounds like it might be related to the problem you are seeing: Fixed the "redef bug" that occurred when nc_enddef() or nf_enddef() is called after nc_redef() or nf_redef(), the file is growing such that the new beginning of a record variable is in the next "chunk", and the size of at least one record variable exceeds the chunk size (see netcdf.3 man page for a description of this tuning parameter and how to set it). This bug resulted in corruption of some values in other variables than the one being added. If the bug you are seeing is not fixed by netCDF 3.5 beta, we would like to get a copy of a program that permits us to reproduce the bug symptoms, so we can fix it. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu