/* * Programmer: Isayah Reed * Wednesday, May 4, 2011 * * Purpose: * This is a simple netCDF4 program that demonstrates how to add CF attributes * to an h5 file. Creates a file with 3 variables: lat, lon, temp. Lat contains * the CF attributes: units, long_name, and standard_name. Lon has the same CF * attributes as the latitude variable. Temp contains the CF attributes: units, * long_name, _FillValue, and coordinates. Outputs data to netcdf_ex1.h5 */ #include #include #include "netcdf.h" #include "hdf5.h" #include "hdf5.h" #include "string.h" /* This is the name of the data file we will create. */ #define FILE_NAME "netcdf_ex1.nc" /* We are writing 2D data, a 180 x 360 grid. */ #define NDIMS 2 #define NX1 180 /* dataset dimensions */ #define NY1 360 #define STRINGLISTSIZE 2 /* datasets */ #define TEMP "temp" #define LAT "lat" #define LON "lon" /* attributes */ #define UNITS "units" #define FILLVALUE "_FillValue" #define LONGNAME "long_name" #define COORDINATES "coordinates" /* Handle errors by printing an error message and exiting with a * non-zero status. */ #define ERRCODE 2 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} int main() { int ncid, varid[3]; int dimsf[1], dimsa[2], dimst; /* float, array, text dimensions */ float temp_array[NX1][NY1], lat_array[NX1], lon_array[NY1], fillvalue= -999.0; int retval, i, j; char *degrees_east= "degrees_east", *degrees_north= "degrees_north", *kelvin= "kelvin", *latitude= "latitude", *longitude= "longitude", *temperature= "temperature"; char *coorlist[STRINGLISTSIZE]= {"lat\0", "lon\0"}; /* values between a[60][*] and a[120][*] is around 300.0 */ for(i=60; i<=120; i++) for(j=0; j