23 #define FILE_NAME "pres_temp_4D.nc"
30 #define LAT_NAME "latitude"
31 #define LON_NAME "longitude"
33 #define REC_NAME "time"
34 #define LVL_NAME "level"
38 #define PRES_NAME "pressure"
39 #define TEMP_NAME "temperature"
41 #define DEGREES_EAST "degrees_east"
42 #define DEGREES_NORTH "degrees_north"
45 #define SAMPLE_PRESSURE 900
46 #define SAMPLE_TEMP 9.0
47 #define START_LAT 25.0
48 #define START_LON -125.0
52 #define PRES_UNITS "hPa"
53 #define TEMP_UNITS "celsius"
54 #define LAT_UNITS "degrees_north"
55 #define LON_UNITS "degrees_east"
56 #define MAX_ATT_LEN 80
60 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
65 int ncid, pres_varid, temp_varid;
66 int lat_varid, lon_varid;
70 size_t start[NDIMS], count[NDIMS];
74 float pres_in[NLVL][NLAT][NLON];
75 float temp_in[NLVL][NLAT][NLON];
78 float lats[NLAT], lons[NLON];
81 int lvl, lat, lon, rec, i = 0;
104 for (lat = 0; lat < NLAT; lat++)
105 if (lats[lat] != START_LAT + 5.*lat)
107 for (lon = 0; lon < NLON; lon++)
108 if (lons[lon] != START_LON + 5.*lon)
113 if ((retval =
nc_inq_varid(ncid, PRES_NAME, &pres_varid)))
115 if ((retval =
nc_inq_varid(ncid, TEMP_NAME, &temp_varid)))
130 for (rec = 0; rec < NREC; rec++)
134 count, &pres_in[0][0][0])))
137 count, &temp_in[0][0][0])))
142 for (lvl = 0; lvl < NLVL; lvl++)
143 for (lat = 0; lat < NLAT; lat++)
144 for (lon = 0; lon < NLON; lon++)
146 if (pres_in[lvl][lat][lon] != SAMPLE_PRESSURE + i)
148 if (temp_in[lvl][lat][lon] != SAMPLE_TEMP + i)
159 printf(
"*** SUCCESS reading example file pres_temp_4D.nc!\n");
Main header file for the C API.
#define NC_NOWRITE
Set read-only access for nc_open().
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
int nc_get_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, float *ip)
Read an array of values from a variable.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
Open an existing netCDF file.
EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp)
Find the ID of a variable, from the name.
int nc_get_var_float(int ncid, int varid, float *ip)
Read an entire variable in one call.