bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDFEOS2CFStr.cc
1
2// This file is part of the hdf4 data handler for the OPeNDAP data server.
3// It retrieves the HDF-EOS2 swath or grid DFNT_CHAR 1D array field and
4// then send to DAP as DAP string for the CF option.
5// Authors: Kent Yang <myang6@hdfgroup.org>
6// Copyright (c) The HDF Group
8
9#ifdef USE_HDFEOS2_LIB
10#include "config.h"
11#include "config_hdf.h"
12
13#include <iostream>
14#include <sstream>
15#include <cassert>
16#include <libdap/debug.h>
17#include <libdap/InternalErr.h>
18#include <BESDebug.h>
19#include <BESLog.h>
20
21#include "HDFCFUtil.h"
22#include "HDFEOS2CFStr.h"
23#include "HDF4RequestHandler.h"
24
25using namespace std;
26using namespace libdap;
27
28HDFEOS2CFStr::HDFEOS2CFStr(const int gsfd,
29 const std::string &filename,
30 const std::string &objname,
31 const std::string &varname,
32 const std::string &varnewname,
33 int grid_or_swath)
34 :Str(varnewname,filename),
35 gsfd(gsfd),
36 filename(filename),
37 objname(objname),
38 varname(varname),
39 grid_or_swath(grid_or_swath)
40{
41}
42
43HDFEOS2CFStr::~HDFEOS2CFStr() = default;
44
45BaseType *HDFEOS2CFStr::ptr_duplicate()
46{
47 return new HDFEOS2CFStr(*this);
48}
49
50bool
51HDFEOS2CFStr::read ()
52{
53
54 BESDEBUG("h4","Coming to HDFEOS2CFStr read "<<endl);
55
56 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
57
58
59 int32 (*openfunc) (char *, intn);
60 intn (*closefunc) (int32);
61 int32 (*attachfunc) (int32, char *);
62 intn (*detachfunc) (int32);
63 intn (*fieldinfofunc) (int32, char *, int32 *, int32 *, int32 *, char *);
64 intn (*readfieldfunc) (int32, char *, int32 *, int32 *, int32 *, void *);
65
66
67 // Define function pointers to handle the swath
68 if (grid_or_swath == 0) {
69 openfunc = GDopen;
70 closefunc = GDclose;
71 attachfunc = GDattach;
72 detachfunc = GDdetach;
73 fieldinfofunc = GDfieldinfo;
74 readfieldfunc = GDreadfield;
75
76 }
77 else {
78 openfunc = SWopen;
79 closefunc = SWclose;
80 attachfunc = SWattach;
81 detachfunc = SWdetach;
82 fieldinfofunc = SWfieldinfo;
83 readfieldfunc = SWreadfield;
84 }
85
86 int32 gfid = -1;
87 if (false == check_pass_fileid_key) {
88
89 // Obtain the EOS object ID(either grid or swath)
90 gfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
91 if (gfid < 0) {
92 ostringstream eherr;
93 eherr << "File " << filename.c_str () << " cannot be open.";
94 throw InternalErr (__FILE__, __LINE__, eherr.str ());
95 }
96
97 }
98 else
99 gfid = gsfd;
100
101 int32 gsid = attachfunc (gfid, const_cast < char *>(objname.c_str ()));
102 if (gsid < 0) {
103 if (false == check_pass_fileid_key)
104 closefunc(gfid);
105 ostringstream eherr;
106 eherr << "Grid/Swath " << objname.c_str () << " cannot be attached.";
107 throw InternalErr (__FILE__, __LINE__, eherr.str ());
108 }
109
110 // Initialize the temp. returned value.
111 intn r = 0;
112 int32 tmp_rank = 0;
113 char tmp_dimlist[1024];
114 int32 tmp_dims[1];
115 int32 field_dtype = 0;
116
117 r = fieldinfofunc (gsid, const_cast < char *>(varname.c_str ()),
118 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
119 if (r != 0) {
120 detachfunc(gsid);
121 if (false == check_pass_fileid_key)
122 closefunc(gfid);
123 ostringstream eherr;
124 eherr << "Field " << varname.c_str () << " information cannot be obtained.";
125 throw InternalErr (__FILE__, __LINE__, eherr.str ());
126 }
127
128
129 vector<int32>offset32;
130 offset32.resize(1);
131 vector<int32>count32;
132 count32.resize(1);
133 vector<int32>step32;
134 step32.resize(1);
135 offset32[0] = 0;
136 count32[0] = tmp_dims[0];
137 step32[0] = 1;
138
139 vector<char>val;
140 val.resize(count32[0]);
141
142 r = readfieldfunc(gsid,const_cast<char*>(varname.c_str()),
143 offset32.data(), step32.data(), count32.data(), val.data());
144
145 if (r != 0) {
146 detachfunc(gsid);
147 if (false == check_pass_fileid_key)
148 closefunc(gfid);
149 ostringstream eherr;
150 eherr << "swath or grid readdata failed.";
151 throw InternalErr (__FILE__, __LINE__, eherr.str ());
152 }
153
154 string final_str(val.begin(),val.end());
155 set_value(final_str);
156 detachfunc(gsid);
157 if (false == check_pass_fileid_key)
158 closefunc(gfid);
159 return false;
160}
161
162
163#endif
This class provides a way to map HDFEOS2 1-D character array to DAP Str for the CF option.
STL class.
STL class.