ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_CheckpointLsmData.H
Go to the documentation of this file.
1 #ifndef ERF_CHECKPOINT_LSM_DATA_H_
2 #define ERF_CHECKPOINT_LSM_DATA_H_
3 
4 #include <cstddef>
5 #include <string>
6 #include <vector>
7 
8 /**
9  * File names of the LSM data in a checkpoint.
10  *
11  * lsm_data[i] is written as "LsmData<i>". The Noah-MP snow and snowh fields
12  * were added in the middle of that numbering, which would shift every later
13  * index (the soil fields) by two and make an older checkpoint restart with the
14  * wrong fields. They are therefore stored under their own names and left out of
15  * the numbering, so every other field keeps the index it always had. A restart
16  * from a checkpoint that predates them keeps their initial values.
17  */
19 
20 inline bool
21 is_separately_named (const std::vector<std::string>& names, const std::size_t ivar)
22 {
23  return ivar < names.size() && (names[ivar] == "snow" || names[ivar] == "snowh");
24 }
25 
26 // The part of the file name after the level directory, for lsm_data[ivar].
27 inline std::string
28 file_stem (const std::vector<std::string>& names, const std::size_t ivar)
29 {
30  if (is_separately_named(names, ivar)) {
31  return "LsmData_" + names[ivar];
32  }
33  std::size_t index = ivar;
34  for (std::size_t k = 0; k < ivar; ++k) {
35  if (is_separately_named(names, k)) { --index; }
36  }
37  return "LsmData" + std::to_string(index);
38 }
39 
40 // True when a checkpoint written before the field existed is allowed to lack it.
41 inline bool
42 may_be_absent (const std::vector<std::string>& names, const std::size_t ivar)
43 {
44  return is_separately_named(names, ivar);
45 }
46 
47 } // namespace erf_checkpoint_lsm_data
48 
49 #endif
Definition: ERF_CheckpointLsmData.H:18
bool may_be_absent(const std::vector< std::string > &names, const std::size_t ivar)
Definition: ERF_CheckpointLsmData.H:42
std::string file_stem(const std::vector< std::string > &names, const std::size_t ivar)
Definition: ERF_CheckpointLsmData.H:28
bool is_separately_named(const std::vector< std::string > &names, const std::size_t ivar)
Definition: ERF_CheckpointLsmData.H:21