#include <stdio.h>
#include <string.h>
#define FILE_NAME "sfc_pres_temp.nc"
#define NDIMS 2
#define NLAT 6
#define NLON 12
#define LAT_NAME "latitude"
#define LON_NAME "longitude"
#define PRES_NAME "pressure"
#define TEMP_NAME "temperature"
#define UNITS "units"
#define DEGREES_EAST "degrees_east"
#define DEGREES_NORTH "degrees_north"
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
int
main()
{
int ncid, lon_dimid, lat_dimid, pres_varid, temp_varid;
int lat_varid, lon_varid;
int dimids[NDIMS];
float pres_out[NLAT][NLON];
float temp_out[NLAT][NLON];
float lats[NLAT], lons[NLON];
char pres_units[] = "hPa";
char temp_units[] = "celsius";
int lat, lon;
int retval;
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
temp_out[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT + lat);
}
ERR(retval);
if ((retval =
nc_def_dim(ncid, LAT_NAME, NLAT, &lat_dimid)))
ERR(retval);
if ((retval =
nc_def_dim(ncid, LON_NAME, NLON, &lon_dimid)))
ERR(retval);
&lat_varid)))
ERR(retval);
&lon_varid)))
ERR(retval);
strlen(DEGREES_NORTH), DEGREES_NORTH)))
ERR(retval);
strlen(DEGREES_EAST), DEGREES_EAST)))
ERR(retval);
dimids[0] = lat_dimid;
dimids[1] = lon_dimid;
dimids, &pres_varid)))
ERR(retval);
dimids, &temp_varid)))
ERR(retval);
strlen(pres_units), pres_units)))
ERR(retval);
strlen(temp_units), temp_units)))
ERR(retval);
ERR(retval);
ERR(retval);
ERR(retval);
ERR(retval);
ERR(retval);
ERR(retval);
printf("*** SUCCESS writing example file sfc_pres_temp.nc!\n");
return 0;
}