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 Arlindo, > I have a few netCDF files needing repair. I was running this model for > many days on my workstation. A power failure made my job terminate in > the middle. I have several netCDF output files which have data in them > (I can tell from their sizes) but the unlimited dimension is still set > to zero. If I try to read the files with the the netCDF library it > does let me read anything, because the library checks the requested > dimensions, and it thinks there is no data in it. > > My question: Is there a simple way for me to change "by hand" the > unlimited dimenion *time*. I know what it should be. > > > I am pretty sure I am not the first one running into this kind of > problems. In any event, would it be adding too much overhead to have > netCDF updating the unlimited dimension on file everytime it writes a > hyperslab? As Bruce Langdon pointed out, preventing this sort of situation is one of the things ncsync (NCSNC) was designed for. In the future it would be best to call ncsync after writing each record to properly update the record count to disk. It may still be practical to manually fix the record count in a netCDF file that thinks there are zero records. The structure you want to update on disk is one that corresponds to the XDR version of the NC structure defined in netcdf/libsrc/local_nc.h, in which the `numrecs' member (an unsigned long) contains the number of records in the file. If you can find the variable of this type corresponding to the open file, you can update its `numrecs' member, then write it out again from the debugger. If you try this, do it with a copy, since I'm not sure that's all that needs to be changed. Alternatively, you can create two files with exactly the same structure as one of your netCDF files, except that one has only 1 record and another has more records of the same data. Then use the `cmp' command or an editor that can edit binary files (such as emacs) to find the offset where the two files differ. That will show you where the unsigned long is in the file header that stores the number of records. Note the offset in the file and edit one of your real files, changing the unsigned long integer stored there from 0 to however many records are in the file, remembering that it is the XDR representation of the unsigned long you are changing (to get the byte order of the integer right). ______________________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 http://www.unidata.ucar.edu/ Boulder, CO 80307-3000 ______________________________________________________________________________