bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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// Kent Yang <myang6@hdfgroup.org>
6//
7// Copyright (c) 2007-2023 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 410 E University Ave,
27// Suite 200, 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(const HE5Parser* p) const
46{
47 bool flag = false;
48 for (const auto &g:p->grid_list) {
49 if (HE5_GCTP_MISSING == g.projection) {
50 flag = true;
51 break;
52 }
53 }
54 return flag;
55}
56
57bool
58HE5Checker::check_grids_unknown_parameters(const HE5Parser* p) const
59{
60 bool flag = false;
61 for (const auto &g:p->grid_list) {
62 if (HE5_GCTP_UNKNOWN == g.projection ||
63 HE5_HDFE_UNKNOWN == g.pixelregistration ||
64 HE5_HDFE_GD_UNKNOWN == g.gridorigin) {
65 flag = true;
66 break;
67 }
68 }
69 return flag;
70}
71
72void
73HE5Checker::set_grids_missing_pixreg_orig(HE5Parser* p) const
74{
75 BESDEBUG("h5", "HE5Checker::set_missing_values(Grid Size="
76 << p->grid_list.size() << ")" << endl);
77 for(auto &g: p->grid_list) {
78#if 0
79// Unnecessary
80 unsigned int j = 0;
81 for(j=0; j < g.dim_list.size(); j++) {
82 HE5Dim d = g.dim_list.at(j);
83 cout << "Grid Dim Name=" << d.name;
84 cout << " Size=" << d.size << endl;
85 }
86 for(j=0; j < g.data_var_list.size(); j++) {
87 HE5Var v = g.data_var_list.at(j);
88 unsigned int k = 0;
89 for(k=0; k < v.dim_list.size(); k++) {
90 HE5Dim d = v.dim_list.at(k);
91 cout << "Grid Var Dim Name=" << d.name << endl;
92 }
93 }
94 if(g.projection == -1){
95 flag = true;
96 "h5", "Grid projection is not set or the projection code is wrong. Name=" << g.name
97 << endl;
98 }
99#endif
100
101 if (HE5_HDFE_MISSING == g.pixelregistration)
102 g.pixelregistration = HE5_HDFE_CENTER;
103
104 if (HE5_HDFE_GD_MISSING == g.gridorigin)
105 g.gridorigin = HE5_HDFE_GD_UL;
106
107 }
108}
109
110bool
111HE5Checker::check_grids_multi_latlon_coord_vars(HE5Parser* p) const
112{
113
114 // No need to check for the file that only has one grid or no grid.
115 if (1 == p->grid_list.size() ||
116 p->grid_list.empty() ) return false;
117
118 // Store name size pair.
119 typedef map<string, int> Dimmap;
120 Dimmap dim_map;
121 bool flag = false;
122
123 // Pick up the same dimension name with different sizes
124 // This is not unusual since typically for grid since XDim and YDim are default for any EOS5 grid.
125 for (const auto &g:p->grid_list) {
126 for (const auto &d:g.dim_list) {
127 Dimmap::iterator iter = dim_map.find(d.name);
128 if(iter != dim_map.end()){
129 if(d.size != iter->second){
130 flag = true;
131 break;
132 }
133 }
134 else{
135 dim_map[d.name] = d.size;
136 }
137 }
138 if (true == flag) break;
139
140 }
141
142 // Even if the {name,size} is the same for different grids,
143 // we still need to check their projection parameters to
144 // make sure they are matched.
145 if (false == flag) {
146
147 HE5Grid g = p->grid_list.at(0);
148 EOS5GridPCType projcode = g.projection;
149 EOS5GridPRType pixelreg = g.pixelregistration;
150 EOS5GridOriginType pixelorig = g.gridorigin;
151
152 auto lowercoor = (float)(g.point_lower);
153 auto uppercoor = (float)(g.point_upper);
154 auto leftcoor = (float)(g.point_left);
155 auto rightcoor= (float)(g.point_right);
156
157 for(unsigned int i=1; i < p->grid_list.size(); i++) {
158 g = p->grid_list.at(i);
159 if (projcode != g.projection ||
160 pixelreg != g.pixelregistration ||
161 pixelorig!= g.gridorigin ||
162 fabs(lowercoor-g.point_lower) >0.001 ||
163 fabs(uppercoor-g.point_upper) >0.001 ||
164 fabs(leftcoor-g.point_left) >0.001 ||
165 fabs(rightcoor-g.point_right) >0.001 ){
166 flag = true;
167 break;
168 }
169 }
170 }
171
172 return flag;
173}
174
175bool HE5Checker::check_grids_support_projcode(const HE5Parser*p) const{
176
177 bool flag = false;
178 for (const auto &g:p->grid_list) {
179 if (g.projection != HE5_GCTP_GEO && g.projection != HE5_GCTP_SNSOID
180 && g.projection != HE5_GCTP_LAMAZ && g.projection != HE5_GCTP_PS) {
181 flag = true;
182 break;
183 }
184 }
185 return flag;
186
187}
188
A class for parsing NASA HDF-EOS5 StructMetadata.
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