1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// *****************************************************************************
/*!
  \file      src/Control/MeshConvConfig.hpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     MeshConv's command line
*/
// *****************************************************************************
#pragma once

#include <getopt.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <csignal><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "NoWarning/charm++.hpp"<--- Include file: "NoWarning/charm++.hpp" not found.

#include "XystConfig.hpp"
#include "Exception.hpp"
#include "Print.hpp"
#include "TaggedTuple.hpp"
#include "PrintTaggedTupleDeep.hpp"
#include "Writer.hpp"

namespace tag {
DEFTAG( input );
DEFTAG( output );
DEFTAG( reorder );
DEFTAG( quiescence );
} // tag::

namespace meshconv {
//! Mesh converter control facilitating user input to internal data transfer
namespace ctr {

//! Member data for tagged tuple
using ConfigMembers = brigand::list<
    tag::input, std::string     // input mesh file
  , tag::output, std::string    // output mesh file
  , tag::reorder, bool          // reorder nodes
  , tag::quiescence, bool       // enable quiescence detection
>;

//! Config is a TaggedTuple specialized to MeshConv
class Config : public tk::TaggedTuple< ConfigMembers > {

  public:
    //! Parse meshconv command line
    void cmdline( int argc, char** argv ) {
      if (argc == 1) {
        help( argv );
        CkExit( EXIT_FAILURE );
      }
      tk::Print print;

      // Process command line arguments
      int c; 
      while ((c = getopt( argc, argv, "h?i:o:qrs:v" )) != -1) {
        switch (c) {
          case '?':
          case 'h':
          default:
            help( argv );
            CkExit();
            break;
          case 'i':
            get< tag::input >() = optarg;
            break;
          case 'o':
            get< tag::output >() = optarg;
            break;
          case 'q':
            get< tag::quiescence >() = true;
            break;
          case 'r':
            get< tag::reorder >() = true;
            break;
          case 's':
            std::raise( std::stoi( optarg ) );
            break;
          case 'v':
            print << '\n';
            print.version( tk::meshconv_executable(), tk::git_commit() );
            CkExit();
            break;
        }
      }

      if (optind != argc) {
        print << "\nA non-option was supplied";
        help( argv );
        CkExit( EXIT_FAILURE );
      }
      ErrChk( not get< tag::input >().empty(),
              "Mandatory input file not specified. Use -i <filename>." );
      ErrChk( not get< tag::output >().empty(),
              "Mandatory output file not specified. Use -o <filename>." );
    
      // Output state to file
      auto logfilename = tk::meshconv_executable() + "_cmdline.log";
      tk::Writer log( logfilename );
      tk::print( log.stream(), *this );
    }

    void help( char** argv ) {
      tk::Print() <<
        "\nUsage: " << argv[0] << " -i <in.msh> -o <out.exo> [OPTION]...\n"
        "\n"
        "  -h, -?       Print out this help\n"
        "  -i <in.msh>  Specify input file\n"
        "  -o <out.exo> Specify output file\n"
        "  -r           Reorder mesh nodes\n"
        "  -q           Enable quiescence detection\n"
        "  -v           Print revision information\n"
        "\n";
    }

    /** @name Pack/Unpack: Serialize Config object for Charm++ */
    ///@{
    //! \brief Pack/Unpack serialize member function
    //! \param[in,out] p Charm++'s PUP::er serializer object reference
    void pup( PUP::er& p ) { tk::TaggedTuple< ConfigMembers >::pup(p); }<--- Derived function 'Config::pup'
    //! \brief Pack/Unpack serialize operator|
    //! \param[in,out] p Charm++'s PUP::er serializer object reference
    //! \param[in,out] c Config object reference
    friend void operator|( PUP::er& p, Config& c ) { c.pup(p); }
    //@}
};

} // ctr::
} // meshconv::