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