bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDFEOS2ArraySwathGeoMultiDimMapField.cc
1
2// Retrieves the latitude and longitude of the HDF-EOS2 Swath without using dimension maps
3//
4// Authors: Kent Yang <myang6@hdfgroup.org>
5// Copyright (c) The HDF Group
7//For the swath using the multiple dimension maps,
8// Latitude/longitude will be interpolated accordingly.
9
10#ifdef USE_HDFEOS2_LIB
11
12#include "HDFEOS2ArraySwathGeoMultiDimMapField.h"
13#include <iostream>
14#include <sstream>
15#include <cassert>
16#include <libdap/debug.h>
17#include <libdap/InternalErr.h>
18#include "BESDebug.h"
19#include "HDF4RequestHandler.h"
20
21using namespace std;
22using namespace libdap;
23#define SIGNED_BYTE_TO_INT32 1
24
25bool
26HDFEOS2ArraySwathGeoMultiDimMapField::read ()
27{
28
29 BESDEBUG("h4","Coming to HDFEOS2ArraySwathGeoMultiDimMapField read "<<endl);
30
31 if (length() == 0)
32 return true;
33
34 if (rank !=2)
35 throw InternalErr (__FILE__, __LINE__, "The field rank must be 2 for swath multi-dimension map reading.");
36
37 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
38
39 // Declare offset, count and step
40 vector<int>offset;
41 offset.resize(rank);
42 vector<int>count;
43 count.resize(rank);
44 vector<int>step;
45 step.resize(rank);
46
47 // Obtain offset,step and count from the client expression constraint
48 int nelms = format_constraint (offset.data(), step.data(), count.data());
49
50 // Just declare offset,count and step in the int32 type.
51 vector<int32>offset32;
52 offset32.resize(rank);
53 vector<int32>count32;
54 count32.resize(rank);
55 vector<int32>step32;
56 step32.resize(rank);
57
58 // Just obtain the offset,count and step in the datatype of int32.
59 for (int i = 0; i < rank; i++) {
60 offset32[i] = (int32) offset[i];
61 count32[i] = (int32) count[i];
62 step32[i] = (int32) step[i];
63 }
64
65 int32 (*openfunc) (char *, intn);
66 int32 (*attachfunc) (int32, char *);
67 intn (*detachfunc) (int32);
68 intn (*fieldinfofunc) (int32, char *, int32 *, int32 *, int32 *, char *);
69 intn (*readfieldfunc) (int32, char *, int32 *, int32 *, int32 *, void *);
70
71 // Define function pointers to handle the swath
72 string datasetname;
73 openfunc = SWopen;
74 attachfunc = SWattach;
75 detachfunc = SWdetach;
76 fieldinfofunc = SWfieldinfo;
77 readfieldfunc = SWreadfield;
78 datasetname = swathname;
79
80 // Declare dimension map size, offset and inc
81 vector<int>dm_dimsizes;
82 dm_dimsizes.resize(rank);
83 vector<int>dm_offsets;
84 dm_offsets.resize(rank);
85 vector<int>dm_incs;
86 dm_incs.resize(rank);
87 bool no_interpolation = true;
88
89 if (dim0inc != 0 || dim1inc !=0 || dim0offset != 0 || dim1offset != 0) {
90 dm_dimsizes[0] = dim0size;
91 dm_dimsizes[1] = dim1size;
92 dm_offsets[0] = dim0offset;
93 dm_offsets[1] = dim1offset;
94 dm_incs[0] = dim0inc;
95 dm_incs[1] = dim1inc;
96 no_interpolation = false;
97 }
98
99 // We may eventually combine the following code with other code, so
100 // we don't add many comments from here to the end of the file.
101 // The jira ticket about combining code is HFRHANDLER-166.
102 int32 sfid = -1;
103 int32 swathid = -1;
104
105 if (false == check_pass_fileid_key) {
106 sfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
107 if (sfid < 0) {
108 ostringstream eherr;
109 eherr << "File " << filename.c_str () << " cannot be open.";
110 throw InternalErr (__FILE__, __LINE__, eherr.str ());
111 }
112 }
113 else
114 sfid = swathfd;
115
116 swathid = attachfunc (sfid, const_cast < char *>(datasetname.c_str ()));
117
118 if (swathid < 0) {
119 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
120 ostringstream eherr;
121 eherr << "Swath " << datasetname.c_str () << " cannot be attached.";
122 throw InternalErr (__FILE__, __LINE__, eherr.str ());
123 }
124
125
126 int32 tmp_rank = -1;
127 vector<int32>tmp_dims;
128 tmp_dims.resize(rank);
129 char tmp_dimlist[1024];
130 int32 type =-1;
131 intn r = -1;
132 r = fieldinfofunc (swathid, const_cast < char *>(fieldname.c_str ()),
133 &tmp_rank, tmp_dims.data(), &type, tmp_dimlist);
134 if (r != 0) {
135 detachfunc (swathid);
136 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
137 ostringstream eherr;
138 eherr << "Field " << fieldname.c_str () << " information cannot be obtained.";
139 throw InternalErr (__FILE__, __LINE__, eherr.str ());
140 }
141
142 vector<int32> newdims;
143 newdims.resize(tmp_rank);
144
145
146 switch (type) {
147 case DFNT_INT8:
148 {
149 if (true == no_interpolation) {
150 vector<int8>val;
151 val.resize(nelms);
152 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
153 if (r != 0) {
154 detachfunc (swathid);
155 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
156 ostringstream eherr;
157 eherr << "field " << fieldname.c_str () << "cannot be read.";
158 throw InternalErr (__FILE__, __LINE__, eherr.str ());
159 }
160#ifndef SIGNED_BYTE_TO_INT32
161 set_value ((dods_byte *) val.data(), nelms);
162#else
163 vector<int32>newval;
164 newval.resize(nelms);
165
166 for (int counter = 0; counter < nelms; counter++)
167 newval[counter] = (int32) (val[counter]);
168 set_value ((dods_int32 *) newval.data(), nelms);
169#endif
170 }
171 else {
172 // Obtaining the total value and interpolating the data
173 // according to dimension map
174 vector <int8> total_val8;
175 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val8, newdims);
176
177 if (r != 0) {
178 detachfunc (swathid);
179 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
180 ostringstream eherr;
181 eherr << "field " << fieldname.c_str () << "cannot be read.";
182 throw InternalErr (__FILE__, __LINE__, eherr.str ());
183
184 }
185 vector<int8>val8;
186 val8.resize(nelms);
187 Field2DSubset (val8.data(), newdims[0], newdims[1],total_val8.data(),
188 offset32.data(), count32.data(), step32.data());
189
190#ifndef SIGNED_BYTE_TO_INT32
191 set_value ((dods_byte *) val8.data(), nelms);
192#else
193 vector<int32>newval;
194 newval.resize(nelms);
195
196 for (int counter = 0; counter < nelms; counter++)
197 newval[counter] = (int32) (val8[counter]);
198 set_value ((dods_int32 *) newval.data(), nelms);
199#endif
200 }
201 }
202 break;
203 case DFNT_UINT8:
204 case DFNT_UCHAR8:
205 {
206 if (no_interpolation == false) {
207 vector <uint8> total_val_uint8;
208 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_uint8, newdims);
209
210 if (r != 0) {
211 detachfunc (swathid);
212 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
213 ostringstream eherr;
214 eherr << "field " << fieldname.c_str () << "cannot be read.";
215 throw InternalErr (__FILE__, __LINE__, eherr.str ());
216
217 }
218 vector<uint8>val_uint8;
219 val_uint8.resize(nelms);
220 Field2DSubset (val_uint8.data(), newdims[0], newdims[1],total_val_uint8.data(),
221 offset32.data(), count32.data(), step32.data());
222
223 set_value ((dods_byte *) val_uint8.data(), nelms);
224 }
225 else {
226
227 vector<uint8>val;
228 val.resize(nelms);
229 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
230 if (r != 0) {
231 detachfunc (swathid);
232 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
233 ostringstream eherr;
234 eherr << "field " << fieldname.c_str () << "cannot be read.";
235 throw InternalErr (__FILE__, __LINE__, eherr.str ());
236 }
237
238 set_value ((dods_byte *) val.data(), nelms);
239 }
240 }
241 break;
242
243 case DFNT_INT16:
244 {
245 if (no_interpolation == false) {
246 vector <int16> total_val_int16;
247 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_int16, newdims);
248
249 if (r != 0) {
250 detachfunc (swathid);
251 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
252 ostringstream eherr;
253 eherr << "field " << fieldname.c_str () << "cannot be read.";
254 throw InternalErr (__FILE__, __LINE__, eherr.str ());
255
256 }
257 vector<int16>val_int16;
258 val_int16.resize(nelms);
259 Field2DSubset (val_int16.data(), newdims[0], newdims[1],total_val_int16.data(),
260 offset32.data(), count32.data(), step32.data());
261
262 set_value ((dods_int16 *) val_int16.data(), nelms);
263 }
264
265 else {
266 vector<int16>val;
267 val.resize(nelms);
268 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
269 if (r != 0) {
270 detachfunc (swathid);
271 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
272 ostringstream eherr;
273 eherr << "field " << fieldname.c_str () << "cannot be read.";
274 throw InternalErr (__FILE__, __LINE__, eherr.str ());
275 }
276 set_value ((dods_int16 *) val.data(), nelms);
277 }
278 }
279 break;
280
281 case DFNT_UINT16:
282 {
283 if (no_interpolation == false) {
284 vector <uint16> total_val_uint16;
285 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_uint16, newdims);
286
287 if (r != 0) {
288 detachfunc (swathid);
289 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
290 ostringstream eherr;
291 eherr << "field " << fieldname.c_str () << "cannot be read.";
292 throw InternalErr (__FILE__, __LINE__, eherr.str ());
293
294 }
295 vector<uint16>val_uint16;
296 val_uint16.resize(nelms);
297 Field2DSubset (val_uint16.data(), newdims[0], newdims[1],total_val_uint16.data(),
298 offset32.data(), count32.data(), step32.data());
299
300 set_value ((dods_uint16 *) val_uint16.data(), nelms);
301 }
302
303 else {
305 val.resize(nelms);
306 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
307 if (r != 0) {
308 detachfunc (swathid);
309 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
310 ostringstream eherr;
311 eherr << "field " << fieldname.c_str () << "cannot be read.";
312 throw InternalErr (__FILE__, __LINE__, eherr.str ());
313 }
314
315 set_value ((dods_uint16 *) val.data(), nelms);
316 }
317 }
318 break;
319
320 case DFNT_INT32:
321 {
322 if (no_interpolation == false) {
323 vector <int32> total_val_int32;
324 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_int32, newdims);
325
326 if (r != 0) {
327 detachfunc (swathid);
328 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
329 ostringstream eherr;
330 eherr << "field " << fieldname.c_str () << "cannot be read.";
331 throw InternalErr (__FILE__, __LINE__, eherr.str ());
332
333 }
334 vector<int32>val_int32;
335 val_int32.resize(nelms);
336 Field2DSubset (val_int32.data(), newdims[0], newdims[1],total_val_int32.data(),
337 offset32.data(), count32.data(), step32.data());
338
339 set_value ((dods_int32 *) val_int32.data(), nelms);
340 }
341 else {
342 vector<int32>val;
343 val.resize(nelms);
344 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
345 if (r != 0) {
346 detachfunc (swathid);
347 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
348 ostringstream eherr;
349 eherr << "field " << fieldname.c_str () << "cannot be read.";
350 throw InternalErr (__FILE__, __LINE__, eherr.str ());
351 }
352
353 set_value ((dods_int32 *) val.data(), nelms);
354 }
355 }
356 break;
357
358 case DFNT_UINT32:
359 {
360 if (no_interpolation == false) {
361 vector <uint32> total_val_uint32;
362 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_uint32, newdims);
363
364 if (r != 0) {
365 detachfunc (swathid);
366 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
367 ostringstream eherr;
368 eherr << "field " << fieldname.c_str () << "cannot be read.";
369 throw InternalErr (__FILE__, __LINE__, eherr.str ());
370
371 }
372 vector<uint32>val_uint32;
373 val_uint32.resize(nelms);
374 Field2DSubset (val_uint32.data(), newdims[0], newdims[1],total_val_uint32.data(),
375 offset32.data(), count32.data(), step32.data());
376
377 set_value ((dods_uint32 *) val_uint32.data(), nelms);
378 }
379 else {
381 val.resize(nelms);
382 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
383 if (r != 0) {
384 detachfunc (swathid);
385 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
386 ostringstream eherr;
387 eherr << "field " << fieldname.c_str () << "cannot be read.";
388 throw InternalErr (__FILE__, __LINE__, eherr.str ());
389 }
390
391 set_value ((dods_uint32 *) val.data(), nelms);
392 }
393 }
394 break;
395 case DFNT_FLOAT32:
396 {
397 if (no_interpolation == false) {
398 vector <float32> total_val_f32;
399 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_f32, newdims);
400
401 if (r != 0) {
402 detachfunc (swathid);
403 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
404 ostringstream eherr;
405 eherr << "field " << fieldname.c_str () << "cannot be read.";
406 throw InternalErr (__FILE__, __LINE__, eherr.str ());
407
408 }
409 vector<float32>val_f32;
410 val_f32.resize(nelms);
411 Field2DSubset (val_f32.data(), newdims[0], newdims[1],total_val_f32.data(),
412 offset32.data(), count32.data(), step32.data());
413
414 set_value ((dods_float32 *) val_f32.data(), nelms);
415 }
416 else {
418 val.resize(nelms);
419 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
420 if (r != 0) {
421 detachfunc (swathid);
422 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
423 ostringstream eherr;
424 eherr << "field " << fieldname.c_str () << "cannot be read.";
425 throw InternalErr (__FILE__, __LINE__, eherr.str ());
426 }
427 set_value ((dods_float32 *) val.data(), nelms);
428 }
429 }
430 break;
431 case DFNT_FLOAT64:
432 {
433 if (no_interpolation == false) {
434 vector <float64> total_val_f64;
435 r = GetFieldValue (swathid, fieldname, dm_dimsizes,dm_offsets,dm_incs, total_val_f64, newdims);
436
437 if (r != 0) {
438 detachfunc (swathid);
439 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
440 ostringstream eherr;
441 eherr << "field " << fieldname.c_str () << "cannot be read.";
442 throw InternalErr (__FILE__, __LINE__, eherr.str ());
443
444 }
445 vector<float64>val_f64;
446 val_f64.resize(nelms);
447 Field2DSubset (val_f64.data(), newdims[0], newdims[1],total_val_f64.data(),
448 offset32.data(), count32.data(), step32.data());
449
450 set_value ((dods_float64 *) val_f64.data(), nelms);
451 }
452 else {
454 val.resize(nelms);
455 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), offset32.data(), step32.data(), count32.data(), val.data());
456 if (r != 0) {
457 detachfunc (swathid);
458 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
459 ostringstream eherr;
460 eherr << "field " << fieldname.c_str () << "cannot be read.";
461 throw InternalErr (__FILE__, __LINE__, eherr.str ());
462 }
463
464 set_value ((dods_float64 *) val.data(), nelms);
465 }
466 }
467 break;
468 default:
469 detachfunc (swathid);
470 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
471 throw InternalErr (__FILE__, __LINE__, "unsupported data type.");
472 }
473
474 r = detachfunc (swathid);
475 if (r != 0) {
476 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
477 ostringstream eherr;
478 eherr << "Swath " << datasetname.c_str () << " cannot be detached.";
479 throw InternalErr (__FILE__, __LINE__, eherr.str ());
480 }
481
482 HDFCFUtil::close_fileid(-1,-1,-1,sfid,check_pass_fileid_key);
483
484 return false;
485}
486
487// Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
488// Return the number of elements to read.
489int
490HDFEOS2ArraySwathGeoMultiDimMapField::format_constraint (int *offset, int *step, int *count)
491{
492 int nels = 1;
493 int id = 0;
494
495 Dim_iter p = dim_begin ();
496 while (p != dim_end ()) {
497
498 int start = dimension_start (p, true);
499 int stride = dimension_stride (p, true);
500 int stop = dimension_stop (p, true);
501
502 // Check for illegal constraint
503 if (start > stop) {
504 ostringstream oss;
505 oss << "Array/Grid hyperslab start point "<< start <<
506 " is greater than stop point " << stop <<".";
507 throw Error(malformed_expr, oss.str());
508 }
509
510 offset[id] = start;
511 step[id] = stride;
512 count[id] = ((stop - start) / stride) + 1; // count of elements
513 nels *= count[id]; // total number of values for variable
514
515 BESDEBUG ("h4",
516 "=format_constraint():"
517 << "id=" << id << " offset=" << offset[id]
518 << " step=" << step[id]
519 << " count=" << count[id]
520 << endl);
521
522 id++;
523 p++;
524 }// end of while
525
526 return nels;
527}
528
529// Subset of latitude and longitude to follow the parameters
530// from the DAP expression constraint
531template < class T >
532bool HDFEOS2ArraySwathGeoMultiDimMapField::Field2DSubset (T * outlatlon,
533 const int ,
534 const int minordim,
535 T * latlon,
536 const int32 * offset,
537 const int32 * count,
538 const int32 * step) const
539{
540
541 int i = 0;
542 int j = 0;
543
544 // do subsetting
545 // Find the correct index
546 int dim0count = count[0];
547 int dim1count = count[1];
548
549 int dim0index[dim0count];
550 int dim1index[dim1count];
551
552 for (i = 0; i < count[0]; i++) // count[0] is the least changing dimension
553 dim0index[i] = offset[0] + i * step[0];
554
555
556 for (j = 0; j < count[1]; j++)
557 dim1index[j] = offset[1] + j * step[1];
558
559 // Now assign the subsetting data
560 int k = 0;
561
562 for (i = 0; i < count[0]; i++) {
563 for (j = 0; j < count[1]; j++) {
564 outlatlon[k] = *(latlon + (dim0index[i] * minordim) + dim1index[j]);
565 k++;
566 }
567 }
568 return true;
569}
570
571// Get latitude and longitude fields.
572// It will call expand_dimmap_field to interpolate latitude and longitude.
573template < class T > int
574HDFEOS2ArraySwathGeoMultiDimMapField::
575GetFieldValue (int32 swathid, const string & geofieldname,
576 const vector <int>&dimsizes,const vector<int>&offset,const vector<int>&inc,
577 vector < T > &vals, vector<int32>&newdims)
578{
579
580 int32 ret = -1;
581 int32 size = -1;
582 int32 sw_rank = -1;
583 int32 dims[130];
584 int32 type = -1;
585
586 // Two dimensions for lat/lon; each dimension name is < 64 characters,
587 // The dimension names are separated by a comma.
588 char dimlist[130];
589 ret = SWfieldinfo (swathid, const_cast < char *>(geofieldname.c_str ()),
590 &sw_rank, dims, &type, dimlist);
591 if (ret != 0)
592 return -1;
593
594 if (sw_rank !=2)
595 return -1;
596
597 size = 1;
598 for (int i = 0; i <sw_rank; i++)
599 size *= dims[i];
600
601 vals.resize (size);
602
603 ret = SWreadfield (swathid, const_cast < char *>(geofieldname.c_str ()),
604 NULL, NULL, NULL, (void *) vals.data());
605 if (ret != 0)
606 return -1;
607
608 vector < string > dimname;
609 HDFCFUtil::Split (dimlist, ',', dimname);
610
611 for (int i = 0; i < sw_rank; i++) {
612
613 int r;
614 r = _expand_dimmap_field (&vals, sw_rank, dims, i, dimsizes[i], offset[i], inc[i]);
615 if (r != 0)
616 return -1;
617 }
618
619 // dims[] are expanded already.
620 for (int i = 0; i < sw_rank; i++) {
621 //cerr<<"i "<< i << " "<< dims[i] <<endl;
622 if (dims[i] < 0)
623 return -1;
624 newdims[i] = dims[i];
625 }
626
627 return 0;
628}
629
630// expand the dimension map field.
631template < class T > int
632HDFEOS2ArraySwathGeoMultiDimMapField::_expand_dimmap_field (vector < T >
633 *pvals, int32 sw_rank,
634 int32 dimsa[],
635 int dimindex,
636 int32 ddimsize,
637 int32 offset,
638 int32 inc) const
639{
640 vector < T > orig = *pvals;
641 vector < int32 > pos;
642 vector < int32 > dims;
643 vector < int32 > newdims;
644 pos.resize (sw_rank);
645 dims.resize (sw_rank);
646
647 for (int i = 0; i < sw_rank; i++) {
648 pos[i] = 0;
649 dims[i] = dimsa[i];
650 }
651 newdims = dims;
652 newdims[dimindex] = ddimsize;
653 dimsa[dimindex] = ddimsize;
654
655 int newsize = 1;
656
657 for (int i = 0; i < sw_rank; i++) {
658 newsize *= newdims[i];
659 }
660 pvals->clear ();
661 pvals->resize (newsize);
662
663 for (;;) {
664 // if end
665 if (pos[0] == dims[0]) {
666 // we past then end
667 break;
668 }
669 else if (pos[dimindex] == 0) {
670 // extract 1D values
671 vector < T > v;
672 for (int i = 0; i < dims[dimindex]; i++) {
673 pos[dimindex] = i;
674 v.push_back (orig[INDEX_nD_TO_1D (dims, pos)]);
675 }
676 // expand them
677
678 vector < T > w;
679 for (int32 j = 0; j < ddimsize; j++) {
680 int32 i = (j - offset) / inc;
681 T f;
682
683 if (i * inc + offset == j) // perfect match
684 {
685 f = (v[i]);
686 }
687 else {
688 int32 i1 = 0;
689 int32 i2 = (i<=0)?1:0;
690 int32 j1 = 0;
691 int32 j2 = 0;
692
693 if ((unsigned int) i + 1 >= v.size ()) {
694 i1 = v.size () - 2;
695 i2 = v.size () - 1;
696 }
697 else {
698 i1 = i;
699 i2 = i + 1;
700 }
701 j1 = i1 * inc + offset;
702 j2 = i2 * inc + offset;
703 f = (((j - j1) * v[i2] + (j2 - j) * v[i1]) / (j2 - j1));
704 }
705 w.push_back (f);
706 pos[dimindex] = j;
707 (*pvals)[INDEX_nD_TO_1D (newdims, pos)] = f;
708 }
709 pos[dimindex] = 0;
710 }
711 // next pos
712 pos[sw_rank - 1]++;
713 for (int i = sw_rank - 1; i > 0; i--) {
714 if (pos[i] == dims[i]) {
715 pos[i] = 0;
716 pos[i - 1]++;
717 }
718 }
719 }
720
721 return 0;
722}
723
724
725#endif
STL class.
STL class.
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
Definition HDFCFUtil.cc:58
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)