bes Updated for version 3.20.13
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 Muqun Yang
5// <myang6@hdfgroup.org>
6
7// Copyright (c) 2009-2016 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 1800 South Oak Street,
25// Suite 203, Champaign, IL 61820
26
36
37
38#include "config_hdf5.h"
39
40#include <string>
41#include <ctype.h>
42
43#include "HDF5Url.h"
44#include <libdap/InternalErr.h>
45
46using namespace std;
47using namespace libdap;
48
49HDF5Url::HDF5Url(const string &n, const string &vpath,const string &d) : Url(n, d),var_path(vpath)
50{
51}
52
54{
55 return new HDF5Url(*this);
56}
57
59{
60
61 hid_t file_id = H5Fopen(dataset().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 if(true == is_dap4())
68 dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
69 else
70 dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
71
72 if(dset_id < 0) {
73 H5Fclose(file_id);
74 throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
75 }
76
77 hobj_ref_t rbuf;
78
79 if (H5Dread(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT,
80 &rbuf) < 0) {
81 H5Dclose(dset_id);
82 H5Fclose(file_id);
83 throw InternalErr(__FILE__, __LINE__, "H5Dread() failed.");
84 }
85
86 hid_t did_r = H5RDEREFERENCE(dset_id, H5R_OBJECT, &rbuf);
87 char r_name[DODS_NAMELEN];
88 if (did_r < 0){
89 H5Dclose(dset_id);
90 H5Fclose(file_id);
91 throw InternalErr(__FILE__, __LINE__, "H5RDEREFERENCE() failed.");
92 }
93 if (H5Iget_name(did_r, r_name, DODS_NAMELEN) < 0){
94 H5Dclose(dset_id);
95 H5Fclose(file_id);
96 throw InternalErr(__FILE__, __LINE__, "Unable to retrieve the name of the object.");
97 }
98 string reference = r_name;
99 set_value(reference);
100
101 // Release the handles.
102 H5Dclose(dset_id);
103 H5Fclose(file_id);
104
105
106 return true;
107}
108
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:58
libdap::BaseType * ptr_duplicate() override
Definition: HDF5Url.cc:53
HDF5Url(const std::string &n, const std::string &vname, const std::string &d)
Constructor.
Definition: HDF5Url.cc:49
const int DODS_NAMELEN
Maximum length of variable or attribute name(default option only).
Definition: hdf5_handler.h:65