Skip to content

Commit 1f1bdc6

Browse files
committed
components, take 1
1 parent 0b8995e commit 1f1bdc6

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/mdim.cpp

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,19 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV
307307
dimensions.attr("names") = dim_names;
308308
NumericVector vec;
309309
if (! proxy) { // read the arrays:
310-
NumericVector vec_(nValues);
311-
if (debug)
312-
Rcout << "size of vec_: " << vec_.size() << "\n";
313-
bool ok = arr->Read(offst.data(),
314-
anCount.data(),
315-
stp.data(), /* step: defaults to 1,1,1 */
316-
nullptr, /* stride: default to row-major convention */
317-
GDALExtendedDataType::Create(GDT_Float64),
318-
vec_.begin());
319-
if (!ok) {
320-
Rcout << "Cannot read array into a Float64 buffer" << name << std::endl;
321-
for (size_t i = 0; i < nValues; i++)
322-
vec_[i] = NA_REAL;
323-
} else {
310+
auto data_type(arr->GetDataType());
311+
if (data_type.GetClass() == GEDTC_NUMERIC) {
312+
NumericVector vec_(nValues);
313+
if (debug)
314+
Rcout << "size of vec_: " << vec_.size() << "\n";
315+
bool ok = arr->Read(offst.data(),
316+
anCount.data(),
317+
stp.data(), /* step: defaults to 1,1,1 */
318+
nullptr, /* stride: default to row-major convention */
319+
GDALExtendedDataType::Create(GDT_Float64),
320+
vec_.begin());
321+
if (!ok)
322+
stop("Cannot read array into a Float64 buffer");
324323
bool has_offset = false;
325324
double offst = arr->GetOffset(&has_offset);
326325
if (!has_offset)
@@ -339,10 +338,26 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV
339338
vec_[i] = vec_[i] * scale + offst;
340339
}
341340
}
341+
vec_.attr("dim") = dims;
342+
vec_.attr("units") = arr->GetUnit();
343+
vec = vec_;
344+
} else if (data_type.GetClass() == GEDTC_COMPOUND) {
345+
std::vector<std::unique_ptr<GDALEDTComponent>> components;
346+
components = data_type.GetComponents();
347+
for (size_t i = 0; i < components.size(); i++) {
348+
auto t(components[i]->GetType());
349+
if (t.GetClass() == GEDTC_NUMERIC)
350+
Rcout << "numeric ";
351+
else if (t.GetClass() == GEDTC_STRING)
352+
Rcout << "string ";
353+
else
354+
Rcout << "other ";
355+
Rcout << std::endl;
356+
}
357+
stop("reading compound data not implemented");
358+
} else { // GEDTC_STRING:
359+
stop("reading string data not implemented");
342360
}
343-
vec_.attr("dim") = dims;
344-
vec_.attr("units") = arr->GetUnit();
345-
vec = vec_;
346361
}
347362
vec_lst[i] = vec;
348363
}

0 commit comments

Comments
 (0)