bes  Updated for version 3.20.6
HDF5CFUInt32.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-2016 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 
30 
31 #include "config_hdf5.h"
32 
33 
34 #include "InternalErr.h"
35 #include "HDF5CFUInt32.h"
36 #include <BESDebug.h>
37 #include "h5common.h"
38 
39 using namespace std;
40 using namespace libdap;
41 
42 HDF5CFUInt32::HDF5CFUInt32(const string &n, const string &d) : UInt32(n, d)
43 {
44 }
45 
46 HDF5CFUInt32::HDF5CFUInt32(const string &n, const string &d,const string &d_f) : UInt32(n, d)
47 {
48  filename = d_f;
49 }
50 
51 HDF5CFUInt32::~HDF5CFUInt32()
52 {
53 }
54 BaseType *HDF5CFUInt32::ptr_duplicate()
55 {
56  return new HDF5CFUInt32(*this);
57 }
58 
59 bool HDF5CFUInt32::read()
60 {
61  BESDEBUG("h5","Coming to HDF5CFUInt32 read "<<endl);
62 
63  if (read_p())
64  return true;
65 
66  hid_t file_id = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
67  if(file_id < 0) {
68  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
69  }
70 
71  hid_t dset_id = -1;
72  dset_id = H5Dopen2(file_id,dataset().c_str(),H5P_DEFAULT);
73 
74  if(dset_id < 0) {
75  H5Fclose(file_id);
76  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the dataset .");
77  }
78 
79  try {
80  dods_uint32 buf;
81  get_data(dset_id, (void *) &buf);
82 
83  set_read_p(true);
84  set_value(buf);
85 
86  // Release the handles.
87  if (H5Dclose(dset_id) < 0) {
88  throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
89  }
90  H5Fclose(file_id);
91  }
92  catch(...) {
93  H5Dclose(dset_id);
94  H5Fclose(file_id);
95  throw;
96  }
97 
98  return true;
99 
100 
101 }
102 
103 
HDF5CFUInt32.h
This class provides a way to map HDF5 unsigned 32-bit integer to DAP uint32 for the CF option.
get_data
void get_data(hid_t dset, void *buf)
Definition: h5common.cc:50
HDF5CFUInt32
Definition: HDF5CFUInt32.h:42
libdap
Definition: BESDapFunctionResponseCache.h:35
h5common.h