18 #define FILE_NAME "sfc_pres_temp.nc"
25 #define LAT_NAME "latitude"
26 #define LON_NAME "longitude"
29 #define PRES_NAME "pressure"
30 #define TEMP_NAME "temperature"
32 #define DEGREES_EAST "degrees_east"
33 #define DEGREES_NORTH "degrees_north"
36 #define SAMPLE_PRESSURE 900
37 #define SAMPLE_TEMP 9.0
38 #define START_LAT 25.0
39 #define START_LON -125.0
43 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
48 int ncid, lon_dimid, lat_dimid, pres_varid, temp_varid;
55 int lat_varid, lon_varid;
60 float pres_out[NLAT][NLON];
61 float temp_out[NLAT][NLON];
62 float lats[NLAT], lons[NLON];
66 char pres_units[] =
"hPa";
67 char temp_units[] =
"celsius";
78 for (lat = 0; lat < NLAT; lat++)
79 lats[lat] = START_LAT + 5.*lat;
80 for (lon = 0; lon < NLON; lon++)
81 lons[lon] = START_LON + 5.*lon;
83 for (lat = 0; lat < NLAT; lat++)
84 for (lon = 0; lon < NLON; lon++)
86 pres_out[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
87 temp_out[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT + lat);
95 if ((retval =
nc_def_dim(ncid, LAT_NAME, NLAT, &lat_dimid)))
97 if ((retval =
nc_def_dim(ncid, LON_NAME, NLON, &lon_dimid)))
118 strlen(DEGREES_NORTH), DEGREES_NORTH)))
121 strlen(DEGREES_EAST), DEGREES_EAST)))
126 dimids[0] = lat_dimid;
127 dimids[1] = lon_dimid;
129 dimids, &pres_varid)))
132 dimids, &temp_varid)))
137 strlen(pres_units), pres_units)))
140 strlen(temp_units), temp_units)))
166 printf(
"*** SUCCESS writing example file sfc_pres_temp.nc!\n");
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
Main header file for the C API.
EXTERNL int nc_put_att_text(int ncid, int varid, const char *name, size_t len, const char *op)
Write a text attribute.
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
#define NC_CLOBBER
Destroy existing file.
int nc_put_var_float(int ncid, int varid, const float *op)
Write an entire variable with one call.
EXTERNL int nc_enddef(int ncid)
Leave define mode.
#define NC_FLOAT
single precision floating point number
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.