ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_checkpoint_surface_temperature Namespace Reference

Enumerations

enum class  ContractReadStatus { Valid , Malformed , UnknownVersion }
 
enum class  LegacyInitType { WRFInput , Metgrid , Unknown }
 
enum class  LegacySurfaceTemperatureCompatibility { Compatible , UnsafeMetgrid , UnknownProvenance }
 

Functions

void write_contract_version (std::ostream &output)
 
int first_legacy_surface_temperature_level (const std::string &checkpointname, const int finest_level)
 
LegacyInitType parse_legacy_init_type_value (std::string value)
 
ContractReadStatus read_contract_version (std::istream &input, int &version)
 
LegacyInitType parse_legacy_init_type_from_job_info (std::istream &input)
 
LegacySurfaceTemperatureCompatibility classify_legacy_surface_temperature_checkpoint (const bool marker_present, const bool has_surface_arrays, const LegacyInitType legacy_init_type)
 

Variables

constexpr int contract_version = 1
 

Enumeration Type Documentation

◆ ContractReadStatus

◆ LegacyInitType

◆ LegacySurfaceTemperatureCompatibility

Function Documentation

◆ classify_legacy_surface_temperature_checkpoint()

LegacySurfaceTemperatureCompatibility erf_checkpoint_surface_temperature::classify_legacy_surface_temperature_checkpoint ( const bool  marker_present,
const bool  has_surface_arrays,
const LegacyInitType  legacy_init_type 
)
inline
178 {
179  if (marker_present || !has_surface_arrays) {
180  return LegacySurfaceTemperatureCompatibility::Compatible;
181  }
182  if (legacy_init_type == LegacyInitType::WRFInput) {
183  return LegacySurfaceTemperatureCompatibility::Compatible;
184  }
185  if (legacy_init_type == LegacyInitType::Metgrid) {
186  return LegacySurfaceTemperatureCompatibility::UnsafeMetgrid;
187  }
188  return LegacySurfaceTemperatureCompatibility::UnknownProvenance;
189 }

◆ first_legacy_surface_temperature_level()

int erf_checkpoint_surface_temperature::first_legacy_surface_temperature_level ( const std::string &  checkpointname,
const int  finest_level 
)
inline

Return the first AMR level containing a legacy SST or TSK surface array.

The arrays are identified by their AMReX header files. A return value of -1 means that neither legacy array is present on any level.

31 {
32  for (int lev = 0; lev <= finest_level; ++lev) {
33  const bool has_sst = amrex::FileExists(
34  amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "SST_0_H"));
35  const bool has_tsk = amrex::FileExists(
36  amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TSK_0_H"));
37  if (has_sst || has_tsk) {
38  return lev;
39  }
40  }
41  return -1;
42 }

◆ parse_legacy_init_type_from_job_info()

LegacyInitType erf_checkpoint_surface_temperature::parse_legacy_init_type_from_job_info ( std::istream &  input)
inline

Legacy Metgrid SST/TSK arrays are absolute temperature, whereas current Metgrid initialization stores the SurfaceLayer representation (theta). Without the marker there is no pressure in a checkpoint with which to reinterpret those legacy arrays safely.

104 {
105  constexpr const char* key = "erf.init_type";
106  constexpr std::size_t key_length = 13;
107  LegacyInitType result = LegacyInitType::Unknown;
108  std::string line;
109 
110  while (std::getline(input, line)) {
111  std::size_t pos = 0;
112  while (pos < line.size() &&
113  std::isspace(static_cast<unsigned char>(line[pos]))) {
114  ++pos;
115  }
116  if (line.compare(pos, key_length, key) != 0) {
117  continue;
118  }
119  pos += key_length;
120  if (pos < line.size() && !std::isspace(static_cast<unsigned char>(line[pos])) &&
121  line[pos] != '=') {
122  continue;
123  }
124  while (pos < line.size() &&
125  std::isspace(static_cast<unsigned char>(line[pos]))) {
126  ++pos;
127  }
128  if (pos == line.size() || line[pos] != '=') {
129  result = LegacyInitType::Unknown;
130  continue;
131  }
132  ++pos;
133  while (pos < line.size() &&
134  std::isspace(static_cast<unsigned char>(line[pos]))) {
135  ++pos;
136  }
137 
138  std::string value;
139  bool malformed = (pos == line.size());
140  if (!malformed && line[pos] == '"') {
141  ++pos;
142  const std::size_t end_quote = line.find('"', pos);
143  if (end_quote == std::string::npos) {
144  malformed = true;
145  } else {
146  value = line.substr(pos, end_quote - pos);
147  pos = end_quote + 1;
148  }
149  } else if (!malformed) {
150  const std::size_t value_begin = pos;
151  while (pos < line.size() &&
152  !std::isspace(static_cast<unsigned char>(line[pos]))) {
153  ++pos;
154  }
155  value = line.substr(value_begin, pos - value_begin);
156  }
157 
158  while (pos < line.size() &&
159  std::isspace(static_cast<unsigned char>(line[pos]))) {
160  ++pos;
161  }
162  if (malformed || pos != line.size()) {
163  result = LegacyInitType::Unknown;
164  continue;
165  }
166 
167  result = parse_legacy_init_type_value(value);
168  }
169 
170  return result;
171 }
LegacyInitType parse_legacy_init_type_value(std::string value)
Definition: ERF_CheckpointSurfaceTemperature.H:63
LegacyInitType
Definition: ERF_CheckpointSurfaceTemperature.H:50
Here is the call graph for this function:

◆ parse_legacy_init_type_value()

LegacyInitType erf_checkpoint_surface_temperature::parse_legacy_init_type_value ( std::string  value)
inline
64 {
65  for (char& character : value) {
66  character = static_cast<char>(std::tolower(static_cast<unsigned char>(character)));
67  }
68  if (value == "wrfinput") {
69  return LegacyInitType::WRFInput;
70  }
71  if (value == "metgrid") {
72  return LegacyInitType::Metgrid;
73  }
74  return LegacyInitType::Unknown;
75 }

Referenced by parse_legacy_init_type_from_job_info().

Here is the caller graph for this function:

◆ read_contract_version()

ContractReadStatus erf_checkpoint_surface_temperature::read_contract_version ( std::istream &  input,
int &  version 
)
inline

Parse the integer surface-temperature contract marker from a checkpoint.

82 {
83  if (!(input >> version)) {
84  return ContractReadStatus::Malformed;
85  }
86 
87  std::string extra;
88  if (input >> extra) {
89  return ContractReadStatus::Malformed;
90  }
91 
92  return (version == contract_version) ? ContractReadStatus::Valid
93  : ContractReadStatus::UnknownVersion;
94 }
constexpr int contract_version
Definition: ERF_CheckpointSurfaceTemperature.H:14

◆ write_contract_version()

void erf_checkpoint_surface_temperature::write_contract_version ( std::ostream &  output)
inline
18 {
19  output << contract_version << "\n";
20 }

Variable Documentation

◆ contract_version

constexpr int erf_checkpoint_surface_temperature::contract_version = 1
constexpr