OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDF5CFModule.cc
Go to the documentation of this file.
1 // This file is part of the hdf5_handler implementing for the CF-compliant
2 // Copyright (c) 2011-2013 The HDF Group, Inc. and OPeNDAP, Inc.
3 //
4 // This is free software; you can redistribute it and/or modify it under the
5 // terms of the GNU Lesser General Public License as published by the Free
6 // Software Foundation; either version 2.1 of the License, or (at your
7 // option) any later version.
8 //
9 // This software is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 // License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
19 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
20 // Suite 203, Champaign, IL 61820
21 
32 
33 #include <InternalErr.h>
34 #include "HDF5CFModule.h"
35 
36 using namespace libdap;
37 
38 H5CFModule check_module(hid_t fileid) {
39 
40  if (true == check_eos5(fileid))
41  return HDF_EOS5;
42  else if(true == check_jpss(fileid))
43  return HDF5_JPSS;
44  else
45  return HDF5_GENERAL;
46 
47 }
48 
49 bool check_eos5(hid_t file_id) {
50 
51  // check HDF-EOS5 group
52  string eos5_check_group = "/HDFEOS INFORMATION";
53  string eos5_check_attr = "HDFEOSVersion";
54  string eos5_dataset = "StructMetadata.0";
55  htri_t has_eos_group = -1;
56 
57  has_eos_group = H5Lexists(file_id,eos5_check_group.c_str(),H5P_DEFAULT);
58 
59  if (has_eos_group > 0){
60 
61  hid_t eos_group_id = -1;
62  htri_t has_eos_attr = -1;
63 
64  // Open the group
65  if((eos_group_id = H5Gopen(file_id, eos5_check_group.c_str(),H5P_DEFAULT))<0) {
66 
67  string msg = "cannot open the HDF5 group ";
68  msg += eos5_check_group;
69 // H5Fclose(file_id);
70  throw InternalErr(__FILE__, __LINE__, msg);
71  }
72 
73  // check the existence of the EOS5 attribute
74  has_eos_attr = H5Aexists(eos_group_id, eos5_check_attr.c_str());
75 
76  if (has_eos_attr >0) {
77 
78  // All HDF-EOS5 conditions are fulfilled, return true;
79  // Otherwise, return false or throw an error.
80  htri_t has_eos_dset = -1;
81 
82  // check the existence of the EOS5 dataset
83  has_eos_dset = H5Lexists(eos_group_id,eos5_dataset.c_str(),H5P_DEFAULT);
84  if (has_eos_dset >0)
85  return true;
86  else if(0 == has_eos_dset)
87  return false;
88  else {
89  string msg = "Fail to determine if the HDF5 dataset ";
90  msg += eos5_dataset;
91  msg +=" exists ";
92  H5Gclose(eos_group_id);
93 // H5Fclose(file_id);
94  throw InternalErr(__FILE__, __LINE__, msg);
95  }
96  }
97  else if(0 == has_eos_attr)
98  return false;
99  else {
100  string msg = "Fail to determine if the HDF5 attribute ";
101  msg += eos5_check_attr;
102  msg +=" exists ";
103  H5Gclose(eos_group_id);
104  // H5Fclose(file_id);
105  throw InternalErr(__FILE__, __LINE__, msg);
106  }
107  }
108  else if( 0 == has_eos_group)
109  return false;
110  else {
111  string msg = "Fail to determine if the HDF5 group ";
112  msg += eos5_check_group;
113  msg +=" exists ";
114 // H5Fclose(file_id);
115  throw InternalErr(__FILE__, __LINE__, msg);
116  }
117 }
118 
119 bool check_jpss(hid_t fileid) {
120  // Currently not supported.
121  return false;
122 }
bool check_eos5(hid_t file_id)
Definition: HDF5CFModule.cc:49
bool check_jpss(hid_t fileid)
static class NCMLUtil overview
H5CFModule check_module(hid_t fileid)
Definition: HDF5CFModule.cc:38
H5CFModule
Definition: HDF5CFModule.h:42
This class describes the different categories of HDF5 products for the CF option. ...