21 #define FILE_NAME "pres_temp_4D.nc" 
   28 #define LAT_NAME "latitude" 
   29 #define LON_NAME "longitude" 
   31 #define REC_NAME "time" 
   32 #define LVL_NAME "level" 
   36 #define PRES_NAME "pressure" 
   37 #define TEMP_NAME "temperature" 
   39 #define DEGREES_EAST "degrees_east" 
   40 #define DEGREES_NORTH "degrees_north" 
   43 #define SAMPLE_PRESSURE 900 
   44 #define SAMPLE_TEMP 9.0 
   45 #define START_LAT 25.0 
   46 #define START_LON -125.0 
   50 #define PRES_UNITS "hPa" 
   51 #define TEMP_UNITS "celsius" 
   52 #define LAT_UNITS "degrees_north" 
   53 #define LON_UNITS "degrees_east" 
   54 #define MAX_ATT_LEN 80 
   58 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
 
   64    int ncid, lon_dimid, lat_dimid, lvl_dimid, rec_dimid;
 
   65    int lat_varid, lon_varid, pres_varid, temp_varid;
 
   70    size_t start[NDIMS], count[NDIMS];
 
   74    float pres_out[NLVL][NLAT][NLON];
 
   75    float temp_out[NLVL][NLAT][NLON];
 
   78    float lats[NLAT], lons[NLON];
 
   81    int lvl, lat, lon, rec, i = 0;
 
   89    for (lat = 0; lat < NLAT; lat++)
 
   90       lats[lat] = START_LAT + 5.*lat;
 
   91    for (lon = 0; lon < NLON; lon++)
 
   92       lons[lon] = START_LON + 5.*lon;
 
   94    for (lvl = 0; lvl < NLVL; lvl++)
 
   95       for (lat = 0; lat < NLAT; lat++)
 
   96      for (lon = 0; lon < NLON; lon++)
 
   98         pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + i;
 
   99         temp_out[lvl][lat][lon] = SAMPLE_TEMP + i++;
 
  109    if ((retval = 
nc_def_dim(ncid, LVL_NAME, NLVL, &lvl_dimid)))
 
  111    if ((retval = 
nc_def_dim(ncid, LAT_NAME, NLAT, &lat_dimid)))
 
  113    if ((retval = 
nc_def_dim(ncid, LON_NAME, NLON, &lon_dimid)))
 
  133                  strlen(DEGREES_NORTH), DEGREES_NORTH)))
 
  136                  strlen(DEGREES_EAST), DEGREES_EAST)))
 
  143    dimids[0] = rec_dimid;
 
  144    dimids[1] = lvl_dimid;
 
  145    dimids[2] = lat_dimid;
 
  146    dimids[3] = lon_dimid;
 
  151                 dimids, &pres_varid)))
 
  154                 dimids, &temp_varid)))
 
  159                  strlen(PRES_UNITS), PRES_UNITS)))
 
  162                  strlen(TEMP_UNITS), TEMP_UNITS)))
 
  191    for (rec = 0; rec < NREC; rec++)
 
  195                       &pres_out[0][0][0])))
 
  198                       &temp_out[0][0][0])))
 
  206    printf(
"*** SUCCESS writing example file %s!\n", FILE_NAME);
 
EXTERNL int nc_put_att_text(int ncid, int varid, const char *name, size_t len, const char *op)
Write a text attribute.
 
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
 
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.
 
EXTERNL int nc_enddef(int ncid)
Leave define mode.
 
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
 
int nc_put_vara_float(int ncid, int varid, const size_t *startp, const size_t *countp, const float *op)
Write an array of values to a variable.
 
int nc_put_var_float(int ncid, int varid, const float *op)
Write an entire variable with one call.
 
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
 
Main header file for the C API.
 
#define NC_UNLIMITED
Size argument to nc_def_dim() for an unlimited dimension.
 
#define NC_CLOBBER
Destroy existing file.
 
#define NC_FLOAT
single precision floating point number