nukede

Untitled

Jun 19th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.05 KB | None | 0 0
  1. void burnToFile(Queue<TaskMeta> &generated)
  2. {
  3.     std::ofstream output;
  4.     time_t seconds;
  5.     time(&seconds);
  6.     std::stringstream ss;
  7.     ss << seconds;
  8.     std::string ts = ss.str();
  9.     std::string fileName = ts + "-output.tex";
  10.     std::string buffer;
  11.  
  12.  
  13.     output.open(fileName);
  14.     output << beginFile();
  15.  
  16.    
  17.     while (true)
  18.     {
  19.         if (generated.size() > 0)
  20.         {
  21.             TaskMeta taskObject = generated.pop();
  22.            
  23.            
  24.  
  25.             /*
  26.             * Send Matrix A to a file;
  27.             */
  28.             output << "\\section{Issue}\\subsection{Real Input}\n precision = ";
  29.             output << taskObject.precision;
  30.             output << "\\\\";
  31.             output << "$\nMatrixA =\\begin{bmatrix}";
  32.  
  33.             std::vector<std::vector<double>> temp = vecToMatr(taskObject.matrixA);
  34.  
  35.             for (size_t i = 0; i < std::sqrt(taskObject.matrixA.size()); ++i)
  36.             {
  37.                 for (size_t j = 0; j < std::sqrt(taskObject.matrixA.size()); ++j)
  38.                 {
  39.                     output << temp[i][j];
  40.                     output << " & ";
  41.                 }
  42.  
  43.                 output << " \\\\ ";
  44.             }
  45.             /*
  46.             * Send Matrix B to a file
  47.             */
  48.  
  49.             output << "\\end{bmatrix}\n";
  50.             output << "\\\\\nMatrixB =\\begin{bmatrix}";
  51.  
  52.             for (size_t i = 0; i < taskObject.matrixB.size(); ++i)
  53.             {
  54.                 output << taskObject.matrixB[i];
  55.                 output << "\\\\\n";
  56.             }
  57.             output << "\\end{bmatrix}\n $\n";
  58.             /*
  59.             * Write iterations into a file
  60.             */
  61.             if (taskObject.storedIterations.size() > 0)
  62.             {
  63.                 output << "\\subsection{Iterations}\n\\begin{table}[h]\\begin{tabular}{|l|";
  64.                 for (size_t i = 0; i < taskObject.matrixB.size(); ++i)
  65.                     output << "l";
  66.  
  67.                 output << "|}\\hline ";
  68.  
  69.                 for (size_t i = 1; i < taskObject.matrixB.size() + 1; ++i)
  70.                 {
  71.                     output << " & \\multicolumn{1}{l|}{$X_";
  72.                     output << i;
  73.                     output << "$} ";
  74.                 }
  75.  
  76.                 output << "\\\\ \\hline ";
  77.  
  78.                 size_t i = 1;
  79.                 std::vector<double> tempOut;
  80.                 for (std::list<std::vector<double >>::iterator it = taskObject.storedIterations.begin();
  81.                     it != taskObject.storedIterations.end();
  82.                     it++)
  83.                 {
  84.                     tempOut = *it;
  85.                     output << i;
  86.                     output << " & ";
  87.                     ++i;
  88.  
  89.                     for (size_t j = 0; j < tempOut.size(); ++j)
  90.                     {
  91.                         output << tempOut[j];
  92.                         if (j != (tempOut.size() - 1))
  93.                             output << " & ";
  94.                     }
  95.                     output << " \\\\ \\hline ";
  96.                 }
  97.  
  98.                 output << " \\end{tabular}\\end{table} ";
  99.  
  100.                 /*
  101.                 * Print final answer
  102.                 */
  103.  
  104.                 output << "\\subsection{ Result }\n$\nX=\\begin{bmatrix}\n";
  105.                 tempOut = taskObject.storedIterations.back();
  106.                 for (size_t i = 0; i < tempOut.size(); ++i)
  107.                 {
  108.                     output << tempOut[i];
  109.                     output << " \\\\ ";
  110.                 }
  111.  
  112.                 output << "\n\\end{bmatrix}\n$";
  113.  
  114.             }
  115.             else
  116.             {
  117.                 output << "\n\\subsection{Result}\nFAILED!\n";
  118.             }
  119.            
  120.         }
  121.         else
  122.         {
  123.             break;
  124.         }
  125.     }
  126.     output << endOfFile();
  127.     output.close();
  128.  
  129.  
  130.     buffer = "D:\\Dev\\Tools\\texlive\\2014\\bin\\win32\\pdflatex.exe " + fileName;
  131.     char command[1024];
  132.     strncpy_s(command, buffer.c_str(), sizeof(command));
  133.     command[sizeof(command) - 1] = 0;
  134.     system(command);
  135.     strncpy_s(command, fileName.c_str(), sizeof(command));
  136.     command[sizeof(command) - 1] = 0;
  137.     system(command);
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment