11#include < fstream>
22#include < sstream>
33#include < iostream>
4- #include < vector >
4+ #include < deque >
55#include < iterator>
66
77using std::string;
8- using std::vector ;
8+ using std::deque ;
99
1010/* ***************** params.in example ******
1111{ DAKOTA_VARS = 2 }
@@ -47,14 +47,15 @@ int main(int argc, char **argv)
4747 }
4848
4949 //
50- // vectors that will contain strinmgs to search for & their replacement
50+ // deques that will contain strinmgs to search for & their replacement
5151 //
5252
53- vector<string> original;
54- vector<string> replace;
55- vector<int > originalLength;
56- vector<int > replacementLength;
57-
53+ deque<string> original;
54+ deque<string> replace;
55+ deque<int > originalLength;
56+ deque<int > replacementLength;
57+ deque<string> rvNames; // original string of random variable names
58+
5859 //
5960 // from params file, 1) read # of RV and 2) then read RV names and values
6061 //
@@ -63,6 +64,8 @@ int main(int argc, char **argv)
6364 int numRVs = 0 ;
6465 string line;
6566 while (getline (params, line)) {
67+
68+
6669 std::istringstream buf (line);
6770 std::istream_iterator<std::string> beg (buf), end;
6871 vector<std::string> tokens (beg, end); // done!
@@ -75,12 +78,35 @@ int main(int argc, char **argv)
7578 } else {
7679
7780 // subsequent lines contain RV and value .. add to string vectors
78- string rvName = " \" RV. " + tokens.at (1 ) + " \" " ; // add SimCenter delimiters begin="RV. & end="
81+ string rvName = tokens.at (1 ); // add SimCenter delimiters begin="RV. &\ end="
7982 string rvValue = tokens.at (3 );
83+ // check if an existing rvName starts as a substring of current
84+ bool subStringExists = false ;
85+ for (size_t i = 0 ; i < rvNames.size (); ++i) {
86+ const std::string& s1 = rvName[i];
87+ if (rvName.find (s1) == 0 ) {
88+ subStringExists = true ;
89+ break ; // No need to check further if found
90+ }
91+ }
92+ }
93+
94+ if (subStringExists == false ) {
95+ rvNames.push_back (rvName);
96+ rvName = " \" RV." + rvName + " \" " ; // add SimCenter delimiters begin="RV. &\ end="
8097 original.push_back (rvName);
8198 replace.push_back (rvValue);
8299 originalLength.push_back (rvName.length ());
83100 replacementLength.push_back (rvValue.length ());
101+
102+ } else {
103+ rvNames.push_front (rvName);
104+ rvName = " \" RV." + rvName + " \" " ;
105+ replace.push_front (rvValue);
106+ originalLength.push_front (rvName.length ());
107+ replacementLength.push_front (rvValue.length ());
108+
109+ }
84110 // std::cerr << rvName << " " << rvValue << "\n";
85111 }
86112
0 commit comments