bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDF5Byte.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
35
36
37// #define DODS_DEBUG
38#include <string>
39#include <ctype.h>
40#include <memory>
41
42#include "config_hdf5.h"
43#include "BESDebug.h"
44#include <libdap/InternalErr.h>
45#include "h5dds.h"
46#include "HDF5Byte.h"
47
48
49using namespace std;
50using namespace libdap;
51
52#if 0
53HDF5Byte::HDF5Byte(const string & n, const string &vpath, const string &d):Byte(n, d)
54{
55 var_path = vpath;
56}
57#endif
58
60{
61 auto HDF5Byte_unique = make_unique<HDF5Byte>(*this);
62 return HDF5Byte_unique.release();
63}
64
66{
67 if (read_p())
68 return true;
69
70 hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
71 if(file_id < 0) {
72 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
73 }
74
75 hid_t dset_id = -1;
76
77 if(true == is_dap4())
78 dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
79 else
80 dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
81
82 if(dset_id < 0) {
83 H5Fclose(file_id);
84 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
85 }
86
87
88 try {
89 dods_byte buf;
90 get_data(dset_id, (void *) &buf);
91 set_read_p(true);
92 set_value(buf);
93
94 if (H5Dclose(dset_id) < 0) {
95 throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
96 }
97
98 H5Fclose(file_id);
99 }
100
101 catch(...) {
102 H5Dclose(dset_id);
103 H5Fclose(file_id);
104 throw;
105 }
106
107 return true;
108}
109
This class provides a way to map HDF5 byte to DAP Byte for the default option.
HDF5Byte(const std::string &n, const std::string &vpath, const std::string &d)
Constructor.
Definition HDF5Byte.h:54
libdap::BaseType * ptr_duplicate() override
Definition HDF5Byte.cc:59
bool read() override
Reads HDF5 byte data into local buffer.
Definition HDF5Byte.cc:65
void get_data(hid_t dset, void *buf)
Data structure and retrieval processing header for the default option.