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: Jean-Marc SINQUIN <address@hidden> >Subject: Add/Remove layer >Organization: IFREMER / Centre de Brest >Keywords: 200108271029.f7RATH106729 netCDF rewrite Hi, > We use 3.5 netCDF interface, for managing multi-grid datas. Thus, we > need to remove and add grids in a one file. > > If we change a layer (with a different size), we must copy all the > layers before and then add the one. > > Is it possible to perform the process (without copying the layers) ? Sorry, but no, not in general. But if you make use of the "UNLIMITED dimension", you can add data along the UNLIMITED dimension without copying all the previous data. If the layers don't differ much in size, you could allocate the maximum size for each grid and use the UNLIMITED dimension for adding grids without copying previous grids, but it would waste space for grids less than the maximum size. Also, there is no easy way in netCDF to remove data, for example a grid, and recover the space of the removed data without rewriting the file. About the best you can do is keep information in a separate array that specifies whether a block of data has been removed and reuse it if it happens to fit a new block of data you want to write. NetCDF is not a database system that uses sophisticated storage allocation schemes; in particular, netCDF has no implementation of "garbage collection". Instead it supports efficient access to multidimensional arrays by making it easy to compute the location of any data in the file from the static shapes of declared variables. If you need to efficiently change more than one dimension in a file or add/delete variables, you may want to consider using another file format such as HDF-5 that permits such flexibility. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu