Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/eamxx/src/dynamics/homme/homme_grids_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void HommeGridsManager::build_dynamics_grid () {

initialize_vertical_coordinates(dyn_grid);

dyn_grid->m_short_name = "dyn";
dyn_grid->m_disambiguation_suffix = "_d";
add_nonconst_grid(dyn_grid);
}

Expand Down Expand Up @@ -306,7 +306,7 @@ build_physics_grid (const ci_string& type, const ci_string& rebalance) {
dx_short_f.sync_to_dev();
}

phys_grid->m_short_name = type;
phys_grid->m_disambiguation_suffix = type;
add_nonconst_grid(phys_grid);
}

Expand Down
2 changes: 1 addition & 1 deletion components/eamxx/src/share/grid/abstract_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class AbstractGrid : public ekat::enable_shared_from_this<AbstractGrid>
// with the same name, IO can use this as a suffix to diambiguate the fields in
// the IO file, by appending each grid's suffix to the fields names.
// NOTE: we'd need setter/getter for this, so we might as well make it public
std::string m_short_name = "";
std::string m_disambiguation_suffix = "";

int get_unique_grid_id () const { return m_unique_grid_id; }

Expand Down
4 changes: 2 additions & 2 deletions components/eamxx/src/share/grid/mesh_free_grids_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ build_se_grid (const std::string& name, ekat::ParameterList& params)
elem_gids.sync_to_dev();
lid2idx.sync_to_dev();

se_grid->m_short_name = "se";
se_grid->m_disambiguation_suffix = "_se";
add_geo_data(se_grid);

add_nonconst_grid(se_grid);
Expand All @@ -130,7 +130,7 @@ build_point_grid (const std::string& name, ekat::ParameterList& params)
area.sync_to_host();

add_geo_data(pt_grid);
pt_grid->m_short_name = "pt";
pt_grid->m_disambiguation_suffix = "_pt";

add_nonconst_grid(pt_grid);
}
Expand Down
9 changes: 8 additions & 1 deletion components/eamxx/src/share/io/eamxx_output_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ setup (const std::shared_ptr<fm_type>& field_mgr,
// geo data in the output file when we create it.
if (m_save_grid_data) {
std::map<std::string, std::shared_ptr<const AbstractGrid>> grids;
DefaultMetadata meta;
for (const auto& it : m_output_streams) {
grids[it->get_io_grid()->name()] = it->get_io_grid();
}
Expand All @@ -149,7 +150,13 @@ setup (const std::shared_ptr<fm_type>& field_mgr,
continue;
}
if (use_suffix) {
fields.push_back(f.clone(f.name()+"_"+grid.second->m_short_name, grid.first));
fields.push_back(f.clone(f.name() + grid.second->m_disambiguation_suffix, grid.first));

// Adjust long/std name, as the default metadata does not recognize the names with suffix
using stratts_t = std::map<std::string,std::string>;
auto& str_atts = fields.back().get_header().get_extra_data<stratts_t>("io: string attributes");
str_atts["long_name"] = meta.get_longname(f.name());
str_atts["standard_name"] = meta.get_standardname(f.name());
} else {
fields.push_back(f.clone(f.name(), grid.first));
}
Expand Down
4 changes: 4 additions & 0 deletions components/eamxx/src/share/util/eamxx_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ std::vector<std::string> globloc(const std::string& pattern) {
return filenames;
}

// Instantiate non-const static members of DefaultMetadata class
std::map<std::string, std::string> DefaultMetadata::name_2_standardname;
std::map<std::string, std::string> DefaultMetadata::name_2_longname;

} // namespace scream
32 changes: 16 additions & 16 deletions components/eamxx/src/share/util/eamxx_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,38 +374,38 @@ struct DefaultMetadata {
// struct to store default metadata for variables output
// See the io_metadata folder for the file of interest

// Default string to fill in missing metadata
std::string fill_str = "MISSING";

std::map<std::string, std::string> name_2_standardname, name_2_longname;
static std::map<std::string, std::string> name_2_standardname;
static std::map<std::string, std::string> name_2_longname;

DefaultMetadata() {
// Ensure to resolve the path to the io_metadata.csv file
std::string fpath = __FILE__;
std::string directory = fpath.substr(0, fpath.find_last_of("/\\"));
std::string csv_path = directory + "/io_metadata/io_metadata.csv";
read_csv_file_to_maps(csv_path, name_2_standardname, name_2_longname);
if (name_2_standardname.size()==0) {
// Ensure to resolve the path to the io_metadata.csv file
std::string fpath = __FILE__;
std::string directory = fpath.substr(0, fpath.find_last_of("/\\"));
std::string csv_path = directory + "/io_metadata/io_metadata.csv";
read_csv_file_to_maps(csv_path, name_2_standardname, name_2_longname);
}
}

std::string get_standardname(const std::string &name) const {
static std::string get_standardname(const std::string &name) {
auto it = name_2_standardname.find(name);
if(it != name_2_standardname.end()) {
return it->second;
} else {
return fill_str;
return "MISSING";
}
}

std::string get_longname(const std::string &name) const {
static std::string get_longname(const std::string &name) {
auto it = name_2_longname.find(name);
if(it != name_2_longname.end()) {
return it->second;
} else {
return fill_str;
return "MISSING";
}
}

void read_csv_file_to_maps(
static void read_csv_file_to_maps(
const std::string &filename,
std::map<std::string, std::string> &name_2_standardname,
std::map<std::string, std::string> &name_2_longname) {
Expand Down Expand Up @@ -436,8 +436,8 @@ struct DefaultMetadata {
}

// Store the values to the maps, if they are not empty
name_2_standardname[column1] = column2.empty() ? fill_str : column2;
name_2_longname[column1] = column3.empty() ? fill_str : column3;
name_2_standardname[column1] = column2.empty() ? "MISSING" : column2;
name_2_longname[column1] = column3.empty() ? "MISSING" : column3;
}
file.close();
}
Expand Down
5 changes: 3 additions & 2 deletions components/eamxx/src/share/util/io_metadata/io_metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ cldfrac_ice_at_cldtop,ice_cloud_area_fraction,
cldfrac_ice,ice_cloud_area_fraction_in_atmosphere_layer,
omega,lagrangian_tendency_of_air_pressure,
landfrac,land_area_fraction,
latitude,latitude,
area,cell_area,
lat,latitude,
cldfrac_liq_at_cldtop,liquid_water_cloud_area_fraction,
cldfrac_liq,liquid_water_cloud_area_fraction_in_atmosphere_layer,
longitude,longitude,
lon,longitude,
rainfrac,mass_fraction_of_liquid_precipitation_in_air,
V,northward_wind,
nc,number_concentration_of_cloud_liquid_water_particles_in_air,
Expand Down