-
Notifications
You must be signed in to change notification settings - Fork 12
/
GetVariables.cxx
73 lines (56 loc) · 1.74 KB
/
GetVariables.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//*************************************************************************
// GetVariables.cxx - Friday, June 13/14
//
// by Ben Davis-Purcell
//
// This class inputs all needed geometry variables from a text file.
//
//
//*************************************************************************
#include "GetVariables.h"
using namespace std;
GetVariables::GetVariables(std::string filename)
{
file = filename;
infile.open(filename.c_str());
if(! infile.is_open()) {
cerr << "Unable to open: " << filename << endl;
exit;
}
}
GetVariables::~GetVariables()
{
/// Destructor
}
int GetVariables::GetInt(std::string variable_int)
{
intvar = variable_int;
infile.seekg(0);
while(!infile.eof()) {
getline(infile,tempstr); /// reads in from infile and puts in tempstr
x = tempstr.find(variable_int); /// gets position of front of var string
if (x!= -1) { /// -1 means string was not found in that line
tempstr.erase(x, x+variable_int.length());
outint = atoi(tempstr.c_str());
return outint;
}
}
cerr<< "Cant find : " << variable_int << "\n";
return -1;
}
double GetVariables::GetDouble(std::string variable_dbl)
{
dblvar = variable_dbl;
infile.seekg(0);
while(!infile.eof()) {
getline(infile,tempstr); /// reads in from infile and puts in tempstr
x = tempstr.find(dblvar); /// gets position of front of var string
if (x!= -1) { /// -1 means string was not found in that line
tempstr.erase(x, x+dblvar.length());
outvar = atof(tempstr.c_str());
return outvar;
}
}
cerr<< "Cant find : " << variable_dbl << "\n";
return -1;
}