From bf72718901b8c45dbb0865937520e333a4378960 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 16 Oct 2024 21:21:10 +0000 Subject: [PATCH] #2859 Added UGridFile::find_metadata_names. Support two dimensions for the cell size --- src/libcode/vx_data2d_ugrid/ugrid_file.cc | 48 ++++++++++++++++++++--- src/libcode/vx_data2d_ugrid/ugrid_file.h | 3 +- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.cc b/src/libcode/vx_data2d_ugrid/ugrid_file.cc index 438e0e58e..806465a64 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.cc +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.cc @@ -232,11 +232,10 @@ bool UGridFile::open_metadata(const char * filepath) // Face (cell) dimension face_count = 1; - meta_name = find_metadata_name(DIM_KEYS[0], dim_names); - if (0 < meta_name.length()) { + StringArray sa; + bool status = find_metadata_names(DIM_KEYS[0], sa, dim_names); + if (status && 0 < sa.n()) { int data_face_count = 1; - StringArray sa; - sa.parse_css(meta_name); for (int i=0; i d(plane_size); int length; + int data_size = 1; size_t dim_size; LongArray offsets; LongArray lengths; for (int k=0; kgetDim(k).getSize(); if (a[k] == vx_data2d_star) { offsets.add(0); - length = plane_size; + length = dim_size; } else { offsets.add(a[k]); if (k != var->t_slot && k != var->z_slot) length = plane_size - a[k]; } + data_size *= length; lengths.add(length); dim_size = v->getDim(k).getSize(); if (dim_size < offsets[k]) { @@ -748,11 +767,23 @@ bool UGridFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const } } + if(data_size < plane_size) { + mlog << Error << "\n" << method_name + << "allocate memory (" << plane_size << ") is smaller than the data size (" + << data_size << ") for " << GET_NC_NAME_P(v) << "\"\n\n"; + exit ( 1 ); + } + else if(data_size > plane_size) { + mlog << Warning << "\n" << method_name + << "allocate memory (" << plane_size << ") is bigger than the data size (" + << data_size << ") for " << GET_NC_NAME_P(v) << "\"\n\n"; + } + get_nc_data(v, d.data(), lengths, offsets); double min_value = 10e10; double max_value = -min_value; - for (int x = 0; x< nx; ++x) { + for (int x = 0; x _lat(face_count); vector _lon(face_count); diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.h b/src/libcode/vx_data2d_ugrid/ugrid_file.h index 622aaa046..99a665b18 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.h +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.h @@ -61,7 +61,7 @@ class UGridFile { return ((_faceDim == nullptr) ? 0 : GET_NC_SIZE_P(_faceDim)) * ((_faceDimY == nullptr) ? 1 : GET_NC_SIZE_P(_faceDimY)); } - + int getNy() const { return 1; } @@ -166,6 +166,7 @@ class UGridFile { // grid member with that information. std::string find_metadata_name(std::string &key, StringArray &available_names); + bool find_metadata_names(std::string &key, StringArray &meta_names, StringArray &available_names); StringArray get_metadata_names(std::string &key); void read_config(ConcatString config_filename); void read_netcdf_grid();