bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDF5CFFloat32.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-2023 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 410 E University Ave,
22// Suite 200, Champaign, IL 61820
23
32
33#include <memory>
34#include <libdap/InternalErr.h>
35#include "HDF5CFFloat32.h"
36#include <BESDebug.h>
37#include "h5common.h"
38
39using namespace libdap;
40using namespace std;
41HDF5CFFloat32::HDF5CFFloat32(const string & n, const string &d) : Float32(n, d)
42{
43}
44
45HDF5CFFloat32::HDF5CFFloat32(const string &n, const string &d,const string &d_f) : Float32(n, d),filename(d_f)
46{
47}
48BaseType *HDF5CFFloat32::ptr_duplicate()
49{
50 auto HDF5CFFloat32_unique = make_unique<HDF5CFFloat32>(*this);
51 return HDF5CFFloat32_unique.release();
52}
53
54bool HDF5CFFloat32::read()
55{
56 BESDEBUG("h5","Coming to HDF5CFFloat32 read "<<endl);
57
58 if (read_p())
59 return true;
60
61 hid_t file_id = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
62 if(file_id < 0) {
63 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
64 }
65
66 hid_t dset_id = -1;
67 dset_id = H5Dopen2(file_id,dataset().c_str(),H5P_DEFAULT);
68
69 if(dset_id < 0) {
70 H5Fclose(file_id);
71 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the dataset .");
72 }
73
74 try {
75 dods_float32 buf;
76 get_data(dset_id, (void *) &buf);
77
78 set_read_p(true);
79 set_value(buf);
80
81 // Release the handles.
82 if (H5Dclose(dset_id) < 0) {
83 throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
84 }
85 H5Fclose(file_id);
86 }
87 catch(...) {
88 H5Dclose(dset_id);
89 H5Fclose(file_id);
90 throw;
91 }
92
93 return true;
94
95
96}
This class provides a way to map HDF5 float to DAP float for the CF option.
void get_data(hid_t dset, void *buf)