-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHDFEOS2CFStr.cc
More file actions
169 lines (141 loc) · 4.71 KB
/
HDFEOS2CFStr.cc
File metadata and controls
169 lines (141 loc) · 4.71 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/////////////////////////////////////////////////////////////////////////////
// This file is part of the hdf4 data handler for the OPeNDAP data server.
// It retrieves the HDF-EOS2 swath or grid DFNT_CHAR 1D array field and
// then send to DAP as DAP string for the CF option.
// Authors: MuQun Yang <myang6@hdfgroup.org>
// Copyright (c) 2010-2012 The HDF Group
/////////////////////////////////////////////////////////////////////////////
#ifdef USE_HDFEOS2_LIB
#include "config.h"
#include "config_hdf.h"
#include <iostream>
#include <sstream>
#include <cassert>
#include <libdap/debug.h>
#include <libdap/InternalErr.h>
#include <BESDebug.h>
#include <BESLog.h>
#include "HDFCFUtil.h"
#include "HDFEOS2CFStr.h"
#include "HDF4RequestHandler.h"
using namespace std;
using namespace libdap;
HDFEOS2CFStr::HDFEOS2CFStr(const int gsfd,
const std::string &filename,
const std::string &objname,
const std::string &varname,
const std::string &varnewname,
int grid_or_swath)
:Str(varnewname,filename),
gsfd(gsfd),
filename(filename),
objname(objname),
varname(varname),
grid_or_swath(grid_or_swath)
{
}
HDFEOS2CFStr::~HDFEOS2CFStr()
{
}
BaseType *HDFEOS2CFStr::ptr_duplicate()
{
return new HDFEOS2CFStr(*this);
}
bool
HDFEOS2CFStr::read ()
{
BESDEBUG("h4","Coming to HDFEOS2CFStr read "<<endl);
#if 0
string check_pass_fileid_key_str="H4.EnablePassFileID";
bool check_pass_fileid_key = false;
check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
#endif
bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
int32 (*openfunc) (char *, intn);
intn (*closefunc) (int32);
int32 (*attachfunc) (int32, char *);
intn (*detachfunc) (int32);
intn (*fieldinfofunc) (int32, char *, int32 *, int32 *, int32 *, char *);
intn (*readfieldfunc) (int32, char *, int32 *, int32 *, int32 *, void *);
// Define function pointers to handle the swath
if(grid_or_swath == 0) {
openfunc = GDopen;
closefunc = GDclose;
attachfunc = GDattach;
detachfunc = GDdetach;
fieldinfofunc = GDfieldinfo;
readfieldfunc = GDreadfield;
}
else {
openfunc = SWopen;
closefunc = SWclose;
attachfunc = SWattach;
detachfunc = SWdetach;
fieldinfofunc = SWfieldinfo;
readfieldfunc = SWreadfield;
}
int32 gfid = -1;
if (false == check_pass_fileid_key) {
// Obtain the EOS object ID(either grid or swath)
gfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
if (gfid < 0) {
ostringstream eherr;
eherr << "File " << filename.c_str () << " cannot be open.";
throw InternalErr (__FILE__, __LINE__, eherr.str ());
}
}
else
gfid = gsfd;
int32 gsid = attachfunc (gfid, const_cast < char *>(objname.c_str ()));
if (gsid < 0) {
if(false == check_pass_fileid_key)
closefunc(gfid);
ostringstream eherr;
eherr << "Grid/Swath " << objname.c_str () << " cannot be attached.";
throw InternalErr (__FILE__, __LINE__, eherr.str ());
}
// Initialize the temp. returned value.
intn r = 0;
int32 tmp_rank = 0;
char tmp_dimlist[1024];
int32 tmp_dims[1];
int32 field_dtype = 0;
r = fieldinfofunc (gsid, const_cast < char *>(varname.c_str ()),
&tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
if (r != 0) {
detachfunc(gsid);
if(false == check_pass_fileid_key)
closefunc(gfid);
ostringstream eherr;
eherr << "Field " << varname.c_str () << " information cannot be obtained.";
throw InternalErr (__FILE__, __LINE__, eherr.str ());
}
vector<int32>offset32;
offset32.resize(1);
vector<int32>count32;
count32.resize(1);
vector<int32>step32;
step32.resize(1);
offset32[0] = 0;
count32[0] = tmp_dims[0];
step32[0] = 1;
vector<char>val;
val.resize(count32[0]);
r = readfieldfunc(gsid,const_cast<char*>(varname.c_str()),
&offset32[0], &step32[0], &count32[0], &val[0]);
if (r != 0) {
detachfunc(gsid);
if(false == check_pass_fileid_key)
closefunc(gfid);
ostringstream eherr;
eherr << "swath or grid readdata failed.";
throw InternalErr (__FILE__, __LINE__, eherr.str ());
}
string final_str(val.begin(),val.end());
set_value(final_str);
detachfunc(gsid);
if(false == check_pass_fileid_key)
closefunc(gfid);
return false;
}
#endif