OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFEOS2ArrayMissField.cc
Go to the documentation of this file.
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
3 // It retrieves the missing "third-dimension" values of the HDF-EOS2 Grid.
4 // Some third-dimension coordinate variable values are not provided.
5 // What we do here is to provide natural number series(1,2,3, ...) for
6 // these missing values. It doesn't make sense to visualize or analyze
7 // with vertical cross-section. One can check the data level by level.
8 // Authors: MuQun Yang <myang6@hdfgroup.org>
9 // Copyright (c) 2009 The HDF Group
11 #ifdef USE_HDFEOS2_LIB
12 
13 #include "HDFEOS2ArrayMissField.h"
14 #include <iostream>
15 #include <sstream>
16 #include <cassert>
17 #include <debug.h>
18 
19 #include <InternalErr.h>
20 #include <BESDebug.h>
21 
22 #include "HDFEOS2.h"
23 
24 // Now we use the vector to replace new []. KY 2012-12-30
25 bool HDFEOS2ArrayMissGeoField::read()
26 {
27 
28  // Declaration of offset,count and step
29  vector<int> offset;
30  offset.resize(rank);
31  vector<int> count;
32  count.resize(rank);
33  vector<int> step;
34  step.resize(rank);
35 
36  // Obtain offset,step and count from the client expression constraint
37  int nelms = -1;
38  nelms = format_constraint(&offset[0], &step[0], &count[0]);
39 
40  vector<int> val;
41  val.resize(nelms);
42 
43  // Since we always assign the the missing Z dimension as 32-bit
44  // integer, so no need to check the type. The missing Z-dim is always
45  // 1-D with natural number 1,2,3,....
46  if (nelms == tnumelm) {
47  for (int i = 0; i < nelms; i++)
48  val[i] = i;
49  set_value((dods_int32 *) &val[0], nelms);
50  }
51  else {
52  if (rank != 1) {
53  throw InternalErr(__FILE__, __LINE__, "Currently the rank of the missing field should be 1");
54  }
55  for (int i = 0; i < count[0]; i++)
56  val[i] = offset[0] + step[0] * i;
57  set_value((dods_int32 *) &val[0], nelms);
58  }
59 
60  return false;
61 }
62 
63 // Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
64 // Return the number of elements to read.
65 int
66 HDFEOS2ArrayMissGeoField::format_constraint (int *offset, int *step, int *count)
67 {
68  long nels = 1;
69  int id = 0;
70 
71  Dim_iter p = dim_begin ();
72 
73  while (p != dim_end ()) {
74 
75  int start = dimension_start (p, true);
76  int stride = dimension_stride (p, true);
77  int stop = dimension_stop (p, true);
78 
79 
80  // Check for illegical constraint
81  if (stride < 0 || start < 0 || stop < 0 || start > stop) {
82  ostringstream oss;
83 
84  oss << "Array/Grid hyperslab indices are bad: [" << start <<
85  ":" << stride << ":" << stop << "]";
86  throw Error (malformed_expr, oss.str ());
87  }
88 
89  // Check for an empty constraint and use the whole dimension if so.
90  if (start == 0 && stop == 0 && stride == 0) {
91  start = dimension_start (p, false);
92  stride = dimension_stride (p, false);
93  stop = dimension_stop (p, false);
94  }
95 
96  offset[id] = start;
97  step[id] = stride;
98  count[id] = ((stop - start) / stride) + 1;// count of elements
99  nels *= count[id];// total number of values for variable
100 
101  BESDEBUG ("h4",
102  "=format_constraint():"
103  << "id=" << id << " offset=" << offset[id]
104  << " step=" << step[id]
105  << " count=" << count[id]
106  << endl);
107 
108  id++;
109  p++;
110  }
111 
112  return nels;
113 }
114 #endif
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64