bes  Updated for version 3.20.6
HE5Checker.cc
Go to the documentation of this file.
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 // MuQun Yang <myang6@hdfgroup.org>
6 //
7 // Copyright (c) 2007-2016 The HDF Group, Inc. and OPeNDAP, Inc.
10 //
11 // This is free software; you can redistribute it and/or modify it under the
12 // terms of the GNU Lesser General Public License as published by the Free
13 // Software Foundation; either version 2.1 of the License, or (at your
14 // option) any later version.
15 //
16 // This software is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 // License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
27 // Suite 203, Champaign, IL 61820
36 #include <map>
37 #include <math.h>
38 #include <BESDebug.h>
39 #include "HE5Checker.h"
40 
41 using namespace std;
42 
43 
44 bool
45 HE5Checker::check_grids_missing_projcode(HE5Parser* p)
46 {
47  bool flag = false;
48  for (unsigned int i = 0; i <p->grid_list.size(); i++) {
49  HE5Grid g = p->grid_list.at(i);
50  if (HE5_GCTP_MISSING == g.projection) {
51  flag = true;
52  break;
53  }
54  }
55  return flag;
56 }
57 
58 bool
59 HE5Checker::check_grids_unknown_parameters(HE5Parser* p)
60 {
61  HE5Grid g;
62  bool flag = false;
63  for (unsigned int i = 0; i <p->grid_list.size(); i++) {
64  g = p->grid_list.at(i);
65  if (HE5_GCTP_UNKNOWN == g.projection ||
66  HE5_HDFE_UNKNOWN == g.pixelregistration ||
67  HE5_HDFE_GD_UNKNOWN == g.gridorigin) {
68  flag = true;
69  break;
70  }
71  }
72  return flag;
73 }
74 
75 void
76 HE5Checker::set_grids_missing_pixreg_orig(HE5Parser* p)
77 {
78  unsigned int i = 0;
79  BESDEBUG("h5", "HE5Checker::set_missing_values(Grid Size="
80  << p->grid_list.size() << ")" << endl);
81  for(i=0; i < p->grid_list.size(); i++) {
82 #if 0
83 // Unnecessary
84  unsigned int j = 0;
85  for(j=0; j < g.dim_list.size(); j++) {
86  HE5Dim d = g.dim_list.at(j);
87  cout << "Grid Dim Name=" << d.name;
88  cout << " Size=" << d.size << endl;
89  }
90  for(j=0; j < g.data_var_list.size(); j++) {
91  HE5Var v = g.data_var_list.at(j);
92  unsigned int k = 0;
93  for(k=0; k < v.dim_list.size(); k++) {
94  HE5Dim d = v.dim_list.at(k);
95  cout << "Grid Var Dim Name=" << d.name << endl;
96  }
97  }
98  if(g.projection == -1){
99  flag = true;
100  "h5", "Grid projection is not set or the projection code is wrong. Name=" << g.name
101  << endl;
102  }
103 #endif
104 
105  if (HE5_HDFE_MISSING == (p->grid_list)[i].pixelregistration)
106  (p->grid_list)[i].pixelregistration = HE5_HDFE_CENTER;
107 
108  if (HE5_HDFE_GD_MISSING == (p->grid_list)[i].gridorigin)
109  (p->grid_list)[i].gridorigin = HE5_HDFE_GD_UL;
110 
111  }
112 }
113 
114 bool
115 HE5Checker::check_grids_multi_latlon_coord_vars(HE5Parser* p)
116 {
117 
118  // No need to check for the file that only has one grid or no grid.
119  if (1 == p->grid_list.size() ||
120  0 == p->grid_list.size() ) return false;
121 
122  unsigned int i = 0;
123  // Store name size pair.
124  typedef map<string, int> Dimmap;
125  Dimmap dim_map;
126  bool flag = false;
127 
128  // Pick up the same dimension name with different sizes
129  // This is not unusual since typically for grid since XDim and YDim are default for any EOS5 grid.
130  for(i=0; i < p->grid_list.size(); i++) {
131  HE5Grid g = p->grid_list.at(i);
132  unsigned int j = 0;
133  for(j=0; j < g.dim_list.size(); j++) {
134  HE5Dim d = g.dim_list.at(j);
135  Dimmap::iterator iter = dim_map.find(d.name);
136  if(iter != dim_map.end()){
137  if(d.size != iter->second){
138  flag = true;
139  break;
140  }
141  }
142  else{
143  dim_map[d.name] = d.size;
144  }
145  }
146  if (true == flag) break;
147 
148  }
149 
150  // Even if the {name,size} is the same for different grids,
151  // we still need to check their projection parameters to
152  // make sure they are matched.
153  if (false == flag) {
154 
155  HE5Grid g = p->grid_list.at(0);
156  EOS5GridPCType projcode = g.projection;
157  EOS5GridPRType pixelreg = g.pixelregistration;
158  EOS5GridOriginType pixelorig = g.gridorigin;
159 
160  float lowercoor = g.point_lower;
161  float uppercoor = g.point_upper;
162  float leftcoor =g.point_left;
163  float rightcoor= g.point_right;
164 
165  for(i=1; i < p->grid_list.size(); i++) {
166  g = p->grid_list.at(i);
167  if (projcode != g.projection ||
168  pixelreg != g.pixelregistration ||
169  pixelorig!= g.gridorigin ||
170  fabs(lowercoor-g.point_lower) >0.001 ||
171  fabs(uppercoor-g.point_upper) >0.001 ||
172  fabs(leftcoor-g.point_left) >0.001 ||
173  fabs(rightcoor-g.point_right) >0.001 ){
174  flag = true;
175  break;
176  }
177  }
178  }
179 
180  return flag;
181 }
182 
183 bool HE5Checker::check_grids_support_projcode(HE5Parser*p) {
184 
185  bool flag = false;
186  for (unsigned int i = 0; i <p->grid_list.size(); i++) {
187  HE5Grid g = p->grid_list.at(i);
188  if (g.projection != HE5_GCTP_GEO && g.projection != HE5_GCTP_SNSOID
189  && g.projection != HE5_GCTP_LAMAZ && g.projection != HE5_GCTP_PS) {
190  flag = true;
191  break;
192  }
193  }
194  return flag;
195 
196 
197 }
198 
HE5Checker.h
A class for parsing NASA HDF-EOS5 StructMetadata.
HE5Var
Definition: HE5Var.h:8
HE5Dim
Definition: HE5Dim.h:7
HE5Grid::point_right
double point_right
The rightmost coordinate value of a Grid.
Definition: HE5Grid.h:25
HE5Parser
Definition: HE5Parser.h:49
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