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