@@ -307,6 +307,7 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV
307307 dimensions.attr (" names" ) = dim_names;
308308 if (! proxy) { // read the arrays:
309309 auto data_type (arr->GetDataType ());
310+ size_t sz = data_type.GetSize ();
310311 if (data_type.GetClass () == GEDTC_NUMERIC) {
311312 NumericVector vec (nValues);
312313 if (debug)
@@ -342,29 +343,30 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV
342343 vec_lst[i] = vec;
343344 } else if (data_type.GetClass () == GEDTC_COMPOUND) {
344345 const auto &components = data_type.GetComponents ();
345- size_t sz = data_type.GetSize ();
346346 std::vector<GByte> buf (sz * nValues);
347347 bool ok = arr->Read (offst.data (),
348348 anCount.data (),
349349 stp.data (), /* step: defaults to 1,1,1 */
350350 nullptr , /* stride: default to row-major convention */
351351 data_type,
352352 &buf[0 ]);
353+ if (!ok)
354+ stop (" Cannot read array into Compound buffer" );
353355 DataFrame tbl;
354356 GByte *v = buf.data ();
355357 for (const auto &co: components) {
356358 auto t (co->GetType ());
357359 if (t.GetClass () == GEDTC_NUMERIC) {
358- if (t.GetSize () != sizeof ( double ) )
360+ if (t.GetNumericDataType () != GDT_Float64 )
359361 stop (" only Float64 data supported in numeric compounds" );
360362 NumericVector vec (nValues);
361- for (int j = 0 ; j < nValues; j++)
363+ for (size_t j = 0 ; j < nValues; j++)
362364 memcpy (&(vec[j]), v + j * sz + co->GetOffset (), sizeof (double ));
363365 tbl.push_back (vec, co->GetName ());
364366 } else if (t.GetClass () == GEDTC_STRING) {
365367 CharacterVector vec (nValues);
366368 const char *str;
367- for (int j = 0 ; j < nValues; j++) {
369+ for (size_t j = 0 ; j < nValues; j++) {
368370 memcpy (&str, v + j * sz + co->GetOffset (), sizeof (const char *));
369371 vec[j] = str; // deep copy
370372 }
@@ -374,7 +376,25 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV
374376 }
375377 vec_lst[i] = tbl;
376378 } else { // GEDTC_STRING:
377- stop (" reading string data not implemented" );
379+ std::vector<GByte> buf (sz * nValues);
380+ bool ok = arr->Read (offst.data (),
381+ anCount.data (),
382+ stp.data (), /* step: defaults to 1,1,1 */
383+ nullptr , /* stride: default to row-major convention */
384+ data_type,
385+ &buf[0 ]);
386+ if (!ok)
387+ stop (" Cannot read array into string buffer" );
388+ GByte *v = buf.data ();
389+ CharacterVector vec (nValues);
390+ const char *str;
391+ for (size_t j = 0 ; j < nValues; j++) {
392+ memcpy (&str, v + j * sz, sizeof (const char *));
393+ vec[j] = str; // deep copy
394+ }
395+ vec.attr (" dim" ) = dims;
396+ vec.attr (" units" ) = arr->GetUnit ();
397+ vec_lst[i] = vec;
378398 }
379399 }
380400 }
0 commit comments