Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utilities/rocflu/map/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(rflumap,RFLUMAP)(const char *,int *,int *,int *,int *,long int);
65 }
66 
67 void
68 Usage(const string &pn)
69 {
70  cout << endl << "Usage: " << pn << " -c <casename> -r <n> -p <m> [-v 0-2]" << endl << endl
71  << " -c | --casename : Specifies the casename" << endl
72  << " -m | --mode : Mapping mode:" << endl
73  << " 1 - Initial mapping" << endl
74  << " 2 - Final mapping" << endl
75  << " -r | --nregions : Specifies the number of regions" << endl
76  << " -p | --nprocs : Specifies the number of processes" << endl
77  << " -v | --verbosity : Verbosity level:" << endl
78  << " 0 - Quiet" << endl
79  << " 1 - Moderately verbose" << endl
80  << " 2 - Ridiculously verbose" << endl
81  << endl;
82 }
83 
84 int
85 main(int argc,char *argv[])
86 {
87  // Get the commandline into a string vector - it's easier
88  // to deal with that way.
89  vector<string> args = Vectize((const char **)argv,argc);
90 
91  // Get the name of the executable by stripping off any leading
92  // directory names
93  string program_name(stripdir(args[0]));
94 
95  // Specify the allowable options to the program
96  AddOp("casename",'c');
97  AddOp("mode",'m');
98  AddOp("nregions",'r');
99  AddOp("nprocs",'p');
100  AddOp("verbosity",'v');
101  AddOp("help",'h');
102 
103  // Declare some variables for command line argument handling
104  string casename;
105  string smode,sprocs,sregs,sverb;
106  int mode;
107  int nprocs;
108  int nregions;
109  int verbosity;
110  bool help;
111  bool isset;
112 
113  // See if the help option is specified, if so give'm the usage text
114  if(help = GetOp("help",args)){
115  Usage(program_name);
116  exit(0);
117  }
118 
119  // Process casename option, if it's not set then fail
120  if(GetOp("casename",casename,args)){
121  if(casename.empty()){ // casename was empty
122  cerr << program_name
123  << ": Expected casename after casename option."
124  << " Use -h for usage instructions."
125  << endl;
126  exit(1);
127  }
128  }
129  else{ // option not specified (but it's required!)
130  cerr << program_name
131  << ": Missing required casename option."
132  << " Use -h for usage instructions."
133  << endl;
134  exit(1);
135  }
136 
137  // Process mode option
138  if(GetOp("mode",smode,args)){
139  if(smode.empty()){
140  cerr << program_name
141  << ": Expected mode value. "
142  << "Use -h for usage instructions." << endl;
143  exit(1);
144  }
145  istringstream Istr(smode);
146  Istr >> mode;
147  if(mode < 1 || mode > 2){ // Some jerk specified an invalid number
148  cerr << program_name
149  << ": Invalid mode value. Use -h for usage "
150  << "instructions." << endl;
151  exit(1);
152  }
153  }
154  else{ // option not specified (but it's required!)
155  cerr << program_name
156  << ": Missing mode value."
157  << " Use -h for usage instructions."
158  << endl;
159  exit(1);
160  }
161 
162  // Process nregions option
163  if(GetOp("nregions",sregs,args)){
164  if(sregs.empty()){
165  cerr << program_name
166  << ": Expected number of regions. "
167  << "Use -h for usage instructions." << endl;
168  exit(1);
169  }
170  istringstream Istr(sregs);
171  Istr >> nregions;
172  if(nregions < 1){ // Some jerk specified zero or a negative number
173  cerr << program_name
174  << ": Invalid number of regions. Use -h for usage "
175  << "instructions." << endl;
176  exit(1);
177  }
178  }
179  else{ // option not specified
180  if(mode == 1){
181  cerr << program_name
182  << ": Missing number of regions."
183  << " Use -h for usage instructions."
184  << endl;
185  exit(1);
186  }
187  else {
188  nregions = -1;
189  }
190  }
191 
192  // Process nprocs option
193  if(GetOp("nprocs",sprocs,args)){
194  if(sprocs.empty()){
195  cerr << program_name
196  << ": Expected number of processes. "
197  << "Use -h for usage instructions." << endl;
198  exit(1);
199  }
200  istringstream Istr(sprocs);
201  Istr >> nprocs;
202  if(nprocs < 1){ // Some jerk specified zero or a negative number
203  cerr << program_name
204  << ": Invalid number of processes. Use -h for usage "
205  << "instructions." << endl;
206  exit(1);
207  }
208  if(nprocs > nregions){
209  cerr << program_name
210  << ": Number of processes must not exceed number of regions." << endl;
211  exit(1);
212  }
213  }
214  else{ // option not specified
215  if(mode == 1){
216  cerr << program_name
217  << ": Missing number of processes."
218  << " Use -h for usage instructions."
219  << endl;
220  exit(1);
221  }
222  else {
223  nprocs = -1;
224  }
225  }
226 
227  // Process verbosity option
228  if(GetOp("verbosity",sverb,args)){
229  if(sverb.empty()){
230  cerr << program_name
231  << ": Expected verbosity level. "
232  << "Use -h for usage instructions." << endl;
233  exit(1);
234  }
235  istringstream Istr(sverb);
236  Istr >> verbosity;
237  if(verbosity < 0 || verbosity > 2){ // Some jerk specified a non numeric or negative
238  cerr << program_name
239  << ": Invalid verbosity value. Use -h for usage "
240  << "instructions." << endl;
241  exit(1);
242  }
243  }
244  else{ // Default verbosity
245  verbosity = 1;
246  }
247 
248  FC_GLOBAL(rflumap,RFLUMAP)(casename.c_str(),&mode,&nregions,&nprocs,&verbosity,casename.length());
249 }
250 
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 RFLUMAP
Definition: clop.H:115
int main(int argc, char *argv[])
Definition: blastest.C:94
subroutine rflumap(caseString, mapOption, nRegions, nProcs, verbLevel)
Definition: rflumap.F90:48
#define FC_GLOBAL(name, NAME)
Definition: FC.h:5
vector< string > Vectize(const char **)
Definition: clop.C:182