toptions.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
toptions.cc (2415B)
---
1 /* Copyright (C) 2018, 2019 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "options.hh"
21
22 #include "pism/util/Context.hh"
23 #include "pism/util/ConfigInterface.hh"
24 #include "pism/util/Logger.hh"
25 #include "pism/util/Component.hh"
26
27 namespace pism {
28
29 ForcingOptions::ForcingOptions(const Context &ctx,
30 const std::string &prefix) {
31
32 const Logger &log = *ctx.log();
33 const Config &config = *ctx.config();
34
35 {
36 auto file = config.get_string(prefix + ".file");
37
38 if (not file.empty()) {
39 this->filename = file;
40 log.message(2,
41 " - Reading boundary conditions from '%s'...\n",
42 file.c_str());
43 } else {
44 this->filename = process_input_options(ctx.com(), ctx.config()).filename;
45
46 log.message(2,
47 " - Option %s.file is not set. Trying the input file '%s'...\n",
48 prefix.c_str(), this->filename.c_str());
49 }
50
51 if (this->filename.empty()) {
52 throw RuntimeError::formatted(PISM_ERROR_LOCATION,
53 "PISM ERROR: %s.file is empty and no input ('-i') file found.",
54 prefix.c_str());
55 }
56 }
57
58 {
59 auto P = config.get_number(prefix + ".period");
60
61 if (P < 0.0) {
62 throw RuntimeError::formatted(PISM_ERROR_LOCATION,
63 "invalid %s_period %d (period length cannot be negative)",
64 prefix.c_str(), (int)P);
65 }
66 this->period = P;
67 }
68
69 {
70 auto ref_year = config.get_number(prefix + ".reference_year");
71
72 this->reference_time = units::convert(ctx.unit_system(), ref_year, "years", "seconds");
73 }
74 }
75
76 } // end of namespace pism