DFNgen  2.0
DFN Model Generator
readInputFunctions.cpp
Go to the documentation of this file.
1 #include "readInputFunctions.h"
2 #include <cstdlib>
3 #include <chrono>
4 #include <fstream>
5 #include <string>
6 
7 
8 /*******************************************************************/
9 /*******************************************************************/
14 void searchVar(std::ifstream &stream, std::string search){
15  std::string word;
16  stream.clear(); // Reset file pointer in case of eof encountered
17  // Reset file position pointer to beginning, allows access to variables in any order
18  stream.seekg(0);
19  while (stream >> word) {
20  if (word == search) {
21  break;
22  }
23  }
24  if ((int) stream.tellg() == -1){
25  std::cout<< "Variable not found: \""<< search << "\"\n";
26  exit(1);
27  }
28 }
29 
30 /*******************************************************************/
31 /*******************************************************************/
35 void checkIfOpen(std::ifstream &stream, std::string fileName){
36  if (!stream.is_open()){
37  std::cout<< "ERROR: unable to open file "<< fileName << std::endl;
38  exit(1);
39  }
40 }
41 
42 void checkIfOpen(std::ofstream &stream, std::string fileName){
43  if (!stream.is_open()){
44  std::cout<< "ERROR: unable to open file "<< fileName << std::endl;
45  exit(1);
46  }
47 }
48 
49 /**********************************************************************/
50 /**********************************************************************/
56 void getRectCoords(std::ifstream &stream, double *var, int nRectangles){
57  int i;
58  char ch;
59  for (i = 0; i < nRectangles; i++) {
60  int x = i*12;
61  stream >> ch >> var[x] >> ch >> var[x+1] >> ch >> var[x+2] >> ch
62  >> ch >> var[x+3] >> ch >> var[x+4] >> ch >> var[x+5] >> ch
63  >> ch >> var[x+6] >> ch >> var[x+7] >> ch >> var[x+8] >> ch
64  >> ch >> var[x+9] >> ch >> var[x+10] >> ch >> var[x+11] >> ch;
65  }
66 }
67 
68 
69 /**********************************************************************/
70 /**********************************************************************/
77 void getCords(std::ifstream & stream, double *outAry, int nPoly, int nVertices) {
78 
79  char ch;
80  int size = nPoly * nVertices;
81 
82  for (int i = 0; i < size; i++) {
83  int x = i * 3;
84  stream >> ch >> outAry[x] >> ch >> outAry[x+1] >> ch >> outAry[x+2] >> ch;
85  }
86 }
87 
88 
89 /*******************************************************************/
90 /*******************************************************************/
95 void printRectCoords(double *var, std::string varName, int nRectangles){
96  int i;
97  std::cout << varName << ": \n";
98  for (i = 0; i<nRectangles; i++) {
99  int x = i*12;
100  std::cout << "{" << var[x] << "," << var[x+1] << "," << var[x+2] << "} "
101  << "{" << var[x+3] << "," << var[x+4] << "," << var[x+5] << "} "
102  << "{" << var[x+6] << "," << var[x+7] << "," << var[x+8] << "} "
103  << "{" << var[x+9] << "," << var[x+10] << "," << var[x+11] << "}\n";
104  }
105 }
106 
107 
108 /*******************************************************************/
109 /*******************************************************************/
112 unsigned int getTimeBasedSeed() {
113  return std::chrono::system_clock::now().time_since_epoch().count();
114 }
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
unsigned int nPoly
Definition: readInput.cpp:15
void getRectCoords(std::ifstream &stream, double *var, int nRectangles)
void searchVar(std::ifstream &stream, std::string search)
void printRectCoords(double *var, std::string varName, int nRectangles)
void getCords(std::ifstream &stream, double *outAry, int nPoly, int nVertices)
unsigned int getTimeBasedSeed()
void checkIfOpen(std::ifstream &stream, std::string fileName)