bes  Updated for version 3.20.6
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 "InternalErr.h"
45 
46 using namespace std;
47 using namespace libdap;
48 
49 HDF5Url::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 // hid_t dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
73  if(dset_id < 0) {
74  H5Fclose(file_id);
75  throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
76  }
77 
78  hobj_ref_t rbuf;
79 
80  if (H5Dread(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT,
81  &rbuf) < 0) {
82  H5Dclose(dset_id);
83  H5Fclose(file_id);
84  throw InternalErr(__FILE__, __LINE__, "H5Dread() failed.");
85  }
86 
87  hid_t did_r = H5RDEREFERENCE(dset_id, H5R_OBJECT, &rbuf);
88  char r_name[DODS_NAMELEN];
89  if (did_r < 0){
90  H5Dclose(dset_id);
91  H5Fclose(file_id);
92  throw InternalErr(__FILE__, __LINE__, "H5RDEREFERENCE() failed.");
93  }
94  if (H5Iget_name(did_r, r_name, DODS_NAMELEN) < 0){
95  H5Dclose(dset_id);
96  H5Fclose(file_id);
97  throw InternalErr(__FILE__, __LINE__, "Unable to retrieve the name of the object.");
98  }
99  string reference = r_name;
100  set_value(reference);
101 
102  // Release the handles.
103  H5Dclose(dset_id);
104  H5Fclose(file_id);
105 
106 
107  return true;
108 }
109 
DODS_NAMELEN
const int DODS_NAMELEN
Maximum length of variable or attribute name(default option only).
Definition: hdf5_handler.h:64
HDF5Url::ptr_duplicate
virtual libdap::BaseType * ptr_duplicate()
Definition: HDF5Url.cc:53
HDF5Url::read
virtual bool read()
Reads HDF5 reference data into local buffer as a string.
Definition: HDF5Url.cc:58
libdap
Definition: BESDapFunctionResponseCache.h:35
HDF5Url::HDF5Url
HDF5Url(const std::string &n, const std::string &vname, const std::string &d)
Constructor.
Definition: HDF5Url.cc:49
HDF5Url.h
This class generates DAP URL type for the default option.