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.
------- Forwarded Message Date: Fri, 01 Mar 2002 10:21:30 -0700 From: Russ Rew <address@hidden> To: Naveenta Anand <address@hidden> Subject: Re: 20020228: Netcdf-C library use (Trouble adding more dimensions to variables) >To: address@hidden >From: Naveenta Anand <address@hidden> >Subject: Re: 20020228: Netcdf-C library use (Trouble adding more dimensions to >variables) >Keywords: 200202282208.g1SM8j809246 Naveenta, > Regarding this question of yours, > > How did you attempt to add the dimension to the PRES variable, since there > is no netCDF library call that lets you change the shape of a variable in > an existing file? > > If I just add a dimension of a variable, won't it just change the shape of > the variable through the programming interface. I didn't quite understand > this. I would appreciate if you could help me understand this part. And I don't understand what you mean by "just add a dimension of a variable". There is no function in the netCDF library that will let you add a dimension to an existing variable of an open netCDF file. If you try to redefine the shape of an existing variable using nc_def_var(ncid, "PRES", ...), for example, you will get an error that the specified variable name is already in use. You can either create a new file with a new netCDF variable in it that has the shape you desire and copy the data from the old file to the new file, or define a new variable in the old file that has the shape you want and copy the data into that. But there is no netCDF function that changes the dimensions of an existing variable, just as there is no function to delete an existing variable from a netCDF file. So I'm still not sure what the right approach is for your problem. If you have only a single small file that you want to change, the easiest way to do it is to use ncdump to get a CDL file, edit the CDL file, then use ncgen to get the new netCDF file. If you have several files or a lot of data, then the ncdump/ncgen approach is not practical, and you will have to use a program to read the old data and write the new data. --Russ ------- End of Forwarded Message