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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
const string ws = " \t"; //going to be used to test input
string filename = "wbbj.top"; //will need to obtain this from elsewhere eventually
const char* filenamechar = filename.c_str();
ifstream inwards; //initialise the opening if the file
inwards.open(filenamechar);
if( !inwards.good() ) //test to see if the file can be opened
{
cerr << "Cannot open the file: \"" << filename+"\"!" << endl;
abort(); //if it can't then print an error and abort
}
//initialise the variables
string line("");
string title_a("");
string title_b("");
string title_c("");
string title_d("");
string left_title("");
string top_title("");
string bottom_title("");
string lower_x_limit("");
string upper_x_limit("");
string scale("");
string limits("");
int new_plot_switch = 0;
int loc_0;
int loc_1;
int loc_2;
int loc_3;
int loc_4;
int loc_5;
int loc_6;
int loc_7;
int loc_8;
int loc_9;
int loc_10;
int loc_11;
int loc_12;
int loc_13;
int title_counter = 0;
int begin_hist = 0;
int end_hist = 0;
while( getline(inwards, line)) { //whilst there are still lines from the file to read
// line=""; //initialise line to be empty
// inwards >> line; //take the line from the file
// cout << "line inputted: " << line << endl; //print the inputted line to the screen
std::string::size_type loc_0 = line.find_first_not_of(ws); // find the first non whitespace element
if(std::string::npos == loc_0) //if the line is empty then just continue
{
continue;
}
else //If the line has text, then erase all whitespace up to that text
{
line.erase(0, loc_0);
}
// Find the location of all the important strings if they're there
loc_1 = line.find( "SCALE", 0 );
loc_2 = line.find( "TITLE", 0 );
loc_3 = line.find( "SET LIMITS", 0);
loc_4 = line.find( "title", 0);
loc_5 = line.find( "BEGIN HIST", 0);
loc_6 = line.find( "END HIST", 0);
loc_7 = line.find( "NEW PLOT", 0);
//test to see if anything interesting has been found
if (std::string::npos != loc_1) //If the line contains the y-axis scale
{
scale = line.substr(12); //extract just the scale used
continue; //Once this line has been identified then we can move on with the next line
}
else if (std::string::npos != loc_2) //If the line contains one of the TITLES
{
loc_8 = line.find( "TOP", 0); //find the location of all the relevant strings
loc_9 = line.find( "BOTTOM", 0);
loc_10 = line.find( "LEFT", 0);
loc_11 = line.find( "SET TITLE", 0);
if (std::string::npos != loc_8) //If the line contains the TITLE TOP
{
top_title = line.substr(10);
continue;
}
else if (std::string::npos != loc_9) //If the line contains the TITLE BOTTOM
{
bottom_title = line.substr(13);
continue;
}
else if (std::string::npos != loc_9) //If the line contains the TITLE LEFT
{
left_title = line.substr(11);
continue;
}
else if (std::string::npos != loc_11) //If the title doesnt contain anything interesting
{
continue;
}
else
{
title_counter++;
if (title_counter == 1)
{
title_a = line.substr(14);
continue;
}
else if (title_counter = 2)
{
title_b = line.substr(14);
continue;
}
else
{
title_c = line.substr(14);
continue;
}
}
}
else if (std::string::npos != loc_3)//If the line contains the limits of the x-axis
{
limits = line.substr(16);
loc_12 = limits.find_last_of(ws);
loc_13 = limits.find_first_of(ws);
line.erase(0, loc_0);
lower_x_limit = limits;
lower_x_limit.erase(loc_13, lower_x_limit.length());
upper_x_limit = limits;
upper_x_limit.erase(0, loc_12+1);
continue;
}
else if (std::string::npos != loc_4) //If the line contains the title
{
title_d = line.substr(23);
continue;
}
else if (std::string::npos != loc_5) //If the line contains the BEGIN HIST marker
{
begin_hist++;
continue;
}
else if (std::string::npos != loc_6) //If the line contains the END HIST marker
{
end_hist++;
continue;
}
else if (std::string::npos != loc_7) //If the line contains the NEW PLOT marker
{
new_plot_switch = 1;
cout << "Histogram Title A: " << title_a << endl;
cout << "Histogram Title B: " << title_b << endl;
cout << "Histogram Title C: " << title_c << endl;
cout << "Histogram Title D: " << title_d << endl;
cout << "Histogram Top Title: " << top_title << endl;
cout << "Histogram Left Title: " << left_title << endl;
cout << "Histogram Bottom Title: " << bottom_title << endl;
cout << "Histogram Scale: " << scale << endl;
cout << "Lower x-axis limit: " << lower_x_limit << endl;
cout << "Upper x-axis limit " << upper_x_limit << endl;
cout << "\n" << endl;
continue;
}
else //Its a line that I dont care about
{
continue;
}
}
return 0;
}
|