bes Updated for version 3.20.13
HE5Checker.cc
Go to the documentation of this file.
1
2// 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
41using namespace std;
42
43
44bool
45HE5Checker::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
58bool
59HE5Checker::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
75void
76HE5Checker::set_grids_missing_pixreg_orig(HE5Parser* p)
77{
78 BESDEBUG("h5", "HE5Checker::set_missing_values(Grid Size="
79 << p->grid_list.size() << ")" << endl);
80 for(unsigned int i=0; i < p->grid_list.size(); i++) {
81#if 0
82// Unnecessary
83 unsigned int j = 0;
84 for(j=0; j < g.dim_list.size(); j++) {
85 HE5Dim d = g.dim_list.at(j);
86 cout << "Grid Dim Name=" << d.name;
87 cout << " Size=" << d.size << endl;
88 }
89 for(j=0; j < g.data_var_list.size(); j++) {
90 HE5Var v = g.data_var_list.at(j);
91 unsigned int k = 0;
92 for(k=0; k < v.dim_list.size(); k++) {
93 HE5Dim d = v.dim_list.at(k);
94 cout << "Grid Var Dim Name=" << d.name << endl;
95 }
96 }
97 if(g.projection == -1){
98 flag = true;
99 "h5", "Grid projection is not set or the projection code is wrong. Name=" << g.name
100 << endl;
101 }
102#endif
103
104 if (HE5_HDFE_MISSING == (p->grid_list)[i].pixelregistration)
105 (p->grid_list)[i].pixelregistration = HE5_HDFE_CENTER;
106
107 if (HE5_HDFE_GD_MISSING == (p->grid_list)[i].gridorigin)
108 (p->grid_list)[i].gridorigin = HE5_HDFE_GD_UL;
109
110 }
111}
112
113bool
114HE5Checker::check_grids_multi_latlon_coord_vars(HE5Parser* p)
115{
116
117 // No need to check for the file that only has one grid or no grid.
118 if (1 == p->grid_list.size() ||
119 p->grid_list.empty() ) return false;
120
121 unsigned int i = 0;
122 // Store name size pair.
123 typedef map<string, int> Dimmap;
124 Dimmap dim_map;
125 bool flag = false;
126
127 // Pick up the same dimension name with different sizes
128 // This is not unusual since typically for grid since XDim and YDim are default for any EOS5 grid.
129 for(i=0; i < p->grid_list.size(); i++) {
130 HE5Grid g = p->grid_list.at(i);
131 for(unsigned int j=0; j < g.dim_list.size(); j++) {
132 HE5Dim d = g.dim_list.at(j);
133 Dimmap::iterator iter = dim_map.find(d.name);
134 if(iter != dim_map.end()){
135 if(d.size != iter->second){
136 flag = true;
137 break;
138 }
139 }
140 else{
141 dim_map[d.name] = d.size;
142 }
143 }
144 if (true == flag) break;
145
146 }
147
148 // Even if the {name,size} is the same for different grids,
149 // we still need to check their projection parameters to
150 // make sure they are matched.
151 if (false == flag) {
152
153 HE5Grid g = p->grid_list.at(0);
154 EOS5GridPCType projcode = g.projection;
155 EOS5GridPRType pixelreg = g.pixelregistration;
156 EOS5GridOriginType pixelorig = g.gridorigin;
157
158 float lowercoor = g.point_lower;
159 float uppercoor = g.point_upper;
160 float leftcoor =g.point_left;
161 float rightcoor= g.point_right;
162
163 for(i=1; i < p->grid_list.size(); i++) {
164 g = p->grid_list.at(i);
165 if (projcode != g.projection ||
166 pixelreg != g.pixelregistration ||
167 pixelorig!= g.gridorigin ||
168 fabs(lowercoor-g.point_lower) >0.001 ||
169 fabs(uppercoor-g.point_upper) >0.001 ||
170 fabs(leftcoor-g.point_left) >0.001 ||
171 fabs(rightcoor-g.point_right) >0.001 ){
172 flag = true;
173 break;
174 }
175 }
176 }
177
178 return flag;
179}
180
181bool HE5Checker::check_grids_support_projcode(HE5Parser*p) {
182
183 bool flag = false;
184 for (unsigned int i = 0; i <p->grid_list.size(); i++) {
185 HE5Grid g = p->grid_list.at(i);
186 if (g.projection != HE5_GCTP_GEO && g.projection != HE5_GCTP_SNSOID
187 && g.projection != HE5_GCTP_LAMAZ && g.projection != HE5_GCTP_PS) {
188 flag = true;
189 break;
190 }
191 }
192 return flag;
193
194
195}
196
A class for parsing NASA HDF-EOS5 StructMetadata.
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