URI:
       tpism_options.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
       ---
       tpism_options.cc (3409B)
       ---
            1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 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 #include <cstring>
           20 
           21 #include "pism_options.hh"
           22 #include "pism_utilities.hh"
           23 #include "VariableMetadata.hh"
           24 #include "ConfigInterface.hh"
           25 
           26 #include "error_handling.hh"
           27 #include "Logger.hh"
           28 
           29 namespace pism {
           30 
           31 //! \brief Print a usage message.
           32 void show_usage(const Logger &log, const std::string &execname, const std::string &usage) {
           33   log.message(1,
           34              "%s is a PISM (http://www.pism-docs.org) executable.\n"
           35              "Options cheat-sheet:\n",
           36              execname.c_str());
           37   log.message(1, usage);
           38   log.message(1,
           39              "Parallel run using N processes (typical case):  mpiexec -n N %s ...\n"
           40              "For more help with PISM:\n"
           41              "  1. download PDF User's Manual:\n"
           42              "       http://www.pism-docs.org/wiki/lib/exe/fetch.php?media=pism_manual.pdf\n"
           43              "  2. read browser for technical details:\n"
           44              "       http://www.pism-docs.org/doxy/html/index.html\n"
           45              "  3. view issues/bugs at source host: https://github.com/pism/pism/issues\n"
           46              "  4. do '%s -help | grep foo' to see PISM and PETSc options with 'foo'.\n"
           47              "  5. email for help:  uaf-pism@alaska.edu\n",
           48              execname.c_str(), execname.c_str());
           49 }
           50 
           51 //! @brief In a single call a driver program can provide a usage string to
           52 //! the user and check if required options are given, and if not, end.
           53 bool show_usage_check_req_opts(const Logger &log,
           54                                const std::string &execname,
           55                                const std::vector<std::string> &required_options,
           56                                const std::string &usage) {
           57   const bool
           58     keep_running = false,
           59     terminate = true;
           60 
           61   log.message(2, "%s %s\n", execname.c_str(), pism::revision);
           62 
           63   if (options::Bool("-version", "stop after printing print PISM version")) {
           64     log.message(2, pism::version());
           65     return terminate;
           66   }
           67 
           68   if (options::Bool("-usage", "print PISM usage")) {
           69     show_usage(log, execname, usage);
           70     return terminate;
           71   }
           72 
           73   // go through list of required options, and if not given, fail
           74   bool req_absent = false;
           75   for (auto opt : required_options) {
           76     if (not options::Bool(opt, "a required option")) {
           77       req_absent = true;
           78       log.error("PISM ERROR: option %s required\n", opt.c_str());
           79     }
           80   }
           81 
           82   if (req_absent) {
           83     log.error("\n");
           84     show_usage(log, execname, usage);
           85     return terminate;
           86   }
           87 
           88   // show usage message with -help, but don't stop
           89   if (options::Bool("-help", "print help on all options")) {
           90     show_usage(log, execname, usage);
           91   }
           92   return keep_running;
           93 }
           94 
           95 } // end of namespace pism