bes  Updated for version 3.20.6
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  unsigned int k = 0;
71  for(k=0; k < v.dim_list.size(); k++) {
72  HE5Dim d = v.dim_list.at(k);
73  cout << "ZA Var Dim Name=" << d.name << endl;
74  }
75  }
76  }
77 
78  cout << "Swath Size=" << swath_list.size() << endl;
79  for(i=0; i < swath_list.size(); i++) {
80  HE5Swath s = swath_list.at(i);
81  cout << "Swath Name=" << s.name << endl;
82  cout << "Swath Dim Size=" << s.dim_list.size() << endl;
83  unsigned int j = 0;
84  for(j=0; j < s.dim_list.size(); j++) {
85  HE5Dim d = s.dim_list.at(j);
86  cout << "Swath Dim Name=" << d.name;
87  cout << " Size=" << d.size << endl;
88  }
89 
90  cout << "Swath Geo Var Size=" << s.geo_var_list.size()
91  << endl;
92  for(j=0; j < s.geo_var_list.size(); j++) {
93  HE5Var v = s.geo_var_list.at(j);
94  cout << "Swath Geo Var Name=" << v.name << endl;
95  cout << "Swath Geo Var Dim Size=" << v.dim_list.size() << endl;
96  unsigned int k = 0;
97  for(k=0; k < v.dim_list.size(); k++) {
98  HE5Dim d = v.dim_list.at(k);
99  cout << "Swath Geo Var Dim Name=" << d.name;
100  cout << " Size=" << d.size << endl;
101  }
102  }
103 
104  cout << "Swath Data Var Size=" << s.data_var_list.size()
105  << endl;
106  for(j=0; j < s.data_var_list.size(); j++) {
107  HE5Var v = s.data_var_list.at(j);
108  cout << "Swath Data Var Name=" << v.name << endl;
109  cout << "Swath Data Var Number Dim =" << v.dim_list.size() << endl;
110  unsigned int k = 0;
111  for(k=0; k < v.dim_list.size(); k++) {
112  HE5Dim d = v.dim_list.at(k);
113  cout << "Swath Data Var Dim Name=" << d.name << endl;
114  cout <<"Swath Data Var Dim Size= "<< d.size<<endl;
115  }
116 // UNCOMMENT OUT the block below to retrieve the maximum dimension list. ALSO NEED TO ADD MAX_DIMENSION_LIST at he5dds.lex.
117 #if 0
118  for(k=0; k < v.max_dim_list.size(); k++) {
119  HE5Dim d = v.max_dim_list.at(k);
120  cout << "Swath Data Var Max Dim Name=" << d.name << endl;
121  cout <<"Swath Data Var Dim Size= "<< d.size<<endl;
122  }
123 #endif
124  }
125  }
126 
127  cout << "Grid Size=" << grid_list.size() << endl;
128  for(i=0; i < grid_list.size(); i++) {
129  HE5Grid g = grid_list.at(i);
130  cout << "Grid Name=" << g.name << endl;
131 
132  cout << "Grid point_lower=" << g.point_lower << endl;
133  cout << "Grid point_upper=" << g.point_upper << endl;
134  cout << "Grid point_left=" << g.point_left << endl;
135  cout << "Grid point_right=" << g.point_right << endl;
136  cout << "Grid Sphere code =" <<g.sphere <<endl;
137 
138  cout << "Grid Dim Size=" << g.dim_list.size() << endl;
139  unsigned int j = 0;
140  for(j=0; j < g.dim_list.size(); j++) {
141  HE5Dim d = g.dim_list.at(j);
142  cout << "Grid Dim Name=" << d.name;
143  cout << " Size=" << d.size << endl;
144  }
145 
146  cout << "Grid Var Size=" << g.data_var_list.size()
147  << endl;
148  for(j=0; j < g.data_var_list.size(); j++) {
149  HE5Var v = g.data_var_list.at(j);
150  cout << "Grid Var Name=" << v.name << endl;
151  cout << "Grid Var Dim Size=" << v.dim_list.size() << endl;
152  unsigned int k = 0;
153  for(k=0; k < v.dim_list.size(); k++) {
154  HE5Dim d = v.dim_list.at(k);
155  cout << "Grid Var Dim Name=" << d.name << endl;
156  }
157 #if 0
158  for(k=0; k < v.max_dim_list.size(); k++) {
159  HE5Dim d = v.max_dim_list.at(k);
160  cout << "Grid Var Max Dim Name=" << d.name << endl;
161  }
162 #endif
163  }
164  cout << "Grid pixelregistration=" <<
165  g.pixelregistration
166  << endl;
167  cout << "Grid origin=" <<
168  g.gridorigin
169  << endl;
170  cout << "Grid projection=" <<
171  g.projection
172  << endl;
173 
174  cout <<"Grid zone= "<< g.zone<<endl;
175  cout <<"Grid sphere= "<<g.sphere<<endl;
176 
177  cout<<"Grid projection parameters are "<<endl;
178  for(j= 0;j<13;j++)
179  cout<<g.param[j]<<endl;
180  }
181 
182 }
183 
184 void HE5Parser::add_projparams(const string & st_str) {
185 
186  string projparms = "ProjParams=(";
187  char parms_end_marker = ')';
188  size_t parms_spos = st_str.find(projparms);
189  int grid_index = 0;
190  while(parms_spos!=string::npos) {
191  size_t parms_epos = st_str.find(parms_end_marker,parms_spos);
192  if(parms_epos == string::npos)
193  throw libdap::InternalErr(__FILE__,__LINE__,"HDF-EOS5 Grid ProjParms syntax error: ProjParams doesn't end with ')'. ");
194  string projparms_raw_values = st_str.substr(parms_spos+projparms.size(),parms_epos-parms_spos-projparms.size());
195  vector<string> projparms_values;
196  HDF5CFUtil::Split(projparms_raw_values.c_str(),',',projparms_values);
197 
198  for(unsigned int i = 0; i<projparms_values.size();i++) {
199  grid_list[grid_index].param[i] = strtod(projparms_values[i].c_str(),NULL);
200  }
201 #if 0
202 for(vector<string>::iterator istr=projparms_values.begin();istr!=projparms_values.end();++istr)
203 cerr<<"projparms value is "<<*istr<<endl;
204 #endif
205  parms_spos = st_str.find(projparms,parms_epos);
206  grid_index++;
207  }
208 
209 }
HE5Parser::print
void print()
Print the information about the members of the Vector list.
Definition: HE5Parser.cc:45
HDF5CFUtil.h
This file includes several helper functions for translating HDF5 to CF-compliant.
HE5Parser.h
A class for parsing NASA HDF-EOS5 StructMetadata.
HE5Var
Definition: HE5Var.h:8
HE5Za
Definition: HE5Za.h:6
HE5Dim
Definition: HE5Dim.h:7
HE5Grid::point_right
double point_right
The rightmost coordinate value of a Grid.
Definition: HE5Grid.h:25
HE5Swath
Definition: HE5Swath.h:6
HDF5CFUtil::Split
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
Definition: HDF5CFUtil.cc:329
HE5Grid::point_lower
double point_lower
The bottom coordinate value of a Grid.
Definition: HE5Grid.h:19
HE5Grid::point_upper
double point_upper
The top coordinate value of a Grid.
Definition: HE5Grid.h:21
HE5Grid
Definition: HE5Grid.h:12
HE5Grid::point_left
double point_left
The leftmost coordinate value of a Grid.
Definition: HE5Grid.h:23