bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDF5Url.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
39#include <string>
40#include <memory>
41#include "HDF5Url.h"
42#include <libdap/InternalErr.h>
43
44using namespace std;
45using namespace libdap;
46
47HDF5Url::HDF5Url(const string &n, const string &vpath,const string &d) : Url(n, d),var_path(vpath)
48{
49}
50
52{
53 auto HDF5Url_unique = make_unique<HDF5Url>(*this);
54 return HDF5Url_unique.release();
55}
56
58{
59
60 hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
61 if(file_id < 0) {
62 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
63 }
64
65 hid_t dset_id = -1;
66 if(true == is_dap4())
67 dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
68 else
69 dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
70
71 if(dset_id < 0) {
72 H5Fclose(file_id);
73 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
74 }
75
76 hobj_ref_t rbuf;
77
78 if (H5Dread(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT,
79 &rbuf) < 0) {
80 H5Dclose(dset_id);
81 H5Fclose(file_id);
82 throw InternalErr(__FILE__, __LINE__, "H5Dread() failed.");
83 }
84
85 hid_t did_r = H5RDEREFERENCE(dset_id, H5R_OBJECT, &rbuf);
86 char r_name[DODS_NAMELEN];
87 if (did_r < 0){
88 H5Dclose(dset_id);
89 H5Fclose(file_id);
90 throw InternalErr(__FILE__, __LINE__, "H5RDEREFERENCE() failed.");
91 }
92 if (H5Iget_name(did_r, r_name, DODS_NAMELEN) < 0){
93 H5Dclose(dset_id);
94 H5Fclose(file_id);
95 throw InternalErr(__FILE__, __LINE__, "Unable to retrieve the name of the object.");
96 }
97 string reference = r_name;
98 set_value(reference);
99
100 // Release the handles.
101 H5Dclose(dset_id);
102 H5Fclose(file_id);
103
104
105 return true;
106}
107
This class generates DAP URL type for the default option.
bool read() override
Reads HDF5 reference data into local buffer as a string.
Definition HDF5Url.cc:57
libdap::BaseType * ptr_duplicate() override
Definition HDF5Url.cc:51
HDF5Url(const std::string &n, const std::string &vname, const std::string &d)
Constructor.
Definition HDF5Url.cc:47
const int DODS_NAMELEN
Maximum length of variable or attribute name(default option only).