Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
read_parameter_file.C File Reference
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include "roccom_c++.h"
#include "Rocin.h"
Include dependency graph for read_parameter_file.C:

Go to the source code of this file.

Functions

void eat_whitespace_until (std::string &str, const char &c, int start=0)
 
void get_parameter_list (std::vector< std::pair< std::string, std::string > > &param_list, const char *file_name)
 

Function Documentation

void eat_whitespace_until ( std::string &  str,
const char &  c,
int  start = 0 
)

Definition at line 149 of file read_parameter_file.C.

References i, and ni.

Referenced by get_parameter_list().

149  {
150  for(int i=start, ni=str.size(); i<ni&&str[i]!=c; ++i){
151  if(str[i] == ' ' || str[i] == '\t'){
152  str.erase(i,1);
153  --i;
154  }
155  }
156 }
blockLoc i
Definition: read.cpp:79
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77

Here is the caller graph for this function:

void get_parameter_list ( std::vector< std::pair< std::string, std::string > > &  param_list,
const char *  file_name 
)

Definition at line 158 of file read_parameter_file.C.

References COM_assertion_msg, eat_whitespace_until(), and cimg_library::cimg::option().

Referenced by Rocin::read_parameter_file().

159  {
160 
161  //open parameter file for input
162  std::ifstream param_file(file_name);
163  COM_assertion_msg(param_file,
164  "Specified parameter file not found.");
165 
166  string cur_line, option, value;
167  string::size_type cur_pos;
168  // get one line of the file at a time
169  while (getline(param_file,cur_line)){
170 
171  cur_pos = cur_line.find('#');
172  if(cur_pos != string::npos)
173  cur_line.erase(cur_pos, cur_line.size()-cur_pos);
174 
175  // remove whitespace up to first '='
176  eat_whitespace_until(cur_line, (char)61);
177 
178  // If the line only contained whitespace and comments,
179  // go to the next line.
180  if(cur_line.size()==0)
181  continue;
182 
183  // Now find the first '='
184  cur_pos = cur_line.find_first_of("=");
185  COM_assertion_msg(cur_pos != string::npos && cur_pos !=0,
186  (std::string("Parameter file '")
187  + file_name + "' has an invalid line.").c_str());
188 
189  option.assign(cur_line,0,cur_pos);
190  value.assign(cur_line,cur_pos+1,string::npos);
191 
192  //eat all whitspace in the value up to the first '"'
193  eat_whitespace_until(value, '"');
194 
195  //if the value has quotes, then make sure they are only at
196  //beginning and ending of the string
197  cur_pos = value.find('"');
198  if(cur_pos != string::npos){
199  COM_assertion_msg(cur_pos == 0,
200  "Parameter file has invalid value format");
201  value.erase(0,1);
202  cur_pos = value.rfind('"');
203  // This should get rid of any whitespace after the last quotation mark
204  eat_whitespace_until(value, '"', (int)cur_pos+1);
205  COM_assertion_msg(cur_pos == value.size()-1,
206  "Parameter file has invalid value format");
207  value.erase(cur_pos,1);
208  COM_assertion_msg(value.find('"') == string::npos,
209  "Parameter file has invalid value format");
210  }
211 
212  // quotations are never allowed in the option
213  cur_pos = option.find_first_of("\"");
214  COM_assertion_msg(cur_pos == string::npos,
215  "Unexpected quotation mark found in an option.");
216 
217  param_list.push_back(std::make_pair(option,value));
218  }
219 
220 }
const char * option(const char *const name, const int argc, const char *const *const argv, const char *defaut, const char *const usage=0)
Definition: CImg.h:5604
#define COM_assertion_msg(EX, msg)
void eat_whitespace_until(std::string &str, const char &c, int start=0)

Here is the call graph for this function:

Here is the caller graph for this function: