ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ForestUtils.H
Go to the documentation of this file.
1 #ifndef ERF_FOREST_UTILS_H_
2 #define ERF_FOREST_UTILS_H_
3 
4 #include <cmath>
5 #include <sstream>
6 #include <string>
7 
8 #include <AMReX_REAL.H>
9 
10 namespace erf_forest_utils {
11 
12 inline std::string
13 validate_cartesian_coordinates (bool has_x, bool has_y,
14  bool has_lon, bool has_lat,
15  const std::string& source)
16 {
17  if (has_x != has_y) {
18  return source + " must provide both projected Cartesian x and y coordinate variables";
19  }
20  if (!has_x && (has_lon || has_lat)) {
21  return source + " provides lon/lat coordinates, but projected Cartesian x/y are required; "
22  "no lon/lat-to-Cartesian projection is applied";
23  }
24  if (!has_x) {
25  return source + " must provide projected Cartesian x and y coordinate variables";
26  }
27  return {};
28 }
29 
30 /**
31  * Return an actionable diagnostic for an invalid type-2 canopy LAI maximum.
32  * The caller supplies the source description so file-backed and input-backed
33  * errors can identify where the bad value came from without aborting here.
34  */
35 inline std::string
36 validate_laimax (const amrex::Real laimax, const std::string& source)
37 {
38  if (std::isfinite(static_cast<double>(laimax)) &&
39  laimax >= amrex::Real(0.0) && laimax < amrex::Real(1.0)) {
40  return {};
41  }
42 
43  std::ostringstream message;
44  message << source << " must satisfy 0 <= laimax < 1 (got " << laimax << ")";
45  return message.str();
46 }
47 
48 } // namespace erf_forest_utils
49 
50 #endif
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_ForestUtils.H:10
std::string validate_laimax(const amrex::Real laimax, const std::string &source)
Definition: ERF_ForestUtils.H:36
std::string validate_cartesian_coordinates(bool has_x, bool has_y, bool has_lon, bool has_lat, const std::string &source)
Definition: ERF_ForestUtils.H:13