Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utilities/rocflu/init/main.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 #include <iostream>
54 #include <vector>
55 #include <list>
56 #include <sstream>
57 
58 using namespace std;
59 
60 #include "clop.H"
61 #include "FC.h"
62 
63 extern "C" {
64  void FC_GLOBAL(rfluinit,RFLUINIT)(const char *,int *,long int);
65 }
66 
67 void
68 Usage(const string &pn)
69 {
70  cout << endl << "Usage: " << pn << " -c <casename> [-v 0-2]" << endl << endl
71  << " -c | --casename : Specifies the casename" << endl
72  << " -v | --verbosity : Verbosity level:" << endl
73  << " 0 - Quiet" << endl
74  << " 1 - Moderately verbose" << endl
75  << " 2 - Ridiculously verbose" << endl
76  << endl;
77 }
78 
79 int
80 main(int argc,char *argv[])
81 {
82  // Get the commandline into a string vector - it's easier
83  // to deal with that way.
84  vector<string> args = Vectize((const char **)argv,argc);
85 
86  // Get the name of the executable by stripping off any leading
87  // directory names
88  string program_name(stripdir(args[0]));
89 
90  // Specify the allowable options to the program
91  AddOp("casename",'c');
92  AddOp("verbosity",'v');
93  AddOp("help",'h');
94 
95  // Declare some variables for command line argument handling
96  string casename;
97  string sverb;
98  int verbosity;
99  bool help;
100  bool isset;
101 
102  // See if the help option is specified, if so give'm the usage text
103  if(help = GetOp("help",args)){
104  Usage(program_name);
105  exit(0);
106  }
107 
108  // Process casename option, if it's not set then fail
109  if(GetOp("casename",casename,args)){
110  if(casename.empty()){ // casename was empty
111  cerr << program_name
112  << ": Expected casename after casename option."
113  << " Use -h for usage instructions."
114  << endl;
115  exit(1);
116  }
117  }
118  else{ // option not specified (but it's required!)
119  cerr << program_name
120  << ": Missing required casename option."
121  << " Use -h for usage instructions."
122  << endl;
123  exit(1);
124  }
125 
126  // Process verbosity option
127  if(GetOp("verbosity",sverb,args)){
128  if(sverb.empty()){
129  cerr << program_name
130  << ": Expected verbosity level. "
131  << "Use -h for usage instructions." << endl;
132  exit(1);
133  }
134  istringstream Istr(sverb);
135  Istr >> verbosity;
136  if(verbosity < 0 || verbosity > 2){ // Some jerk specified a non numeric or negative
137  cerr << program_name
138  << ": Invalid verbosity value. Use -h for usage "
139  << "instructions." << endl;
140  exit(1);
141  }
142  }
143  else{ // Default verbosity
144  verbosity = 1;
145  }
146 
147  FC_GLOBAL(rfluinit,RFLUINIT)(casename.c_str(),&verbosity,casename.length());
148 }
149 
subroutine rfluinit(caseString, verbLevel)
Definition: rfluinit.F90:45
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)
#define RFLUINIT
Definition: clop.H:114
int main(int argc, char *argv[])
Definition: blastest.C:94
#define FC_GLOBAL(name, NAME)
Definition: FC.h:5
vector< string > Vectize(const char **)
Definition: clop.C:182