This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparamreader.cpp
114 lines (100 loc) · 3.28 KB
/
paramreader.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
paramreader.cpp
Copyright (c) Michael Strickland
GNU General Public License (GPLv3)
See detailed text in license directory
*/
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <complex>
#include <cstring>
using namespace std;
#include "mpisolve.h"
// this workhorse examines a key to see if it corresponds to a var we are setting
// and then attempts to set the var corresponding to key by converting value to the
// appropriate type. lots of hardcoding here
void setParameter(const char *key, const char *value) {
// integer params
if (strcmp(key,"NUM")==0) NUM=atoi(value);
if (strcmp(key,"STEPS")==0) STEPS=atoi(value);
if (strcmp(key,"UPDATE")==0) UPDATE=atoi(value);
if (strcmp(key,"SNAPUPDATE")==0) SNAPUPDATE=atoi(value);
if (strcmp(key,"POTENTIAL")==0) POTENTIAL=atoi(value);
if (strcmp(key,"INITCONDTYPE")==0) INITCONDTYPE=atoi(value);
if (strcmp(key,"INITSYMMETRY")==0) INITSYMMETRY=atoi(value);
if (strcmp(key,"NF")==0) NF=atoi(value);
if (strcmp(key,"SAVEWAVEFNCS")==0) SAVEWAVEFNCS=atoi(value);
if (strcmp(key,"DUMPSNAPS")==0) DUMPSNAPS=atoi(value);
// double/float params
if (strcmp(key,"A")==0) A=atof(value);
if (strcmp(key,"EPS")==0) EPS=atof(value);
if (strcmp(key,"SIG")==0) SIG=atof(value);
if (strcmp(key,"SIGMA")==0) SIGMA=atof(value);
if (strcmp(key,"MASS")==0) MASS=atof(value);
if (strcmp(key,"T")==0) T=atof(value);
if (strcmp(key,"TC")==0) TC=atof(value);
if (strcmp(key,"XI")==0) XI=atof(value);
if (strcmp(key,"TOLERANCE")==0) TOLERANCE=atof(value);
if (strcmp(key,"eB")==0) eB=atof(value);
if (strcmp(key,"Kx")==0) Kx=atof(value);
if (strcmp(key,"SPINEXP")==0) SPINEXP=atof(value);
return;
}
//
// This routine assumes that paramters are in text file with
// each parameter on a new line in the format
//
// PARAMKEY PARAMVALUE
//
// The PARAMKEY must begin the line and only tabs and spaces
// can appear between the PARAMKEY and PARAMVALUE.
//
// Lines which begin with 'commentmarker' defined below are ignored
//
void readParametersFromFile(char *filename, int echo) {
string commentmarker = "//";
char space = ' ';
char tab = '\t';
int maxline = 128; // maximum line length used in the buffer for reading
char buffer[maxline];
ifstream paramFile(filename);
while(!paramFile.eof()) {
paramFile.getline(buffer,maxline,'\n');
string line = buffer; int length = strlen(buffer);
if (line.substr(0,commentmarker.length())!=commentmarker && line.length()>0) {
char key[64]="",value[64]=""; int founddelim=0;
for (int i=0;i<length;i++) {
if (buffer[i]==space || buffer[i]==tab) founddelim=1;
else {
if (founddelim==0) key[strlen(key)] = buffer[i];
else value[strlen(value)] = buffer[i];
}
}
if (strlen(key)>0 && strlen(value)>0) {
setParameter(key,value);
if (echo) cout << key << " = " << value << endl;
}
}
}
return;
}
//
// Read parameters from commandline
//
void readParametersFromCommandLine(int argc, char** argv, int echo) {
int optind = 1;
while (optind < argc)
{
if (argv[optind][0]=='-') {
string key = argv[optind];
key = key.substr(1,key.length()); // remove '-'
string value = argv[optind+1]; // load value
if (echo) cout << key << " = " << value << endl;
setParameter(key.c_str(),value.c_str());
optind++;
}
optind++;
}
return;
}