Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <iostream>
- //void read_file_line_by_line(){
- // fstream file;
- // string line;
- // file.open("pbs_output.txt",fstream::in);
- // while (getline (file, line))
- // cout << line << endl;
- // file.close();
- //}
- #include <iostream>
- #include <iomanip>
- #include <cstring>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int main()
- {
- string testline;
- string store[29];
- string node[29][6];
- string word[47];
- string temp;
- int i = 0, j = 0, k = 0, linecount = 0, line = 0, pick = 0, skip = 0;
- string cpus[29];
- string used[29];
- string mem[29][10];
- string state[29][9];
- fstream Test;
- Test.open("pbs_output.txt", fstream::in);
- if (!Test)
- {
- cout << "There was a problem opening the file. Press any key to close.\n";
- getchar();
- return 0;
- }
- //store words in array
- while (Test.good())
- {
- getline(Test, testline);
- if (testline != "")
- {
- word[i] = testline;
- i++;
- }
- }
- Test.close();
- for (int k = 0; k<i; k++)
- if (word[k] == "NODE CPUS USED MEM STATE") {
- line++;
- if (line == 1)//occurence one
- {
- pick = 1;//line counter
- while (pick< 5) //take first five lines of following the first occurence
- {
- temp = word[k + pick];
- store[linecount] = temp;//store each line
- linecount++;
- pick++;
- }
- }
- else if (line == 2)
- {
- pick = 1;
- while (pick< 10)
- {
- temp = word[k + pick];
- store[linecount] = temp;
- linecount++;
- pick++;
- }
- }
- else if (line == 3)
- {
- pick = 1;
- while (pick< 11)
- {
- temp = word[k + pick];
- store[linecount] = temp;
- linecount++;
- pick++;
- }
- }
- else if (line == 4)
- {
- pick = 1;
- while (pick< 7)
- {
- temp = word[k + pick];
- store[linecount] = temp;
- linecount++;
- pick++;
- }
- }
- }
- cout << linecount << endl;
- for (j = 0; j < linecount; j++)//for loop to remove whitespaces
- {
- temp = store[j];
- for (i = 0; i<26; i++)
- {
- if (temp[i] == ' ' || temp[i] == '\t')
- {
- temp.erase(i, 1);
- store[j] = temp;
- i--;
- }
- }
- }
- for (j = 0; j<linecount; j++)//to store nodes
- {
- temp = store[j];
- for (i = 0; i<6; i++) // storing first six characters from string
- {
- node[j][i] = temp[i];
- }
- }
- for (j = 0; j<linecount; j++)//to store cpus
- {
- temp = store[j];
- cpus[j] = temp[i];//i starting from where nodes string ended
- }
- i++;
- for (j = 0; j<linecount; j++)//to store used
- {
- temp = store[j];
- used[j] = temp[i];//i starting from where cpus string ended
- }
- i++;
- for (j = 0; j<linecount; j++)//to store memory
- {
- temp = store[j];
- cout << temp << endl;
- for (k = 0; k<10; k++)
- {
- mem[j][k] = temp[i + k];//i starting from where used string ended
- }
- }
- i = i + 10;//incremented to make the next loop start from state
- for (j = 0; j<linecount; j++)//to store state
- {
- temp = store[j];
- cout << temp << endl;
- for (k = 0; k<9; k++)
- {
- if (temp[k + i] == 'f')//find f and take until its "free"
- {
- for (k = 0; k<4; k++)
- {
- state[j][k] = temp[k + i];
- }
- for (k = 4; k<9; k++)
- {
- state[j][k] = '\0';
- }
- }
- else//take the job-busy string
- {
- state[j][k] = temp[k + i];
- }
- }
- }
- for (j = 0; j<linecount; j++)//to output stored states
- {
- for (i = 0; i<9; i++) {
- cout << state[j][i];
- }
- cout << endl;
- }
- // fstream json;
- // json.open("data.json", fstream::in | fstream::out);
- // if (!json)
- // {
- // cout << "There was a problem opening the file. Press any key to close.\n";
- // getchar();
- // return 0;
- // }
- // //store words in array while outputting, skipping blank lines
- // while (json.good())
- // {
- // getline(json, testline);
- // if (testline != "")
- // // {
- // // word[i] = testline;
- // // i++;
- // cout << testline <<endl;
- // // }
- // }
- // json.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement