Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. //#include <iostream>
  2. //void read_file_line_by_line(){
  3. // fstream file;
  4. // string line;
  5. // file.open("pbs_output.txt",fstream::in);
  6. // while (getline (file, line))
  7. // cout << line << endl;
  8. // file.close();
  9. //}
  10. #include <iostream>
  11. #include <iomanip>
  12. #include <cstring>
  13. #include <fstream>
  14. #include <sstream>
  15. using namespace std;
  16. int main()
  17. {
  18. string testline;
  19. string store[29];
  20. string node[29][6];
  21. string word[47];
  22. string temp;
  23. int i = 0, j = 0, k = 0, linecount = 0, line = 0, pick = 0, skip = 0;
  24. string cpus[29];
  25. string used[29];
  26. string mem[29][10];
  27. string state[29][9];
  28.  
  29. fstream Test;
  30. Test.open("pbs_output.txt", fstream::in);
  31.  
  32. if (!Test)
  33. {
  34. cout << "There was a problem opening the file. Press any key to close.\n";
  35. getchar();
  36. return 0;
  37. }
  38. //store words in array
  39. while (Test.good())
  40. {
  41. getline(Test, testline);
  42. if (testline != "")
  43. {
  44. word[i] = testline;
  45. i++;
  46.  
  47. }
  48. }
  49. Test.close();
  50. for (int k = 0; k<i; k++)
  51. if (word[k] == "NODE CPUS USED MEM STATE") {
  52. line++;
  53. if (line == 1)//occurence one
  54. {
  55. pick = 1;//line counter
  56. while (pick< 5) //take first five lines of following the first occurence
  57. {
  58. temp = word[k + pick];
  59. store[linecount] = temp;//store each line
  60. linecount++;
  61. pick++;
  62. }
  63. }
  64. else if (line == 2)
  65. {
  66. pick = 1;
  67. while (pick< 10)
  68. {
  69. temp = word[k + pick];
  70. store[linecount] = temp;
  71. linecount++;
  72. pick++;
  73. }
  74. }
  75. else if (line == 3)
  76. {
  77. pick = 1;
  78. while (pick< 11)
  79. {
  80. temp = word[k + pick];
  81. store[linecount] = temp;
  82. linecount++;
  83. pick++;
  84. }
  85. }
  86. else if (line == 4)
  87. {
  88. pick = 1;
  89. while (pick< 7)
  90. {
  91. temp = word[k + pick];
  92. store[linecount] = temp;
  93. linecount++;
  94. pick++;
  95. }
  96. }
  97. }
  98. cout << linecount << endl;
  99. for (j = 0; j < linecount; j++)//for loop to remove whitespaces
  100. {
  101. temp = store[j];
  102. for (i = 0; i<26; i++)
  103. {
  104. if (temp[i] == ' ' || temp[i] == '\t')
  105. {
  106. temp.erase(i, 1);
  107. store[j] = temp;
  108. i--;
  109. }
  110. }
  111. }
  112. for (j = 0; j<linecount; j++)//to store nodes
  113. {
  114. temp = store[j];
  115. for (i = 0; i<6; i++) // storing first six characters from string
  116. {
  117. node[j][i] = temp[i];
  118. }
  119. }
  120. for (j = 0; j<linecount; j++)//to store cpus
  121. {
  122. temp = store[j];
  123. cpus[j] = temp[i];//i starting from where nodes string ended
  124. }
  125. i++;
  126. for (j = 0; j<linecount; j++)//to store used
  127. {
  128. temp = store[j];
  129. used[j] = temp[i];//i starting from where cpus string ended
  130. }
  131. i++;
  132. for (j = 0; j<linecount; j++)//to store memory
  133. {
  134. temp = store[j];
  135. cout << temp << endl;
  136. for (k = 0; k<10; k++)
  137. {
  138. mem[j][k] = temp[i + k];//i starting from where used string ended
  139. }
  140. }
  141. i = i + 10;//incremented to make the next loop start from state
  142. for (j = 0; j<linecount; j++)//to store state
  143. {
  144. temp = store[j];
  145. cout << temp << endl;
  146. for (k = 0; k<9; k++)
  147. {
  148. if (temp[k + i] == 'f')//find f and take until its "free"
  149. {
  150. for (k = 0; k<4; k++)
  151. {
  152. state[j][k] = temp[k + i];
  153. }
  154. for (k = 4; k<9; k++)
  155. {
  156. state[j][k] = '\0';
  157. }
  158. }
  159. else//take the job-busy string
  160. {
  161. state[j][k] = temp[k + i];
  162. }
  163. }
  164. }
  165. for (j = 0; j<linecount; j++)//to output stored states
  166. {
  167. for (i = 0; i<9; i++) {
  168.  
  169. cout << state[j][i];
  170. }
  171. cout << endl;
  172. }
  173. // fstream json;
  174. // json.open("data.json", fstream::in | fstream::out);
  175. // if (!json)
  176. // {
  177. // cout << "There was a problem opening the file. Press any key to close.\n";
  178. // getchar();
  179. // return 0;
  180. // }
  181. // //store words in array while outputting, skipping blank lines
  182. // while (json.good())
  183. // {
  184. // getline(json, testline);
  185. // if (testline != "")
  186. // // {
  187. // // word[i] = testline;
  188. // // i++;
  189. // cout << testline <<endl;
  190. // // }
  191. // }
  192. // json.close();
  193. return 0;
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement