bes Updated for version 3.20.13
HDFEOS2GeoCF1D.cc
1
2// This file is part of the hdf4 data handler for the OPeNDAP data server.
3// Authors: MuQun Yang <myang6@hdfgroup.org>
4// Copyright (c) 2009 The HDF Group
6#ifdef USE_HDFEOS2_LIB
7
8#include "HDFEOS2GeoCF1D.h"
9#include <iostream>
10#include <sstream>
11#include <cassert>
12#include <libdap/debug.h>
13
14#include <libdap/InternalErr.h>
15#include <BESDebug.h>
16
17using namespace libdap;
18
19bool HDFEOS2GeoCF1D::read()
20{
21 if(length() == 0)
22 return true;
23
24 // Declaration of offset,count and step
25 vector<int> offset;
26 offset.resize(1);
27 vector<int> count;
28 count.resize(1);
29 vector<int> step;
30 step.resize(1);
31
32 // Obtain offset,step and count from the client expression constraint
33 int nelms = -1;
34 nelms = format_constraint(offset.data(), step.data(), count.data());
35
36 vector<double> val;
37 val.resize(tnumelm);
38
39 //HFRHANDLER-303, the number of element represents cells according
40 //to the data scientist at LP DAAC.
41
42#if 0
43 //double step_v = (evalue - svalue)/((tnumelm-1)*1000);
44 // Use meter instead of km. KY 2016-04-22
45 //double step_v = (evalue - svalue)/(tnumelm*1000);
46#endif
47
48 double step_v = (evalue - svalue)/tnumelm;
49
50#if 0
51// double newsvalue = svalue/1000;
52//
53 // Use meter instead of km. KY 2016-04-22
54 //val[0] = svalue/1000;
55#endif
56
57 val[0] = svalue;
58 for(int i = 1;i<tnumelm; i++)
59 val[i] = val[i-1] + step_v;
60
61 if (nelms == tnumelm) {
62 set_value((dods_float64 *) val.data(), nelms);
63 }
64 else {
65 vector<double>val_subset;
66 val_subset.resize(nelms);
67 for (int i = 0; i < count[0]; i++)
68 val_subset[i] = val[offset[0] + step[0] * i];
69 set_value((dods_float64 *) val_subset.data(), nelms);
70 }
71
72 return false;
73}
74
75// Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
76// Return the number of elements to read.
77int
78HDFEOS2GeoCF1D::format_constraint (int *offset, int *step, int *count)
79{
80
81 int nels = 1;
82 int id = 0;
83
84 Dim_iter p = dim_begin ();
85 while (p != dim_end ()) {
86
87 int start = dimension_start (p, true);
88 int stride = dimension_stride (p, true);
89 int stop = dimension_stop (p, true);
90
91 // Check for illegal constraint
92 if (start > stop) {
93 ostringstream oss;
94 oss << "Array/Grid hyperslab start point "<< start <<
95 " is greater than stop point " << stop <<".";
96 throw Error(malformed_expr, oss.str());
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 }// while (p != dim_end ())
114
115 return nels;
116}
117
118
119#endif