[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pgf90, nf90_short

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.


  • Subject: Re: pgf90, nf90_short
  • Date: Mon, 15 Dec 2003 15:01:41 -0700

Hi Tim,

> I am creating a netcdf file but do not seem to be getting the right
> _size_ file.
> 
> I have a variable of length 18811 and the netCDF file is
> the same size if I code this thing as a NF90_SHORT or a NF90_FLOAT.
 ...
> call check(NF90_def_var(ncid=ncFileID, name="precip", xtype=NF90_short, &
>               dimids = TimeDimID, varid=PrcpVarID))
> call check(NF90_put_att(ncFileID, PrcpVarID, "long_name",
>                                              "daily total precipitation"))
> call check(NF90_put_att(ncFileID, PrcpVarID, "units", "mm"))

The size in bytes of each record in a netCDF file is padded out to be
a multiple of 4 for portability and efficiency.  This is implied in
the chapter on the file format, but not very easy to find.

So, if you just have a single one-dimensional record variable,
"precip", the sizes are the same whether it's byte, short, or float,
because the size in bytes of every record in a netCDF file must be
divisible by 4.  But you could store two values per record with each
value a short and it would still only take 4 bytes.  Typically, there
are more than one record variable, and record variables have other
dimensions than the record dimension, so there are many values per
record.  In that case, the padding out to a multiple of 4 bytes does
not take a significant amount of space.

--Russ