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: Ying Ding <address@hidden> >Subject: question of ncdump and ncgen in netcdf >Organization: University of Tennessee at Knoxville >Keywords: 200410051815.i95IFRUE004308 netCDF ncdump ncgen Hi Ying, > i've a question about netcdf utility ncgen and ncdump. > i've a test.nc file. i use: > LINUX>ncdump test.nc > test.cdl > then i use: > ncgen -b -o test1.nc test.cdl > I suppose test.nc and test1.nc should be the same, but when i run diff > test1.nc test.nc, it shows "test.nc and test1.nc differ". > Could you tell me why? You're right, they should be the same, except that it's possible that a few unimportant differences result from: - Least significant bit in floating point or double values if the transformation from binary to text and back to binary doesn't preserve the least significant bit. ncdump is designed to provide enough precision in text output to preserve all the bits, but it's a quality of implementation issue for the printf and scanf library functions it depends on and how they treat rounding. - Elimination of unnecessary padding in the header or after the last data value in test.nc. In this case, test1.nc would be smaller than test1.nc but would have the same data. This could happen if test.nc were created with extra padding in the header by using the "underbar underbar" function nc__endef(), because this extra padding is not represented in any way in the CDL, so would be lost in converting back to test1.nc. Similarly, any extra bytes in test.nc after the last netCDF value are not accessible through the netCDF interface, so would not be in test.cdl and hence not in test1.nc. Are the sizes of test.nc and test1.nc identical? If you create test1.cdl with ncdump test1.nc > test1.cdl are test.cdl and test1.cdl identical? If the CDL files are the same, then any differences are not important. If you want to be able to just use "diff" or "cmp" to compare binary netCDF files, you may have to do some sort of canonicalization first to eliminate insignificant differences such as amount of extra space in the header (unless you consider this significant, which it is if you later intend to add more variables to the file without copying the data). For comparing netCDF files more easily, you might consider using a program designed for this purpose, such as nccmp: http://nccmp.sourceforge.net/ or ncdiff: http://www.gfdl.noaa.gov/products/vis/data/netcdf/GFDL_VG_NetCDF_Utils.html#ncdiff If you think you have discovered a bug in ncdump or ncgen because none of the above explains the difference you are seeing between test.nc and test1.nc, please send us more details! Thanks. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu/staff/russ