// Copyright by The HDF Group. // All rights reserved. // // This file is part of the H4CF Conversion Toolkit. The full H4CF Conversion // Toolkit 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. If you do not have access to this file, you may request // a copy from eoshelp@hdfgroup.org. #include "h4cf.h" #include #include #include #include #include // This example code is to demonstrate how to open a hdf file and read // attributes of the specified data field. int main(int argc, char* argv[]) { // Open file and initialize library. h4cf_open("geo.hdf"); const list pvars = h4cf_get_vars(); for(list::const_iterator var_iter = pvars.begin(); var_iter != pvars.end(); var_iter++) { // Find the specified variable according its name. // In this case, it is "temp". if(h4cf_get_var_name((*var_iter))=="temp") { // Obtain variable attributes. const list vattrs = h4cf_get_var_attrs(*var_iter); vector vals; for(list::const_iterator vattr_iter = vattrs.begin(); vattr_iter != vattrs.end(); vattr_iter++) { // Find the specified attribute according to its // name. if(h4cf_get_attr_name((*vattr_iter)) == "_FillValue") { // Obtain attribute's data. In this case, // its data type is double and the data is // "-999.0". h4cf_get_attr_value(&vals, (*vattr_iter)); // Print data out. cout << (*vattr_iter)->get_name() << " = " << (double)*((float64*)&(vals[0])) << endl; } } } } // Close file and library. h4cf_close(); return 0; }