bes Updated for version 3.20.10
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[0], &step[0], &count[0]);
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 //double step_v = (evalue - svalue)/((tnumelm-1)*1000);
42 // Use meter instead of km. KY 2016-04-22
43 //double step_v = (evalue - svalue)/(tnumelm*1000);
44 double step_v = (evalue - svalue)/tnumelm;
45// double newsvalue = svalue/1000;
46//
47 // Use meter instead of km. KY 2016-04-22
48 //val[0] = svalue/1000;
49 val[0] = svalue;
50 for(int i = 1;i<tnumelm; i++)
51 val[i] = val[i-1] + step_v;
52
53 if (nelms == tnumelm) {
54 set_value((dods_float64 *) &val[0], nelms);
55 }
56 else {
57 vector<double>val_subset;
58 val_subset.resize(nelms);
59 for (int i = 0; i < count[0]; i++)
60 val_subset[i] = val[offset[0] + step[0] * i];
61 set_value((dods_float64 *) &val_subset[0], nelms);
62 }
63
64 return false;
65}
66
67// Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
68// Return the number of elements to read.
69int
70HDFEOS2GeoCF1D::format_constraint (int *offset, int *step, int *count)
71{
72
73 long nels = 1;
74 int id = 0;
75
76 Dim_iter p = dim_begin ();
77 while (p != dim_end ()) {
78
79 int start = dimension_start (p, true);
80 int stride = dimension_stride (p, true);
81 int stop = dimension_stop (p, true);
82
83 // Check for illegal constraint
84 if (start > stop) {
85 ostringstream oss;
86 oss << "Array/Grid hyperslab start point "<< start <<
87 " is greater than stop point " << stop <<".";
88 throw Error(malformed_expr, oss.str());
89 }
90
91 offset[id] = start;
92 step[id] = stride;
93 count[id] = ((stop - start) / stride) + 1; // count of elements
94 nels *= count[id]; // total number of values for variable
95
96 BESDEBUG ("h4",
97 "=format_constraint():"
98 << "id=" << id << " offset=" << offset[id]
99 << " step=" << step[id]
100 << " count=" << count[id]
101 << endl);
102
103 id++;
104 p++;
105 }// while (p != dim_end ())
106
107 return nels;
108}
109
110
111#endif