20 #define FILE_NAME "sfc_pres_temp.nc"
27 #define LAT_NAME "latitude"
28 #define LON_NAME "longitude"
31 #define PRES_NAME "pressure"
32 #define TEMP_NAME "temperature"
34 #define DEGREES_EAST "degrees_east"
35 #define DEGREES_NORTH "degrees_north"
38 #define SAMPLE_PRESSURE 900
39 #define SAMPLE_TEMP 9.0
40 #define START_LAT 25.0
41 #define START_LON -125.0
45 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
50 int ncid, lon_dimid, lat_dimid, pres_varid, temp_varid;
57 int lat_varid, lon_varid;
62 float pres_out[NLAT][NLON];
63 float temp_out[NLAT][NLON];
64 float lats[NLAT], lons[NLON];
68 char pres_units[] =
"hPa";
69 char temp_units[] =
"celsius";
80 for (lat = 0; lat < NLAT; lat++)
81 lats[lat] = START_LAT + 5.*lat;
82 for (lon = 0; lon < NLON; lon++)
83 lons[lon] = START_LON + 5.*lon;
85 for (lat = 0; lat < NLAT; lat++)
86 for (lon = 0; lon < NLON; lon++)
88 pres_out[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
89 temp_out[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT + lat);
97 if ((retval =
nc_def_dim(ncid, LAT_NAME, NLAT, &lat_dimid)))
99 if ((retval =
nc_def_dim(ncid, LON_NAME, NLON, &lon_dimid)))
120 strlen(DEGREES_NORTH), DEGREES_NORTH)))
123 strlen(DEGREES_EAST), DEGREES_EAST)))
128 dimids[0] = lat_dimid;
129 dimids[1] = lon_dimid;
131 dimids, &pres_varid)))
134 dimids, &temp_varid)))
139 strlen(pres_units), pres_units)))
142 strlen(temp_units), temp_units)))
168 printf(
"*** SUCCESS writing example file sfc_pres_temp.nc!\n");