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