OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFEOS5CFMissLLArray.cc
Go to the documentation of this file.
1 // This file is part of the hdf5_handler implementing for the CF-compliant
2 // Copyright (c) 2011-2013 The HDF Group, Inc. and OPeNDAP, Inc.
3 //
4 // This is free software; you can redistribute it and/or modify it under the
5 // terms of the GNU Lesser General Public License as published by the Free
6 // Software Foundation; either version 2.1 of the License, or (at your
7 // option) any later version.
8 //
9 // This software is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 // License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
19 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
20 // Suite 203, Champaign, IL 61820
21 
31 
32 #include "config_hdf5.h"
33 #include <iostream>
34 #include <sstream>
35 #include <cassert>
36 #include <debug.h>
37 #include "InternalErr.h"
38 #include <BESDebug.h>
39 #include <Array.h>
40 
41 #include "HDFEOS5CFMissLLArray.h"
42 
43 
44 
46 {
47  return new HDFEOS5CFMissLLArray(*this);
48 }
49 
51 {
52 
53  BESDEBUG("h5","Coming to HDFEOS5CFMissLLArray read "<<endl);
54  int nelms = -1;
55  vector<int>offset;
56  vector<int>count;
57  vector<int>step;
58 
59  if (eos5_projcode != HE5_GCTP_GEO)
60  throw InternalErr (__FILE__, __LINE__,"The projection is not supported.");
61 
62 
63  if (rank <= 0)
64  throw InternalErr (__FILE__, __LINE__,
65  "The number of dimension of this variable should be greater than 0");
66  else {
67 
68  offset.resize(rank);
69  count.resize(rank);
70  step.resize(rank);
71  nelms = format_constraint (&offset[0], &step[0], &count[0]);
72  }
73 
74  if (nelms <= 0)
75  throw InternalErr (__FILE__, __LINE__,
76  "The number of elments is negative.");
77 
78 
79  float start = 0.0;
80  float end = 0.0;
81 
82  vector<float>val;
83  val.resize(nelms);
84 
85 
86  if (CV_LAT_MISS == cvartype) {
87 
88  if (HE5_HDFE_GD_UL == eos5_origin || HE5_HDFE_GD_UR == eos5_origin) {
89 
90  start = point_upper;
91  end = point_lower;
92 
93  }
94  else {// (gridorigin == HE5_HDFE_GD_LL || gridorigin == HE5_HDFE_GD_LR)
95 
96  start = point_lower;
97  end = point_upper;
98  }
99 
100  if(ydimsize <=0)
101  throw InternalErr (__FILE__, __LINE__,
102  "The number of elments should be greater than 0.");
103 
104  float lat_step = (end - start) /ydimsize;
105 
106  // Now offset,step and val will always be valid. line 74 and 85 assure this.
107  if ( HE5_HDFE_CENTER == eos5_pixelreg ) {
108  for (int i = 0; i < nelms; i++)
109  val[i] = ((float)(offset[0]+i*step[0] + 0.5f) * lat_step + start) / 1000000.0;
110  }
111  else { // HE5_HDFE_CORNER
112  for (int i = 0; i < nelms; i++)
113  val[i] = ((float)(offset[0]+i * step[0])*lat_step + start) / 1000000.0;
114  }
115 
116  }
117 
118  if (CV_LON_MISS == cvartype) {
119 
120  if (HE5_HDFE_GD_UL == eos5_origin || HE5_HDFE_GD_LL == eos5_origin) {
121 
122  start = point_left;
123  end = point_right;
124 
125  }
126  else {// (gridorigin == HE5_HDFE_GD_UR || gridorigin == HE5_HDFE_GD_LR)
127 
128  start = point_right;
129  end = point_left;
130  }
131 
132  if(xdimsize <=0)
133  throw InternalErr (__FILE__, __LINE__,
134  "The number of elments should be greater than 0.");
135  float lon_step = (end - start) /xdimsize;
136 
137  if (HE5_HDFE_CENTER == eos5_pixelreg) {
138  for (int i = 0; i < nelms; i++)
139  val[i] = ((float)(offset[0] + i *step[0] + 0.5f) * lon_step + start ) / 1000000.0;
140  }
141  else { // HE5_HDFE_CORNER
142  for (int i = 0; i < nelms; i++)
143  val[i] = ((float)(offset[0]+i*step[0]) * lon_step + start) / 1000000.0;
144  }
145 
146  }
147 
148 #if 0
149 for (int i =0; i <nelms; i++)
150 cerr <<"final data val "<< i <<" is " << val[i] <<endl;
151 #endif
152 
153  set_value ((dods_float32 *) &val[0], nelms);
154  return true;
155 }
156 
157 // parse constraint expr. and make hdf5 coordinate point location.
158 // return number of elements to read.
159 int
160 HDFEOS5CFMissLLArray::format_constraint (int *offset, int *step, int *count)
161 {
162  long nels = 1;
163  int id = 0;
164 
165  Dim_iter p = dim_begin ();
166 
167  while (p != dim_end ()) {
168 
169  int start = dimension_start (p, true);
170  int stride = dimension_stride (p, true);
171  int stop = dimension_stop (p, true);
172 
173 
174  // Check for illegical constraint
175  if (stride < 0 || start < 0 || stop < 0 || start > stop) {
176  ostringstream oss;
177 
178  oss << "Array/Grid hyperslab indices are bad: [" << start <<
179  ":" << stride << ":" << stop << "]";
180  throw Error (malformed_expr, oss.str ());
181  }
182 
183  // Check for an empty constraint and use the whole dimension if so.
184  if (start == 0 && stop == 0 && stride == 0) {
185  start = dimension_start (p, false);
186  stride = dimension_stride (p, false);
187  stop = dimension_stop (p, false);
188  }
189 
190  offset[id] = start;
191  step[id] = stride;
192  count[id] = ((stop - start) / stride) + 1; // count of elements
193  nels *= count[id]; // total number of values for variable
194 
195  BESDEBUG ("h5",
196  "=format_constraint():"
197  << "id=" << id << " offset=" << offset[id]
198  << " step=" << step[id]
199  << " count=" << count[id]
200  << endl);
201 
202  id++;
203  p++;
204  }
205 
206  return nels;
207 }
208 
209 
int format_constraint(int *cor, int *step, int *edg)
This class specifies the retrieval of the missing lat/lon values for HDF-EOS5 products.
HDFEOS5CFMissLLArray(int rank, const string &filename, const hid_t fileid, const string &varfullpath, CVType cvartype, float point_lower, float point_upper, float point_left, float point_right, EOS5GridPRType eos5_pixelreg, EOS5GridOriginType eos5_origin, EOS5GridPCType eos5_projcode, int xdimsize, int ydimsize, const string &n="", BaseType *v=0)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
virtual BaseType * ptr_duplicate()