OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFEOS2CFStr.cc
Go to the documentation of this file.
1 // 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: MuQun Yang <myang6@hdfgroup.org>
6 // Copyright (c) 2010-2012 The HDF Group
8 
9 #ifdef USE_HDFEOS2_LIB
10 #include <iostream>
11 #include <sstream>
12 #include <cassert>
13 #include <debug.h>
14 #include "InternalErr.h"
15 #include <BESDebug.h>
16 #include <BESLog.h>
17 
18 #include "HDFCFUtil.h"
19 #include "HDFEOS2CFStr.h"
20 
21 using namespace std;
22 
23 HDFEOS2CFStr::HDFEOS2CFStr(const int gsfd,
24  const std::string &filename,
25  const std::string &objname,
26  const std::string &varname,
27  const std::string &varnewname,
28  int grid_or_swath)
29  :Str(varnewname,filename),
30  gsfd(gsfd),
31  filename(filename),
32  objname(objname),
33  varname(varname),
34  grid_or_swath(grid_or_swath)
35 {
36 }
37 
38 HDFEOS2CFStr::~HDFEOS2CFStr()
39 {
40 }
41 BaseType *HDFEOS2CFStr::ptr_duplicate()
42 {
43  return new HDFEOS2CFStr(*this);
44 }
45 
46 bool
47 HDFEOS2CFStr::read ()
48 {
49 
50  BESDEBUG("h4","Coming to HDFEOS2CFStr read "<<endl);
51 
52  string check_pass_fileid_key_str="H4.EnablePassFileID";
53  bool check_pass_fileid_key = false;
54  check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
55 
56 
57  int32 (*openfunc) (char *, intn);
58  intn (*closefunc) (int32);
59  int32 (*attachfunc) (int32, char *);
60  intn (*detachfunc) (int32);
61  intn (*fieldinfofunc) (int32, char *, int32 *, int32 *, int32 *, char *);
62  intn (*readfieldfunc) (int32, char *, int32 *, int32 *, int32 *, void *);
63  int32 (*inqfunc) (char *, char *, int32 *);
64 
65 
66  // Define function pointers to handle the swath
67  if(grid_or_swath == 0) {
68  openfunc = GDopen;
69  closefunc = GDclose;
70  attachfunc = GDattach;
71  detachfunc = GDdetach;
72  fieldinfofunc = GDfieldinfo;
73  readfieldfunc = GDreadfield;
74  inqfunc = GDinqgrid;
75 
76  }
77  else {
78  openfunc = SWopen;
79  closefunc = SWclose;
80  attachfunc = SWattach;
81  detachfunc = SWdetach;
82  fieldinfofunc = SWfieldinfo;
83  readfieldfunc = SWreadfield;
84  inqfunc = SWinqswath;
85  }
86 
87  int32 gfid = -1;
88  if (false == check_pass_fileid_key) {
89 
90  // Obtain the EOS object ID(either grid or swath)
91  gfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
92  if (gfid < 0) {
93  ostringstream eherr;
94  eherr << "File " << filename.c_str () << " cannot be open.";
95  throw InternalErr (__FILE__, __LINE__, eherr.str ());
96  }
97 
98  }
99  else
100  gfid = gsfd;
101 
102  int32 gsid = attachfunc (gfid, const_cast < char *>(objname.c_str ()));
103  if (gsid < 0) {
104  if(false == check_pass_fileid_key)
105  closefunc(gfid);
106  ostringstream eherr;
107  eherr << "Grid/Swath " << objname.c_str () << " cannot be attached.";
108  throw InternalErr (__FILE__, __LINE__, eherr.str ());
109  }
110 
111  // Initialize the temp. returned value.
112  intn r = 0;
113  int32 tmp_rank = 0;
114  char tmp_dimlist[1024];
115  int32 tmp_dims[1];
116  int32 field_dtype = 0;
117 
118  r = fieldinfofunc (gsid, const_cast < char *>(varname.c_str ()),
119  &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
120  if (r != 0) {
121  detachfunc(gsid);
122  if(false == check_pass_fileid_key)
123  closefunc(gfid);
124  ostringstream eherr;
125  eherr << "Field " << varname.c_str () << " information cannot be obtained.";
126  throw InternalErr (__FILE__, __LINE__, eherr.str ());
127  }
128 
129 
130  vector<int32>offset32;
131  offset32.resize(1);
132  vector<int32>count32;
133  count32.resize(1);
134  vector<int32>step32;
135  step32.resize(1);
136  offset32[0] = 0;
137  count32[0] = tmp_dims[0];
138  step32[0] = 1;
139 
140  vector<char>val;
141  val.resize(count32[0]);
142 
143  r = readfieldfunc(gsid,const_cast<char*>(varname.c_str()),
144  &offset32[0], &step32[0], &count32[0], &val[0]);
145 
146  if (r != 0) {
147  detachfunc(gsid);
148  if(false == check_pass_fileid_key)
149  closefunc(gfid);
150  ostringstream eherr;
151  eherr << "swath or grid readdata failed.";
152  throw InternalErr (__FILE__, __LINE__, eherr.str ());
153  }
154 
155  string final_str(val.begin(),val.end());
156  set_value(final_str);
157  detachfunc(gsid);
158  if(false == check_pass_fileid_key)
159  closefunc(gfid);
160  return false;
161 }
162 
163 
164 #endif
STL namespace.
static bool check_beskeys(const std::string &key)
Check the BES key. This function will check a BES key specified at the file h4.conf.in. If the key's value is either true or yes. The handler claims to find a key and will do some operations. Otherwise, will do different operations. For example, One may find a line H4.EnableCF=true at h4.conf.in. That means, the HDF4 handler will handle the HDF4 files by following CF conventions.
Definition: HDFCFUtil.cc:17
This class provides a way to map HDFEOS2 1-D character array to DAP Str for the CF option...
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64