Skip to content

Commit

Permalink
#2673 Added _faceDimY and support two dimensions for the cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Oct 16, 2024
1 parent 7b73439 commit 73123a2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
38 changes: 31 additions & 7 deletions src/libcode/vx_data2d_ugrid/ugrid_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void UGridFile::init_from_scratch()
_time_var_info = (NcVarInfo *)nullptr;

_faceDim = (NcDim *)nullptr;
_faceDimY = (NcDim *)nullptr;
_edgeDim = (NcDim *)nullptr;
_nodeDim = (NcDim *)nullptr;
_virtDim = (NcDim *)nullptr;
Expand Down Expand Up @@ -135,7 +136,22 @@ void UGridFile::close()
metadata_map.clear();
metadata_names.clear();

_faceDim = _edgeDim = _tDim = (NcDim *)nullptr;
if (_faceDim) {
delete _faceDim;
_faceDim = (NcDim *)nullptr;
}
if (_faceDimY) {
delete _faceDimY;
_faceDimY = (NcDim *)nullptr;
}
if (_edgeDim) {
delete _edgeDim;
_edgeDim = (NcDim *)nullptr;
}
if (_tDim) {
delete _tDim;
_tDim = (NcDim *)nullptr;
}

// Reclaim the variable pointers

Expand Down Expand Up @@ -215,13 +231,20 @@ bool UGridFile::open_metadata(const char * filepath)
get_dim_names(_ncMetaFile, &dim_names);

// Face (cell) dimension
face_count = 1;
meta_name = find_metadata_name(DIM_KEYS[0], dim_names);
if (0 < meta_name.length()) {
dim = get_nc_dim(_ncMetaFile, meta_name.c_str());
face_count = get_dim_size(&dim);
_faceDim = new NcDim(dim);
NcDim face_dim = get_nc_dim(_ncFile, meta_name.c_str());
int data_face_count = get_dim_size(&face_dim);
int data_face_count = 1;
StringArray sa;
sa.parse_css(meta_name);
for (int i=0; i<sa.n(); i++) {
dim = get_nc_dim(_ncMetaFile, sa[i].c_str());
face_count *= get_dim_size(&dim);
if (i == 0) _faceDim = new NcDim(dim);
else _faceDimY = new NcDim(dim);
NcDim face_dim = get_nc_dim(_ncFile, sa[i].c_str());
data_face_count *= get_dim_size(&face_dim);
}
if (face_count != data_face_count) {
mlog << Error << "\n" << method_name
<< meta_name << " dimension is different: data file = "
Expand Down Expand Up @@ -473,6 +496,7 @@ void UGridFile::dump(ostream & out, int depth) const
out << prefix << "\n";

out << prefix << "face_dim = " << (_faceDim ? GET_NC_NAME_P(_faceDim) : "(nul)") << "\n";
out << prefix << "face_dimY = " << (_faceDimY ? GET_NC_NAME_P(_faceDimY) : "(nul)") << "\n";
out << prefix << "edge_dim = " << (_edgeDim ? GET_NC_NAME_P(_edgeDim) : "(nul)") << "\n";
out << prefix << "Tdim = " << (_tDim ? GET_NC_NAME_P(_tDim) : "(nul)") << "\n";

Expand Down Expand Up @@ -512,7 +536,7 @@ void UGridFile::dump(ostream & out, int depth) const
{
if (Var[j].Dims[k] == _faceDim)
out << 'X';
else if (Var[j].Dims[k] == _edgeDim)
else if (Var[j].Dims[k] == _faceDimY)
out << 'Y';
else if (Var[j].Dims[k] == _tDim)
out << 'T';
Expand Down
6 changes: 4 additions & 2 deletions src/libcode/vx_data2d_ugrid/ugrid_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class UGridFile {


int getNx() const {
return (_faceDim == nullptr) ? 0 : GET_NC_SIZE_P(_faceDim);
return ((_faceDim == nullptr) ? 0 : GET_NC_SIZE_P(_faceDim))
* ((_faceDimY == nullptr) ? 1 : GET_NC_SIZE_P(_faceDimY));
}

int getNy() const {
return 1;
}

NcVarInfo *get_time_var_info() const { return _time_var_info; }

//
Expand Down Expand Up @@ -140,6 +141,7 @@ class UGridFile {
// arrays so should not be deleted.

netCDF::NcDim *_faceDim;
netCDF::NcDim *_faceDimY;
netCDF::NcDim *_edgeDim;
netCDF::NcDim *_nodeDim;
netCDF::NcDim *_virtDim;
Expand Down

0 comments on commit 73123a2

Please sign in to comment.