Simon,
"Best way" depends on what software you have installed, how often
you need to convert, file size, style preferences, etc. Here are
some reasonable alternatives; there are other ways.
1. If you have NCO installed, use the ncap2 type conversion feature.
http://nco.sourceforge.net/nco.html#Manual-type-conversion
2. Use ncdump to convert the file to CDL text, then edit using sed
or your choice of stream editor.
ncdump infile.nc | sed -e 's/double varname(/float varname(/' \
> temp.cdl
ncgen -o outfile.nc temp.cdl
3. For "small" files, do the same as (2), except use a manual text
editor instead of sed. This may be the most expedient if you also
need to fiddle with attributes or other metadata.
With all methods, you may also need to perform type conversion on
attributes directly related to the data variable, in particular
_FillValue, missing_value, and/or valid_range.
--Dave A.
NOAA/PSD/CIRES
On 9/1/2010 3:40 PM, Simon Su wrote:
Hi All,
What would be the best way to convert a variable type within a netcdf file?
I need to change a variable of the type double to float within a netcdf
file.
thanks
Simon