bes  Updated for version 3.20.6
HDFSPArrayMissField.cc
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 using namespace std;
27 using namespace libdap;
28 
29 bool
30 HDFSPArrayMissGeoField::read ()
31 {
32 
33  BESDEBUG("h4","Coming to HDFSPArrayMissGeoField read "<<endl);
34 
35  if(length() == 0)
36  return true;
37  // Declaration of offset,count and step
38  vector<int>offset;
39  offset.resize(rank);
40  vector<int>count;
41  count.resize(rank);
42  vector<int>step;
43  step.resize(rank);
44 
45  // Obtain offset,step and count from the client expression constraint
46  int nelms = format_constraint(&offset[0],&step[0],&count[0]);
47 
48  vector<int>val;
49  val.resize(nelms);
50 
51  // Since we always assign the the missing Z dimension as 32-bit
52  // integer, so no need to check the type. The missing Z-dim is always
53  // 1-D with natural number 1,2,3,....
54  if (nelms == tnumelm) {
55  for (int i = 0; i < nelms; i++)
56  val[i] = i;
57  set_value ((dods_int32 *) &val[0], nelms);
58  }
59  else {
60  if (rank != 1) {
61  throw InternalErr (__FILE__, __LINE__,
62  "Currently the rank of the missing field should be 1");
63  }
64  for (int i = 0; i < count[0]; i++)
65  val[i] = offset[0] + step[0] * i;
66  set_value ((dods_int32 *) &val[0], nelms);
67  }
68 
69  return true;
70 }
71 
72 // Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
73 // Return the number of elements to read.
74 int
75 HDFSPArrayMissGeoField::format_constraint (int *offset, int *step, int *count)
76 {
77 
78  long nels = 1;
79  int id = 0;
80 
81  Dim_iter p = dim_begin ();
82  while (p != dim_end ()) {
83 
84  int start = dimension_start (p, true);
85  int stride = dimension_stride (p, true);
86  int stop = dimension_stop (p, true);
87 
88  // Check for illegal constraint
89  if (start > stop) {
90  ostringstream oss;
91  oss << "Array/Grid hyperslab start point "<< start <<
92  " is greater than stop point " << stop <<".";
93  throw Error(malformed_expr, oss.str());
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  }// while (p != dim_end ())
111 
112  return nels;
113 }
114 
115 
libdap
Definition: BESDapFunctionResponseCache.h:35
Error