/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * Copyright by The HDF Group. ! * All rights reserved. ! * ! * The full HDF5 copyright notice, including terms governing use, modification, ! * and redistribution, is contained in the file COPYING. COPYING can be found ! * at the root of the source code distribution tree. ! * For questions contact the help desk at help@hdfgroup.org ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * Programmer: Isayah Reed * Wednesday, May 4, 2011 * * Purpose: * This is 1 of 4 simple HDF5 programs that demonstrates how to add CF attributes * to an h5 file. This example demonstrates how to use the HDF5 dimension scale * API. A file is created with 3 datasets: lat, lon, temp. Lat contains the CF * attributes: units and long_name. Lon has the same CF attributes as the latitude * dataset. Temp contains the CF attributes: units, long_name, _FillValue, and * coordinates. Outputs data to ds_ex1.h5 */ #include "hdf5.h" #include "string.h" #define H5FILE_NAME "ds_ex1.h5" #define TEMP "temp" #define LAT "lat" #define LON "lon" #define NX1 180 #define NY1 360 #define STRINGLISTSIZE 2 #define UNITS "Units" #define FILLVALUE "_FillValue" #define LONGNAME "long_name" #define COORDINATES "coordinates" int main (void) { hid_t file, dataset[3], att; /* file, dataset, attribute handles */ hid_t floatType, stringType, arrayType; /* datatypes */ hid_t floatSpace, stringSpace, arraySpace; /* dataspaces */ hsize_t dimsa[2], dimsa3[3], dimsf[1], dimsc[2]; /* dataset dimensions */ herr_t status; int i, j, k; float temp_array[NX1][NY1], lat_array[NX1], lon_array[NY1], fillvalue; char *longname, *units; char *degrees_east= "degrees_east", *degrees_north= "degrees_north", *kelvin= "kelvin", *latitude= "latitude", *longitude= "longitude", *temperature= "temperature"; char *coorlist[STRINGLISTSIZE]= {"lat", "lon"}; /* create h5 file */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* initialize handles */ floatType= H5Tcopy(H5T_NATIVE_FLOAT); H5Tset_precision(floatType, 32); dimsa[0]= NX1; dimsa[1]= NY1; floatSpace= H5Screate_simple(2, dimsa, NULL); stringType= H5Tcopy(H5T_C_S1); stringSpace= H5Screate(H5S_SCALAR); /* PART 1: temp */ /* initialize temperature array */ /* values between a[60][*] and a[120][*] is around 300.0 */ for(i=60; i<=120; i++) for(j=0; j