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