Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plagprep.C
Go to the documentation of this file.
1 
13 //============================================================================
14 // P R E P R O C E S S O R D I R E C T I V E S
15 //============================================================================
16 #include <iostream>
17 #include <cstdlib>
18 #include <cstdio>
19 #include <fstream>
20 #include <sstream>
21 #include <string>
22 #include <cstring>
23 
24 //================================================================================
25 // G L O B A L V A R I A B L E S
26 //================================================================================
27 
29 std::string prjname;
30 
32 std::string outputfile;
33 
36 
43 
44 
45 //=================================================================================
46 // F U N C T I O N P R O T O T Y P E D E C L A R A T I O N
47 //=================================================================================
48 
52 void showUsage( );
53 
61 bool parseCmdParameters( int argc, char **argv );
62 
67 void searchTopFile( );
68 
76 int main( int argc, char **argv )
77 {
78  std::cout << __DATE__ << " Running program: " << argv[ 0 ] << std::endl;
79 
80  std::cout << "Parsing command line parameters...";
81  if( parseCmdParameters( argc, argv ) )
82  {
83  std::cout << "[DONE]\n";
84 
85  std::cout << "Searching " << prjname << ".top for BC=" << bndrycondition << "...";
86  searchTopFile( );
87  std::cout << "[DONE]\n";
88 
89  std::cout << "Output is saved at " << outputfile << "!\n";
90 
91  }
92  else
93  {
94  std::cout << "[DONE]\n";
95 
96  std::cerr << "Error parsing command line parameters!\n";
97  std::cerr << "File: " << __FILE__ << std::endl;
98  std::cerr << "Line: " << __LINE__ << std::endl;
99 
100  showUsage( );
101 
102  return(-1 );
103  }
104 
105  return( 0 );
106 
107 }
108 
109 //=============================================================================
110 // F U N C T I O N P R O T O T Y P E I M P L E M E N T A T I O N
111 //=============================================================================
112 
114 {
115  std::string dummyline;
116 
117  std::ofstream ofs;
118  ofs.open( outputfile.c_str( ) );
119  if( !ofs.is_open( ) )
120  {
121  std::cerr << "\n Error: Cannot open output file " << outputfile << std::endl;
122  std::cerr << "File: " << __FILE__ << std::endl;
123  std::cerr << "Line: " << __LINE__ << std::endl;
124  }
125 
126  ofs << "0.00E+000\n";
127 
128  std::ifstream ifs;
129  ifs.open( ( prjname+std::string(".top") ).c_str( ) );
130  if( !ifs.is_open( ) )
131  {
132  std::cerr << "\n Error: Cannot open input file " << prjname+std::string(".top") << std::endl;
133  std::cerr << "File: " << __FILE__ << std::endl;
134  std::cerr << "Line: " << __LINE__ << std::endl;
135  }
136 
137  std::getline( ifs, dummyline );
138  std::getline( ifs, dummyline );
139 
140  ifs >> numberOfBlocks;
141  std::getline( ifs, dummyline );
142 
143  for( int i=1; i <= numberOfBlocks; ++i )
144  ofs << i << " 0 0\n";
145 
146  int blockidx,bc,npatches;
147  for( int i=0; i < numberOfBlocks; ++i )
148  {
149  ifs >> blockidx;
150  std::getline( ifs, dummyline );
151  ifs >> npatches;
152  std::getline( ifs, dummyline );
153 
154  for( int j=0; j < npatches; ++j )
155  {
156  ifs >> bc;
157  std::getline( ifs, dummyline );
158  if( bc == bndrycondition )
159  ofs << blockidx << " 0\n";
160  }
161  }
162 
163  ofs.close( );
164  ifs.close( );
165 
166 }
167 
168 //=============================================================================
169 
170 void showUsage( )
171 {
172  std::cout << "plagprep -- generates the initial particle solution dump at t=0\n";
173  std::cout << "OPTIONS:\n";
174  std::cout << "-bc {bc} sets the boundary condition used to identify injection surfaces. Default is 91.\n";
175  std::cout << "-p {projectname} sets the project name, essentially the filename without the suffix.\n";
176  std::cout << "-h prints this help menu.\n";
177  std::cout << "Usage: ./plagprep -p titan_60s_MP\n";
178  std::cout.flush( );
179 }
180 
181 //=============================================================================
182 
183 bool parseCmdParameters( int argc, char **argv )
184 {
185  prjname = "";
186  outputfile = "";
187  numberOfBlocks = 0;
188  bndrycondition = 91;
189 
190  for( int i=1; i < argc; ++i )
191  {
192  if( std::strcmp( argv[ i ], "-bc") == 0 )
193  {
194  bndrycondition = std::atoi( argv[ ++i ] );
195  }
196  else if( std::strcmp( argv[ i ], "-p") == 0 )
197  {
198  prjname = std::string( argv[ ++i ] );
199  outputfile = prjname + std::string( ".sola_0.00000E+00" );
200  }
201  else if( std::strcmp( argv[ i ], "-h") == 0 )
202  {
203  showUsage( );
204  exit( 0 );
205  }
206  }
207 
208  if( prjname == "" )
209  return false;
210 
211  return true;
212 }
213 
214 
int bndrycondition
The boundary condition corresponding to an injecting surface.
Definition: plagprep.C:42
void searchTopFile()
Searches the prjname.top file for injecting boundary conditions.
Definition: plagprep.C:113
std::string outputfile
Output file to write the file.
Definition: hdf2pltV2.C:55
blockLoc i
Definition: read.cpp:79
bool parseCmdParameters(int argc, char **argv)
Parses the user-supplied parameters for this utility.
Definition: plagprep.C:183
void showUsage()
Prints usage and examples to STDOUT.
Definition: hdf2plt.C:785
int numberOfBlocks
Definition: plagprep.C:35
int main(int argc, char *argv[])
Definition: blastest.C:94
j indices j
Definition: Indexing.h:6
std::string prjname
&lt;
Definition: plagprep.C:29