20 #define FILE_NAME "sfc_pres_temp.nc"
27 #define LAT_NAME "latitude"
28 #define LON_NAME "longitude"
29 #define PRES_NAME "pressure"
30 #define TEMP_NAME "temperature"
33 #define SAMPLE_PRESSURE 900
34 #define SAMPLE_TEMP 9.0
35 #define START_LAT 25.0
36 #define START_LON -125.0
40 #define PRES_UNITS "hPa"
41 #define TEMP_UNITS "celsius"
42 #define LAT_UNITS "degrees_north"
43 #define LON_UNITS "degrees_east"
44 #define MAX_ATT_LEN 80
48 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
53 int ncid, pres_varid, temp_varid;
54 int lat_varid, lon_varid;
57 float pres_in[NLAT][NLON];
58 float temp_in[NLAT][NLON];
61 float lats_in[NLAT], lons_in[NLON];
64 char pres_units_in[MAX_ATT_LEN], temp_units_in[MAX_ATT_LEN];
65 char lat_units_in[MAX_ATT_LEN], lon_units_in[MAX_ATT_LEN];
69 int ndims_in, nvars_in, ngatts_in, unlimdimid_in;
86 if ((retval =
nc_inq(ncid, &ndims_in, &nvars_in, &ngatts_in,
93 if (ndims_in != 2 || nvars_in != 4 || ngatts_in != 0 ||
94 unlimdimid_in != -1)
return 2;
100 if ((retval =
nc_inq_varid(ncid, LON_NAME, &lon_varid)))
110 for (lat = 0; lat < NLAT; lat++)
111 if (lats_in[lat] != START_LAT + 5.*lat)
113 for (lon = 0; lon < NLON; lon++)
114 if (lons_in[lon] != START_LON + 5.*lon)
119 if ((retval =
nc_inq_varid(ncid, PRES_NAME, &pres_varid)))
121 if ((retval =
nc_inq_varid(ncid, TEMP_NAME, &temp_varid)))
133 for (lat = 0; lat < NLAT; lat++)
134 for (lon = 0; lon < NLON; lon++)
135 if (pres_in[lat][lon] != SAMPLE_PRESSURE + (lon * NLAT + lat) ||
136 temp_in[lat][lon] != SAMPLE_TEMP + .25 * (lon * NLAT + lat))
143 if (strncmp(lat_units_in, LAT_UNITS, strlen(LAT_UNITS)))
148 if (strncmp(lon_units_in, LON_UNITS, strlen(LON_UNITS)))
151 if ((retval =
nc_get_att_text(ncid, pres_varid, UNITS, pres_units_in)))
153 if (strncmp(pres_units_in, PRES_UNITS, strlen(PRES_UNITS)))
156 if ((retval =
nc_get_att_text(ncid, temp_varid, UNITS, temp_units_in)))
158 if (strncmp(temp_units_in, TEMP_UNITS, strlen(TEMP_UNITS)))
return 2;
164 printf(
"*** SUCCESS reading example file sfc_pres_temp.nc!\n");