-
Notifications
You must be signed in to change notification settings - Fork 3
/
HDF5UInt64.cc
105 lines (84 loc) · 2.82 KB
/
HDF5UInt64.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// This file is part of hdf5_handler a HDF5 file handler for the OPeNDAP
// data server.
// Author: Hyo-Kyung Lee <hyoklee@hdfgroup.org> and Muqun Yang
// <myang6@hdfgroup.org>
// Copyright (c) 2009-2016 The HDF Group, Inc. and OPeNDAP, Inc.
//
// This is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your
// option) any later version.
//
// This software is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// You can contact The HDF Group, Inc. at 1800 South Oak Street,
// Suite 203, Champaign, IL 61820
/// \file HDF5UInt64.cc
/// \brief Implementation of mapping HDF5 byte to DAP UInt64 for the default option.
///
///
/// \author Hyo-Kyung Lee (hyoklee@hdfgroup.org)
/// \author Kent Yang (ymuqun@hdfgroup.org)
/// \author James Gallagher (jgallagher@opendap.org)
///
// #define DODS_DEBUG
#include <string>
#include <ctype.h>
#include "config_hdf5.h"
#include "BESDebug.h"
#include <libdap/InternalErr.h>
#include "h5dds.h"
#include "HDF5UInt64.h"
using namespace std;
using namespace libdap;
HDF5UInt64::HDF5UInt64(const string & n, const string &vpath, const string &d):UInt64(n, d)
{
var_path = vpath;
}
BaseType *HDF5UInt64::ptr_duplicate()
{
return new HDF5UInt64(*this);
}
bool HDF5UInt64::read()
{
if (read_p())
return true;
hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
if(file_id < 0) {
throw InternalErr(__FILE__,__LINE__, "Fail to obtain the HDF5 file ID .");
}
hid_t dset_id = -1;
if(true == is_dap4())
dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
else
dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
// hid_t dset_id = H5Dopen2(file_id,name().c_str(),H5P_DEFAULT);
if(dset_id < 0) {
H5Fclose(file_id);
throw InternalErr(__FILE__,__LINE__, "Fail to obtain the datatype .");
}
try {
dods_uint64 buf;
get_data(dset_id, (void *) &buf);
set_read_p(true);
set_value(buf);
if (H5Dclose(dset_id) < 0) {
throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
}
H5Fclose(file_id);
}
catch(...) {
H5Dclose(dset_id);
H5Fclose(file_id);
throw;
}
return true;
}