24 #define FILE_NAME "pres_temp_4D.nc"
31 #define LAT_NAME "latitude"
32 #define LON_NAME "longitude"
34 #define REC_NAME "time"
35 #define LVL_NAME "level"
39 #define PRES_NAME "pressure"
40 #define TEMP_NAME "temperature"
42 #define DEGREES_EAST "degrees_east"
43 #define DEGREES_NORTH "degrees_north"
46 #define SAMPLE_PRESSURE 900
47 #define SAMPLE_TEMP 9.0
48 #define START_LAT 25.0
49 #define START_LON -125.0
53 #define PRES_UNITS "hPa"
54 #define TEMP_UNITS "celsius"
55 #define LAT_UNITS "degrees_north"
56 #define LON_UNITS "degrees_east"
57 #define MAX_ATT_LEN 80
61 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
66 int ncid, pres_varid, temp_varid;
67 int lat_varid, lon_varid;
71 size_t start[NDIMS], count[NDIMS];
75 float pres_in[NLVL][NLAT][NLON];
76 float temp_in[NLVL][NLAT][NLON];
79 float lats[NLAT], lons[NLON];
82 int lvl, lat, lon, rec, i = 0;
105 for (lat = 0; lat < NLAT; lat++)
106 if (lats[lat] != START_LAT + 5.*lat)
108 for (lon = 0; lon < NLON; lon++)
109 if (lons[lon] != START_LON + 5.*lon)
114 if ((retval =
nc_inq_varid(ncid, PRES_NAME, &pres_varid)))
116 if ((retval =
nc_inq_varid(ncid, TEMP_NAME, &temp_varid)))
131 for (rec = 0; rec < NREC; rec++)
135 count, &pres_in[0][0][0])))
138 count, &temp_in[0][0][0])))
143 for (lvl = 0; lvl < NLVL; lvl++)
144 for (lat = 0; lat < NLAT; lat++)
145 for (lon = 0; lon < NLON; lon++)
147 if (pres_in[lvl][lat][lon] != SAMPLE_PRESSURE + i)
149 if (temp_in[lvl][lat][lon] != SAMPLE_TEMP + i)
160 printf(
"*** SUCCESS reading example file pres_temp_4D.nc!\n");
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
Open an existing netCDF file.
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_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.
Main header file for the C API.
#define NC_NOWRITE
Set read-only access for nc_open().