/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * 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 shows how to use chunking and compression. 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, coordinates. * It is has a chunk size is 900x1800. The deflate compression is used with a * compression level of 1. Outputs data to chunk_compress.h5 */ #include "hdf5.h" #include "string.h" #include #define H5FILE_NAME "chunk_compress.h5" #define NX1 1800 #define NY1 3600 #define STRINGLISTSIZE 2 #define TEMP "temp" #define LAT "lat" #define LON "lon" /* attributes */ #define UNITS "units" #define FILLVALUE "_FillValue" #define LONGNAME "long_name" #define COORDINATES "coordinates" int main (void) { hid_t file, dataset, att; /* file, dataset, attribute handles */ hid_t dataprop; /* data properties */ 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; hvl_t hvl[STRINGLISTSIZE]; /* varialbe length string list */ int i, j, k; char *degrees_east= "degrees_east", *degrees_north= "degrees_north", *kelvin= "kelvin", *latitude= "latitude", *longitude= "longitude", *temperature= "temperature"; char *longname, *units; char *coorlist[STRINGLISTSIZE]= {"lat", "lon"}; float **temp_array, lat_array[NX1], lon_array[NY1], fillvalue; file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* PART 1: temp */ temp_array= malloc(NX1*sizeof(float*)); for(i=0; i