bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDF5CFProj1D.cc
1
2// This file is part of the hdf5 data handler for the OPeNDAP data server.
3// This is to support the HDF-EOS5 grid for the default option.
4// The grid mapping variable is declared here.
6
7#include "HDF5CFProj1D.h"
8#include <iostream>
9#include <sstream>
10#include <libdap/debug.h>
11
12#include <libdap/InternalErr.h>
13#include <BESDebug.h>
14using namespace std;
15using namespace libdap;
16
17bool HDF5CFProj1D::read()
18{
19
20 // Declaration of offset,count and step
21 vector<int64_t> offset;
22 offset.resize(1);
23 vector<int64_t> count;
24 count.resize(1);
25 vector<int64_t> step;
26 step.resize(1);
27
28 // Obtain offset,step and count from the client expression constraint
29 int64_t nelms = -1;
30 nelms = format_constraint(offset.data(), step.data(), count.data());
31
32 vector<double> val;
33 val.resize(tnumelm);
34
35 //Based on the HFRHANDLER-303, the number of element represents cells according
36 //to the data scientist at LP DAAC.
37 // Use meter instead of km. KY 2016-04-22
38#if 0
39 //double step_v = (evalue - svalue)/((tnumelm-1)*1000);
40 // double newsvalue = svalue/1000;
41 //val[0] = svalue/1000;
42 //double step_v = (evalue - svalue)/(tnumelm*1000);
43#endif
44
45 double step_v = (evalue - svalue)/tnumelm;
46 val[0] = svalue;
47 for(int64_t i = 1;i<tnumelm; i++)
48 val[i] = val[i-1] + step_v;
49
50 if (nelms == tnumelm)
51 set_value_ll((dods_float64 *) val.data(), nelms);
52 else {
53 vector<double>val_subset;
54 val_subset.resize(nelms);
55 for (int64_t i = 0; i < count[0]; i++)
56 val_subset[i] = val[offset[0] + step[0] * i];
57 set_value_ll((dods_float64 *) val_subset.data(), nelms);
58 }
59
60 return false;
61}
62
63int64_t
64HDF5CFProj1D::format_constraint (int64_t *offset, int64_t *step, int64_t *count)
65{
66 int64_t nels = 1;
67 int id = 0;
68
69 Dim_iter p = dim_begin ();
70
71 while (p != dim_end ()) {
72
73 int64_t start = dimension_start_ll (p, true);
74 int64_t stride = dimension_stride_ll (p, true);
75 int64_t stop = dimension_stop_ll (p, true);
76
77 // Check for illegal constraint
78 if (start > stop) {
79 ostringstream oss;
80 oss << "Array/Grid hyperslab start point "<< start <<
81 " is greater than stop point " << stop <<".";
82 throw Error(malformed_expr, oss.str());
83 }
84
85 offset[id] = start;
86 step[id] = stride;
87 count[id] = ((stop - start) / stride) + 1; // count of elements
88 nels *= count[id]; // total number of values for variable
89
90 BESDEBUG ("h5",
91 "=format_constraint():"
92 << "id=" << id << " offset=" << offset[id]
93 << " step=" << step[id]
94 << " count=" << count[id]
95 << endl);
96
97 id++;
98 p++;
99 }// "while (p != dim_end ())"
100
101 return nels;
102}
103
104