bes  Updated for version 3.20.6
HDF5CFInt64.cc
Go to the documentation of this file.
1 // This file is part of hdf5_handler: an HDF5 file handler for the OPeNDAP
2 // data server.
3 
4 // Copyright (c) 2011-2018 The HDF Group, Inc. and OPeNDAP, Inc.
5 //
6 // This is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your
9 // option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
22 // Suite 203, Champaign, IL 61820
23 
32 
33 #include "config_hdf5.h"
34 
35 #include <BESDebug.h>
36 #include "InternalErr.h"
37 #include "HDF5CFInt64.h"
38 #include "h5common.h"
39 using namespace std;
40 using namespace libdap;
41 
42 HDF5CFInt64::HDF5CFInt64(const string &n, const string &d) : Int64(n, d)
43 {
44 }
45 
46 HDF5CFInt64::HDF5CFInt64(const string &n, const string &d,const string &d_f) : Int64(n, d),filename(d_f)
47 {
48 }
49 HDF5CFInt64::~HDF5CFInt64()
50 {
51 }
52 BaseType *HDF5CFInt64::ptr_duplicate()
53 {
54  return new HDF5CFInt64(*this);
55 }
56 
57 bool HDF5CFInt64::read()
58 {
59 
60  BESDEBUG("h5","Coming to HDF5CFInt64 read "<<endl);
61 
62  if (read_p())
63  return true;
64 
65  hid_t file_id = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
66  if(file_id < 0) {
67  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
68  }
69 
70  hid_t dset_id = -1;
71  dset_id = H5Dopen2(file_id,dataset().c_str(),H5P_DEFAULT);
72 
73  if(dset_id < 0) {
74  H5Fclose(file_id);
75  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the dataset .");
76  }
77 
78  try {
79  dods_int64 buf;
80  get_data(dset_id, (void *) &buf);
81 
82  set_read_p(true);
83  set_value(buf);
84 
85  // Release the handles.
86  if (H5Dclose(dset_id) < 0) {
87  throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
88  }
89  H5Fclose(file_id);
90  }
91  catch(...) {
92  H5Dclose(dset_id);
93  H5Fclose(file_id);
94  throw;
95  }
96 
97  return true;
98 
99 }
100 
get_data
void get_data(hid_t dset, void *buf)
Definition: h5common.cc:50
libdap
Definition: BESDapFunctionResponseCache.h:35
HDF5CFInt64
Definition: HDF5CFInt64.h:41
HDF5CFInt64.h
This class provides a way to map HDF5 64-bit integer to DAP4 Int64 for the CF option.
h5common.h