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.
Jim, > Subject: netCDF question > To: address@hidden > From: address@hidden (Jim Hines (awdnsun) 472-6708) > Organization: . > Keywords: 199510171555.AA05908 In the above message you wrote: > I just started playing with netCDF and do not understand something. > i wrote 2 netCDF > > exp1 > ************************************** > netcdf 3200proto { > dimensions: > time = UNLIMITED ; > variables: > short EVAP(time) ; > short EVAPQ(time); > } > > exp2 > ************************************** > netcdf 3200proto { > dimensions: > time = UNLIMITED ; > variables: > short EVAP(time); > } > *************************************** > > > I then used ncgen (with -b option) to build the the netCDF file > > the size of the netCDF file of exp1 was 120 bytes long > the size of the netCDF file of exp2 was 80 bytes long > everything ok > > > I then wrote the following fortran program and ran it on both netCDF file > I think it added 100 values to the netCDF file > ************************************************************* > c > INCLUDE 'netcdf.inc' > integer ncid,rcode > integer evapid > integer*2 ival > > integer index(1) > > ncid=ncopn('coop.nc',NCWRITE,rcode) > write(*,*)"ncid=",ncid," rcode=",rcode > > > c get variable ID's > evapid=ncvid(ncid,'EVAP',rcode) > write(*,*)"evap id=",evapid," rcode=",rcode > > do 10 i=1,100 > index(1)=i > ival=i > call ncvpt1 (ncid,evapid,index,ival,rcode) > 10 write(*,*)"ncvpt1 rcode=",rcode,i > > > c must use ncclos or ncdump does not work properly > > call ncclos(ncid,rcode) > write(*,*)"rcode close =",rcode > > stop > end > ************************************************************ > the program seamed to work but > the size of the netCDF file in exp1 was now 920 bytes > the size of the netCDF file in exp2 was now 282 bytes > > the size of the exp2 example seamed to be about right.. > the increase in space of exp1 is about double of what > i would have expected > > any ideas on what i might be doing wrong You're not doing anything wrong. The discrepancy between the actual sizes and the "expected" ones results from using a too-simple model of the netCDF file format. In the case with two short variables in each record, the netCDF library actually writes two 4-byte variables per record (the 2-byte shorts are expanded to 4-bytes by the XDR library). Consequently, the size of the data is 2*4*100 = 800 bytes. In the case with a single short variable in each record, the netCDF library is clever enough to optimize the I/O and write the entire array using 2-byte variables rather than 4-byte ones. Consequently, the size of the data is just 2*100 = 200 bytes. -------- Steve Emmerson <address@hidden>