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