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.
>To: <address@hidden> >From: "John Zbesko" <address@hidden> >Subject: Changing/redefining a dimension and/or variable >Organization: UCAR/Unidata >Keywords: 200205170334.g4H3YEa14957 Hi John, > Is it possible to redefine the length of a dimension in an existing NetCDF > datafile? I am developing a stock market application that uses the number of > companies in the dataset as a dimension. If I wish to include more > companies, can I change the length of that dimension using nc_def_dim? I get > an error code that implies that the dimension name is already in use. Or do > I have to make a copy of the dataset with the change implemented? > > If I define a new variable, using a combination of an existing dimension > (number of companies) and a new dimension (number of periods of time series > data), does the new data get "tacked on to the end" of the dataset file, or > is the whole dataset rewritten? You can only change (increase) the length of the unlimited dimension (also called the "record dimension"), and you can only have one unlimited dimension per netCDF dataset. To increase the length of the unlimited dimension, you just write additional data along that dimension, for example additional 2D slices of a 3D variable. You can't use the nc_def_dim() function to redefine the dimension length, since the dimension length of the unlimited dimension is the predefined constant "NC_UNLIMITED". Here's some previous responses to a similar question that have more details and possible workarounds: http://www.unidata.ucar.edu/cgi-bin/mfs/70/1856 http://www.unidata.ucar.edu/cgi-bin/mfs/70/2183 --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu