[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20020819: NetCDF values and attributes to dimensions
- Subject: Re: 20020819: NetCDF values and attributes to dimensions
- Date: Mon, 19 Aug 2002 11:13:59 -0600
>To: address@hidden
>From: =?gb2312?q?Xuguang=20Sun?= <address@hidden>
>Subject: ask some questions
>Keywords: 200208180328.g7I3SiK03141
Hi,
> I am a new user of netCDF, so I have some problems to
> generate a .nc file, that is,
> I use the netCDF library to generate a *.nc file, but
> I am wondering how I can give values and attributes to
> dimensions like lon,lat,lev,time.
If you are using the C interface to netCDF, you define dimensions
using something like:
/* define dimensions */
status = nc_def_dim(ncid, "lat", 4, &lat_dimid);
status = nc_def_dim(ncid, "lon", 3, &lon_dimid);
status = nc_def_dim(ncid, "time", NC_UNLMITED, &time_dimid);
and then you can give values to associated coordinate variables (with
the same name as the corresponding dimension) using something like:
/* define variables and assign attributes */
dims[0] = lat_dimid;
status = nc_def_var(ncid, "lat", NC_FLOAT, 1, dims, &lat_id);
status = nc_put_att_text(ncid, lat_id, "long_name", 8, "latitude");
status = nc_put_att_text(ncid, lat_id, "units", 13, "degrees_north");
dims[0] = lon_dimid;
status = nc_def_var(ncid, "lon", NC_FLOAT, 1, dims , &lon_id);
status = nc_put_att_text(ncid, lon_id, "long_name", 9, "longitude");
status = nc_put_att_text(ncid, lon_id, "units", 12, "degrees_east");
dims[0] = time_dimid;
status = nc_def_var(ncid, "time", NC_LONG, 1, dims , &time_id);
status = nc_put_att_text(ncid, frtime_id, "long_name", 13, "time");
status = nc_put_att_text(ncid, frtime_id, "units", 5, "hours");
These calls are all documented, with small examples, in the netCDF C
User's Guide:
http://www.unidata.ucar.edu/packages/netcdf/guidec/
There are similar calls for Fortran-77, Fortran-90, C++, Java, and
other languages.
A complete C example that creates and writes to a netCDF file,
including error checking after each call, is available from:
http://www.unidata.ucar.edu/packages/netcdf/examples/example1.c
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu