bes  Updated for version 3.20.8
HE5Parser.cc
1 // This file is part of the hdf5 data handler for the OPeNDAP data server.
3 //
4 // Author: Hyo-Kyung Lee <hyoklee@hdfgroup.org>
5 //
6 // Copyright (c) 2007-2016 The HDF Group, Inc. and OPeNDAP, Inc.
7 //
8 // This is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License as published by the Free
10 // Software Foundation; either version 2.1 of the License, or (at your
11 // option) any later version.
12 //
13 // This software is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 // License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
24 // Suite 203, Champaign, IL 61820
25 
26 #include "HE5Parser.h"
27 #include <InternalErr.h>
28 #include <HDF5CFUtil.h>
29 #include <stdlib.h>
30 
31 using namespace std;
32 
33 HE5Parser::HE5Parser()
34 {
35  structure_state = -1; // Za/Swath/Grid state
36  parser_state = 0; // Parser's current state
37  err_msg = ""; // error message.
38 }
39 
40 HE5Parser::~HE5Parser()
41 {
42 }
43 
44 
46 {
47  unsigned int i = 0;
48 
49  if(err_msg != ""){
50  cerr<< "Parse error:" << err_msg << endl;
51  }
52  cout << "ZA Size=" << za_list.size() << endl;
53  for(i=0; i < za_list.size(); i++) {
54  HE5Za z = za_list.at(i);
55  cout << "ZA Name=" << z.name << endl;
56  cout << "ZA Dim Size=" << z.dim_list.size() << endl;
57  unsigned int j = 0;
58  for(j=0; j < z.dim_list.size(); j++) {
59  HE5Dim d = z.dim_list.at(j);
60  cout << "ZA Dim Name=" << d.name;
61  cout << " Size=" << d.size << endl;
62  }
63 
64  cout << "ZA Var Size=" << z.data_var_list.size()
65  << endl;
66  for(j=0; j < z.data_var_list.size(); j++) {
67  HE5Var v = z.data_var_list.at(j);
68  cout << "ZA Var Name=" << v.name << endl;
69  cout << "ZA Var Dim Size=" << v.dim_list.size() << endl;
70  for(unsigned int k=0; k < v.dim_list.size(); k++) {
71  HE5Dim d = v.dim_list.at(k);
72  cout << "ZA Var Dim Name=" << d.name << endl;
73  }
74  }
75  }
76 
77  cout << "Swath Size=" << swath_list.size() << endl;
78  for(i=0; i < swath_list.size(); i++) {
79  HE5Swath s = swath_list.at(i);
80  cout << "Swath Name=" << s.name << endl;
81  cout << "Swath Dim Size=" << s.dim_list.size() << endl;
82  unsigned int j = 0;
83  for(j=0; j < s.dim_list.size(); j++) {
84  HE5Dim d = s.dim_list.at(j);
85  cout << "Swath Dim Name=" << d.name;
86  cout << " Size=" << d.size << endl;
87  }
88 
89  cout << "Swath Geo Var Size=" << s.geo_var_list.size()
90  << endl;
91  for(j=0; j < s.geo_var_list.size(); j++) {
92  HE5Var v = s.geo_var_list.at(j);
93  cout << "Swath Geo Var Name=" << v.name << endl;
94  cout << "Swath Geo Var Dim Size=" << v.dim_list.size() << endl;
95  for(unsigned int k=0; k < v.dim_list.size(); k++) {
96  HE5Dim d = v.dim_list.at(k);
97  cout << "Swath Geo Var Dim Name=" << d.name;
98  cout << " Size=" << d.size << endl;
99  }
100  }
101 
102  cout << "Swath Data Var Size=" << s.data_var_list.size()
103  << endl;
104  for(j=0; j < s.data_var_list.size(); j++) {
105  HE5Var v = s.data_var_list.at(j);
106  cout << "Swath Data Var Name=" << v.name << endl;
107  cout << "Swath Data Var Number Dim =" << v.dim_list.size() << endl;
108  for(unsigned int k=0; k < v.dim_list.size(); k++) {
109  HE5Dim d = v.dim_list.at(k);
110  cout << "Swath Data Var Dim Name=" << d.name << endl;
111  cout <<"Swath Data Var Dim Size= "<< d.size<<endl;
112  }
113 // UNCOMMENT OUT the block below to retrieve the maximum dimension list. ALSO NEED TO ADD MAX_DIMENSION_LIST at he5dds.lex.
114 #if 0
115  for(k=0; k < v.max_dim_list.size(); k++) {
116  HE5Dim d = v.max_dim_list.at(k);
117  cout << "Swath Data Var Max Dim Name=" << d.name << endl;
118  cout <<"Swath Data Var Dim Size= "<< d.size<<endl;
119  }
120 #endif
121  }
122  }
123 
124  cout << "Grid Size=" << grid_list.size() << endl;
125  for(i=0; i < grid_list.size(); i++) {
126  HE5Grid g = grid_list.at(i);
127  cout << "Grid Name=" << g.name << endl;
128 
129  cout << "Grid point_lower=" << g.point_lower << endl;
130  cout << "Grid point_upper=" << g.point_upper << endl;
131  cout << "Grid point_left=" << g.point_left << endl;
132  cout << "Grid point_right=" << g.point_right << endl;
133  cout << "Grid Sphere code =" <<g.sphere <<endl;
134 
135  cout << "Grid Dim Size=" << g.dim_list.size() << endl;
136  unsigned int j = 0;
137  for(j=0; j < g.dim_list.size(); j++) {
138  HE5Dim d = g.dim_list.at(j);
139  cout << "Grid Dim Name=" << d.name;
140  cout << " Size=" << d.size << endl;
141  }
142 
143  cout << "Grid Var Size=" << g.data_var_list.size()
144  << endl;
145  for(j=0; j < g.data_var_list.size(); j++) {
146  HE5Var v = g.data_var_list.at(j);
147  cout << "Grid Var Name=" << v.name << endl;
148  cout << "Grid Var Dim Size=" << v.dim_list.size() << endl;
149  for(unsigned int k=0; k < v.dim_list.size(); k++) {
150  HE5Dim d = v.dim_list.at(k);
151  cout << "Grid Var Dim Name=" << d.name << endl;
152  }
153 #if 0
154  for(k=0; k < v.max_dim_list.size(); k++) {
155  HE5Dim d = v.max_dim_list.at(k);
156  cout << "Grid Var Max Dim Name=" << d.name << endl;
157  }
158 #endif
159  }
160  cout << "Grid pixelregistration=" <<
161  g.pixelregistration
162  << endl;
163  cout << "Grid origin=" <<
164  g.gridorigin
165  << endl;
166  cout << "Grid projection=" <<
167  g.projection
168  << endl;
169 
170  cout <<"Grid zone= "<< g.zone<<endl;
171  cout <<"Grid sphere= "<<g.sphere<<endl;
172 
173  cout<<"Grid projection parameters are "<<endl;
174  for(j= 0;j<13;j++)
175  cout<<g.param[j]<<endl;
176  }
177 
178 }
179 
180 void HE5Parser::add_projparams(const string & st_str) {
181 
182  string projparms = "ProjParams=(";
183  char parms_end_marker = ')';
184  size_t parms_spos = st_str.find(projparms);
185  int grid_index = 0;
186  while(parms_spos!=string::npos) {
187  size_t parms_epos = st_str.find(parms_end_marker,parms_spos);
188  if(parms_epos == string::npos)
189  throw libdap::InternalErr(__FILE__,__LINE__,"HDF-EOS5 Grid ProjParms syntax error: ProjParams doesn't end with ')'. ");
190  string projparms_raw_values = st_str.substr(parms_spos+projparms.size(),parms_epos-parms_spos-projparms.size());
191  vector<string> projparms_values;
192  HDF5CFUtil::Split(projparms_raw_values.c_str(),',',projparms_values);
193 
194  for(unsigned int i = 0; i<projparms_values.size();i++) {
195  grid_list[grid_index].param[i] = strtod(projparms_values[i].c_str(),NULL);
196  }
197 #if 0
198 for(vector<string>::iterator istr=projparms_values.begin();istr!=projparms_values.end();++istr)
199 cerr<<"projparms value is "<<*istr<<endl;
200 #endif
201  parms_spos = st_str.find(projparms,parms_epos);
202  grid_index++;
203  }
204 
205 }
This file includes several helper functions for translating HDF5 to CF-compliant.
A class for parsing NASA HDF-EOS5 StructMetadata.
void print()
Print the information about the members of the Vector list.
Definition: HE5Parser.cc:45
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
Definition: HDF5CFUtil.cc:335
Definition: HE5Dim.h:7
double point_right
The rightmost coordinate value of a Grid.
Definition: HE5Grid.h:25
double point_upper
The top coordinate value of a Grid.
Definition: HE5Grid.h:21
double point_left
The leftmost coordinate value of a Grid.
Definition: HE5Grid.h:23
double point_lower
The bottom coordinate value of a Grid.
Definition: HE5Grid.h:19
Definition: HE5Var.h:8
Definition: HE5Za.h:6