-
Notifications
You must be signed in to change notification settings - Fork 3
/
HDF5CFUInt16.cc
100 lines (81 loc) · 2.85 KB
/
HDF5CFUInt16.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
// This file is part of the hdf5_handler implementing for the CF-compliant
// Copyright (c) 2011-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 HDF5CFUInt16.cc
/// \brief The implementation of mapping HDF5 unsigned 16-bit integer to DAP uint16 for the CF option
///
/// In the future, this may be merged with the default option.
/// \author Muqun Yang <myang6@hdfgroup.org>
///
////////////////////////////////////////////////////////////////////////////////
#include "config_hdf5.h"
#include <libdap/InternalErr.h>
#include "HDF5CFUInt16.h"
#include <BESDebug.h>
#include "h5common.h"
using namespace std;
using namespace libdap;
HDF5CFUInt16::HDF5CFUInt16(const string &n, const string &d) : UInt16(n, d)
{
}
HDF5CFUInt16::HDF5CFUInt16(const string &n, const string &d,const string &d_f) : UInt16(n, d),filename(d_f)
{
}
HDF5CFUInt16::~HDF5CFUInt16()
{
}
BaseType *HDF5CFUInt16::ptr_duplicate()
{
return new HDF5CFUInt16(*this);
}
bool HDF5CFUInt16::read()
{
BESDEBUG("h5","Coming to HDF5CFUInt16 read "<<endl);
if (read_p())
return true;
hid_t file_id = -1;
if ((file_id = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
throw InternalErr (__FILE__, __LINE__, "Failed to obtain the HDF5 file ID.");
}
hid_t dset_id = -1;
dset_id = H5Dopen2(file_id,dataset().c_str(),H5P_DEFAULT);
if(dset_id < 0) {
H5Fclose(file_id);
throw InternalErr(__FILE__,__LINE__, "Fail to obtain the dataset .");
}
try {
dods_uint16 buf;
get_data(dset_id, (void *) &buf);
set_read_p(true);
set_value(buf);
// Release the handles.
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;
}