[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #QOP-799183]: output netCDF variables
- Subject: [netCDF #QOP-799183]: output netCDF variables
- Date: Tue, 12 Oct 2010 16:17:49 -0600
Mike,
> I'm processing a series of similar netCDF files that have 3-D (time, Y,
> X) air temperature data, and want to output the data as a 2-D field (Y,
> X) to a proper netCDF file. The advantage here is that the data will be
> on the same grid as the original input 3-D field. Therefore, I assume
> that much of the header for the resulting output netCDF file will be the
> same as the original header. The air temp variable, of course, will go
> from 3-D to 2-D. I'd like to ask you what would be the most reasonable
> way to create the output file with header and coordinate data fields (Y,
> X, lat, lon) plus the 2-D air temperature field. In other words, would
> it be reasonable to use a series of ncdump -h -var [variable] to create
> most of the output file, as opposed to writing all of this with
> nf_put_var_TYPE commands? For example, imagine taking this file:
>
> ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/monolevel/air.2m.1980.nc
>
> and then creating a file proper netCDF file with a 2-D (y,x) field for
> variable air(time, y, x). How best to get all of the header and
> coordinate info in the new netCDF file. Most of it will be the same,
> no? Is there a command to write out all header information?
Yes, you can use the ncgen utility with the output from ncdump to do
what you want, but since you're using Fortran, you need to use the
older "ncgen3" utility if you have installed netCDF version 4.1.1 or
later. (The older version can generate Fortran or C code, but the
newer ncgen generates C or Java code (or NcML) instead ...)
You can what ncgen utility to use tell by checking the bin directory
where you installed netCDF. If it's got both ncgen and ncgen3, use
ncgen3. If it's got both ncgen4 and ncgen (which was the case for
versions 4.x before 4,1,1), use ncgen. If it only has ncgen (versions
before 4.0), just use that. I'll refer to the utility as "ncgen3"
below.
First capture the header information in a cdl file, for example
ncdump -h air.2m.1980.nc > air.cdl
Then generate the Fortran-77 code needed to create the corresponding
.nc file (with the header information, but not the data):
ncgen3 -f air.cdl > air.f
Now edit the Fortran program in air.f to do what you want. Most of
the boilerplate code you'll need is there, but you'll have to change
statements such as
parameter (air_rank = 3)
to
parameter (air_rank = 2)
for example. Then compile the resulting program, link it with the
netCDF library, and run it, and you'll have the netCDF file you want.
--Russ
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: QOP-799183
Department: Support netCDF
Priority: Normal
Status: Closed