bes  Updated for version 3.20.6
HDF5Float64.cc
Go to the documentation of this file.
1 // This file is part of hdf5_handler a HDF5 file handler for the OPeNDAP
2 // data server.
3 
4 // Author: Hyo-Kyung Lee <hyoklee@hdfgroup.org> and Muqun Yang
5 // <myang6@hdfgroup.org>
6 
7 // Copyright (c) 2009-2016 The HDF Group, Inc. and OPeNDAP, Inc.
8 //
9 // This is free software; you can redistribute it and/or modify it under the
10 // terms of the GNU Lesser General Public License as published by the Free
11 // Software Foundation; either version 2.1 of the License, or (at your
12 // option) any later version.
13 //
14 // This software is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 // License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
25 // Suite 203, Champaign, IL 61820
26 
27 // #define DODS_DEBUG
28 
37 
38 
39 
40 #include <string>
41 #include <ctype.h>
42 #include "config_hdf5.h"
43 #include "InternalErr.h"
44 #include "h5dds.h"
45 #include "HDF5Float64.h"
46 #include "BESDebug.h"
47 
48 using namespace std;
49 using namespace libdap;
50 
51 HDF5Float64::HDF5Float64(const string & n, const string & vpath,const string &d) : Float64(n, d),var_path(vpath)
52 {
53 }
54 
56 {
57  return new HDF5Float64(*this);
58 }
59 
61 {
62  if (read_p())
63  return true;
64  hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
65  if(file_id < 0) {
66  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
67  }
68 
69  hid_t dset_id = -1;
70  if(true == is_dap4())
71  dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
72  else
73  dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
74 
75  if(dset_id < 0) {
76  H5Fclose(file_id);
77  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
78  }
79 
80  try {
81  dods_float64 buf;
82  get_data(dset_id, (void *) &buf);
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 
93  catch(...) {
94  H5Dclose(dset_id);
95  H5Fclose(file_id);
96  throw;
97  }
98 
99  return true;
100 }
101 
HDF5Float64::HDF5Float64
HDF5Float64(const std::string &n, const std::string &vpath, const std::string &d)
Constructor.
Definition: HDF5Float64.cc:51
HDF5Float64.h
A class for mapping HDF5 64-bit float to DAP for the default option.
h5dds.h
Data structure and retrieval processing header for the default option.
HDF5Float64::ptr_duplicate
virtual libdap::BaseType * ptr_duplicate()
Definition: HDF5Float64.cc:55
get_data
void get_data(hid_t dset, void *buf)
Definition: h5common.cc:50
HDF5Float64::read
virtual bool read()
Reads HDF5 64-bit float data into local buffer.
Definition: HDF5Float64.cc:60
libdap
Definition: BESDapFunctionResponseCache.h:35