bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDF5Float32.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 Kent Yang
5// <myang6@hdfgroup.org>
6
7// Copyright (c) 2009-2023 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 410 E University Ave,
25// Suite 200, Champaign, IL 61820
26
27
35
36#include <memory>
37#include <string>
38#include "BESDebug.h"
39#include "h5dds.h"
40#include <libdap/InternalErr.h>
41#include "HDF5Float32.h"
42
43
44using namespace std;
45using namespace libdap;
46HDF5Float32::HDF5Float32(const string & n, const string &vpath, const string &d) : Float32(n, d),var_path(vpath)
47{
48}
49
51{
52 auto HDF5Float32_unique = make_unique<HDF5Float32>(*this);
53 return HDF5Float32_unique.release();
54}
55
57{
58 BESDEBUG("h5", ">HDFFloat32::read() dataset=" << dataset() << endl);
59 if (read_p())
60 return true;
61
62 hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
63 if(file_id < 0) {
64 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
65 }
66
67 hid_t dset_id = -1;
68 if(true == is_dap4())
69 dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
70 else
71 dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
72
73 if(dset_id < 0) {
74 H5Fclose(file_id);
75 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
76 }
77
78
79 try {
80 dods_float32 buf;
81 get_data(dset_id, (void *) &buf);
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
90 H5Fclose(file_id);
91 }
92 catch(...) {
93 H5Dclose(dset_id);
94 H5Fclose(file_id);
95 throw;
96 }
97
98 return true;
99}
100
A class for mapping HDF5 32-bit float to DAP for the default option.
HDF5Float32(const std::string &n, const std::string &vpath, const std::string &d)
Constructor.
bool read() override
Reads HDF5 32-bit float data into local buffer.
libdap::BaseType * ptr_duplicate() override
void get_data(hid_t dset, void *buf)
Data structure and retrieval processing header for the default option.