Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
standalone/main.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 #include <iostream>
24 #include <vector>
25 #include <list>
26 #include <sstream>
27 
28 using namespace std;
29 
30 #include "clop.H"
31 
32 extern "C" {
33  void RFLUMP(const char *,int *,long int);
34 }
35 
36 void
37 Usage(const string &pn)
38 {
39  cout << endl << "Usage: " << pn << " -c <casename> [-v 0-2]" << endl << endl
40  << " -c | --casename : Specifies the casename." << endl
41  << " -v | --verbosity : 0 - Quiet" << endl
42  << " 1 - Moderately verbose" << endl
43  << " 2 - Ridiculously verbose" << endl
44  << endl;
45 }
46 
47 int
48 main(int argc,char *argv[])
49 {
50  // Get the commandline into a string vector - it's easier
51  // to deal with that way.
52  vector<string> args = Vectize((const char **)argv,argc);
53 
54  // Get the name of the executable by stripping off any leading
55  // directory names
56  string program_name(stripdir(args[0]));
57 
58  // Specify the allowable options to the program
59  AddOp("casename",'c');
60  AddOp("verbosity",'v');
61  AddOp("help",'h');
62 
63  // Declare some variables for command line argument handling
64  string casename;
65  string sverb;
66  int verbosity;
67  bool help;
68  bool isset;
69 
70  // See if the help option is specified, if so give'm the usage text
71  if(help = GetOp("help",args)){
72  Usage(program_name);
73  exit(0);
74  }
75 
76  // Process casename option, if it's not set then fail
77  if(GetOp("casename",casename,args)){
78  if(casename.empty()){ // casename was empty
79  cerr << program_name
80  << ": Expected casename after casename option."
81  << " Use -h for usage instructions."
82  << endl;
83  exit(1);
84  }
85  }
86  else{ // option not specified (but it's required!)
87  cerr << program_name
88  << ": Missing required casename option."
89  << " Use -h for usage instructions."
90  << endl;
91  exit(1);
92  }
93 
94  // Process verbosity option
95  if(GetOp("verbosity",sverb,args)){
96  if(sverb.empty()){
97  cerr << program_name
98  << ": Expected verbosity level. "
99  << "Use -h for usage instructions." << endl;
100  exit(1);
101  }
102  istringstream Istr(sverb);
103  Istr >> verbosity;
104  if(verbosity < 0 || verbosity > 2){ // Some jerk specified a non numeric or negative
105  cerr << program_name
106  << ": Invalid verbosity value. Use -h for usage "
107  << "instructions." << endl;
108  exit(1);
109  }
110  }
111  else{ // Default verbosity
112  verbosity = 1;
113  }
114 
115  RFLUMP(casename.c_str(),&verbosity,casename.length());
116 }
117 
118 
119 
120 
121 
122 
const string stripdir(const string &)
bool GetOp(const string &ops, const vector< string > &args)
void AddOp(const string &lo, const char &so)
void Usage(const string &pn)
int main(int argc, char *argv[])
Definition: blastest.C:94
void RFLUMP(const char *, int *, long int)
vector< string > Vectize(const char **)
Definition: clop.C:182