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.
Hi Ramesh, > In my program I read existing netcdf files. One of the dimension in the > file is an 'unlimited dimension' and I have several variables that use > this dimension. > > e.g. > dimensions: > index = UNLIMITED ; > short var1(index, oversampling) ; > short var2(index, oversampling) ; > > data: > var1 = .... > ....; > > var2 = .... > ....; > > When I query for the dimension of 'index' it reports the largest number > for 'index' across all the variables that use this dimension. > > My question is how can I detect that the variables (var1 and var2 in > the example above) have different number of data samples for 'index' > dimension? Just like other dimensions used with netCDF-3, the unlimited dimension is shared, so it always has only one length, which corresponds to the largest value it has grown to as the result of writing data to variables that share that dimension. One way to figure out how many data samples actually exist for different variables that use the unlimited dimension is to take advantage of "fill values", the value given to data that has never been written. The default fill value for short variables (as used in your example) is NC_FILL_SHORT in C (or a corresponding constant for other language APIs), which is defined as -32767. So you could read in the data for var2 and search backwards for the first value not equal to -32767 to determine how many values were actually written for that variable. If that's too inefficient, you could store the number of values written for each variable in a variable-specific attribute or in a separate variable, and increment it when you append new data. Alternatively, if you can use the enhanced data model of netCDF-4, it supports any number of unlimited dimensions. By using a different unlimited dimension for each variable, you can get the desired functionality, but your data will only be accessible to applications that can interpret netCDF-4 data. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: XQR-671194 Department: Support netCDF Priority: Normal Status: Closed