77 const char *curvetype[] =
95 const string & label, LineType_en enLineType_) :
99 enLineType(enLineType_)
102 if (vdX.size() != vdY.size())
104 cerr <<
"GNUcurve::GNUcurve number of x and y elements does not match." << endl;
111 cout <<
"Curve label: " <<
clabel << endl;
112 cout <<
"Curve type: " << curvetype[
enLineType] << endl;
113 cout <<
"Curve data points: \n";
115 unsigned int vSize = vdX.size();
116 for(
unsigned int i = 0; i < vSize; ++i)
118 cout << vdX[i] <<
" " << vdY[i] << endl;
134 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__)
135 char filename[L_tmpnam];
137 char filename[] =
"tmpfileXXXXXX";
143 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__)
149 while((wibsl = strchr(filename,bsl)) != 0) {
154 ofstream fileout(filename);
156 fileout <<
"set title \"" <<
title <<
"\"\n";
157 fileout <<
"set xlabel \"" <<
xlabel <<
"\"\n";
158 fileout <<
"set ylabel \"" <<
ylabel <<
"\"\n";
159 fileout <<
"plot \\\n";
161 for(i = 0; i < vCurves.size(); i++) {
162 fileout <<
"\"" << filename <<
"." << i <<
"\" ";
163 fileout <<
"title \"" << vCurves[i]->clabel <<
"\" ";
164 fileout <<
"with " << curvetype[vCurves[i]->enLineType] <<
" ";
165 if( i+1 < vCurves.size()){
173 filedata =
new char[strlen(filename)+3];
177 cerr <<
"Plot2d::gnuplot:: new ran out of memory" << endl;
179 strcpy(filedata,filename);
180 strcat(filedata,
".");
181 strl = strlen(filedata);
183 for(i = 0; i < vCurves.size(); i++)
185 sprintf(&filedata[strl],
"%d",i);
186 ofstream fileout(filedata);
191 unsigned int vSize = vCurves[i]->vdX.size();
192 for (
unsigned int j = 0; j < vSize; ++j)
194 fileout << vCurves[i]->vdX[j] <<
" " << vCurves[i]->vdY[j] << endl;
210 command = popen(GNUPLOT,
"w");
211 fprintf(command,
"load \"%s\"\n",filename); fflush(command);
212 fprintf(stderr,
"Press Enter to continue...\n"); fflush(stderr);
217 for(i = 0; i < vCurves.size(); i++) {
218 sprintf(&filedata[strl],
"%d",i);
231 for(
int j = 1; j <= data.Nrows(); j++)
233 x.push_back(data(j,1));
234 y.push_back(data(j,2));
240 vCurves.push_back(PSHR_Curve(pCurve));
242 catch (bad_alloc & e)
274 cout <<
"gnuplot commands:\n" <<
gnucommand.c_str();
275 cout <<
"Plot title: " <<
title.c_str() <<
"\n";
276 cout <<
"X label: " <<
xlabel.c_str() <<
"\n";
277 cout <<
"Y label: " <<
ylabel.c_str() <<
"\n";
279 for (
unsigned int i = 0; i < vCurves.size(); ++i)
281 cout <<
"\nCurve #" << i <<
"\n";
290 if (xyz.Ncols() != 3*xyz.Nrows())
292 cerr <<
"Plot3d::gnuplot: wrong size of xyz data matrix." << endl;
297 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__)
298 char filename[L_tmpnam];
300 char filename[] =
"tmpfileXXXXXX";
306 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__)
312 while((wibsl = strchr(filename,bsl)) != 0) {
316 ofstream fileout(filename);
317 fileout <<
"set title \"" <<
title <<
"\"\n";
318 fileout <<
"set xlabel \"" <<
xlabel <<
"\"\n";
319 fileout <<
"set ylabel \"" <<
ylabel <<
"\"\n";
320 fileout <<
"set zlabel \"" <<
zlabel <<
"\"\n";
321 fileout <<
"splot \\\n";
322 fileout <<
"\"" << filename <<
"." << 0 <<
"\" ";
323 fileout <<
"title \"" <<
"" <<
"\" ";
324 fileout <<
"with " <<
"linespoints" <<
" ";
329 filedata =
new char[strlen(filename)+3];
333 cerr <<
"Plot3d::gnuplot:: new ran out of memory" << endl;
335 strcpy(filedata,filename);
336 strcat(filedata,
".");
337 strl = strlen(filedata);
339 sprintf(&filedata[strl],
"%d",0);
340 ofstream fileout(filedata);
342 for(
int j = 0; j < 3*xyz.Nrows(); j+=3)
344 fileout << xyz.SubMatrix(1, xyz.Nrows(), j+1, j+3);
345 fileout <<
" " << endl;
348 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__) || defined(__CYGWIN__) || defined(__MINGW32__)
353 if (WinExec(GNUPLOT, SW_SHOWNORMAL) <= 32) {
355 cout <<
"Cannot find the gnuplot application\n";
356 cout <<
"Press Enter to continue" << endl;
364 hwndm = FindWindow((LPSTR) 0, (LPSTR)
"gnuplot");
366 hwnd= GetWindow(hwndm, GW_CHILD);
367 if(hwnd == 0) cout <<
"OUPS!!!\n";
368 sprintf(c,
"load \"%s\" \n",filename);
371 char ccygnus[] =
"cd \"c:\"\n";
376 SendMessage(hwnd,WM_CHAR,*d,1L);
382 SendMessage(hwnd,WM_CHAR,*d,1L);
385 cout <<
"Press Enter to continue..." << endl;
389 command = popen(GNUPLOT,
"w");
390 fprintf(command,
"load \"%s\"\n",filename); fflush(command);
391 fprintf(stderr,
"Press Enter to continue...\n"); fflush(stderr);
397 sprintf(&filedata[strl],
"%d",0);
440 short IO_matrix_file::write(
const vector<Matrix> & data)
443 vector<string> title;
445 for(
unsigned int i = 1; i <= data.size(); i++)
449 title.push_back(tmp);
452 return IO_matrix_file::write(data, title);
456 short IO_matrix_file::write(
const vector<Matrix> & data,
const vector<string> & title)
482 const char *ptr_filename =
filename.c_str();
488 if(stat(ptr_filename, &buf) )
490 ofstream outvecfile(ptr_filename);
495 outvecfile <<
"nb_vector " << data.size() << endl;
496 for(
unsigned int i = 0; i < data.size(); i++)
497 outvecfile <<
"nb_rows " << data[i].Nrows() <<
" "
498 <<
"nb_cols " << data[i].Ncols() <<
" "
500 outvecfile <<
"---------------------------------\n";
504 cerr <<
"IO_matrix_file::write: can not open file " <<
filename.c_str() << endl;
505 return IO_COULD_NOT_OPEN_FILE;
510 ifstream invecfile(ptr_filename, ios::in);
516 ofstream outvecfile(ptr_filename, ios::in | ios::out);
519 outvecfile.seekp(strlen(
"nb_iterations "));
521 outvecfile.seekp(0, std::ios::end);
522 for(
unsigned int i = 0; i < data.size(); i++)
524 for(
int j = 1; j <= data[i].Nrows(); j++) {
525 for(
int k = 1; k <= data[i].Ncols(); k++) {
526 outvecfile << data[i](j,k) <<
" ";
535 cerr <<
"IO_matrix_file::write: can not open file " <<
filename.c_str() << endl;
536 return IO_COULD_NOT_OPEN_FILE;
541 cerr <<
"IO_matrix_file::write: vector data is empty" << endl;
542 return IO_DATA_EMPTY;
549 short IO_matrix_file::read(vector<Matrix> & data)
552 vector<string> data_title;
554 for(
unsigned int i = 1; i <= data.size(); i++)
558 data_title.push_back(tmp);
561 return IO_matrix_file::read(data, data_title);
565 short IO_matrix_file::read(vector<Matrix> & data, vector<string> & data_title)
575 static const char *ptr_filename =
filename.c_str();
576 ifstream invecfile(ptr_filename, ios::in);
583 int nbcol = 0, nbrow = 0;
591 data.push_back(mat_tmp);
592 data_title.push_back(temp);
596 invecfile >> temp >> nbrow;
597 invecfile >> temp >> nbcol;
598 getline(invecfile,data_title[j]);
599 if( (nbrow != data[j].Nrows()) ||
600 (nbcol != data[j].Ncols()) )
601 data[j] = Matrix(nbrow, nbcol);
610 for(
unsigned int ii = 0; ii < data.size(); ii++)
611 for(
int jj = 1; jj <= data[ii].Nrows(); jj++)
612 for(
int kk = 1; kk <= data[ii].Ncols(); kk++)
613 invecfile >> data[ii](jj,kk);
620 cerr <<
"IO_matrix_file::read, can not open file" <<
filename.c_str() << endl;
621 return IO_COULD_NOT_OPEN_FILE;
638 static const char *ptr_filename =
filename.c_str();
639 ifstream invecfile(ptr_filename, ios::in);
644 int nbcol = 0, nbrow = 0;
653 data.push_back(mat_tmp);
654 data_title.push_back(
" ");
659 invecfile >> temp >> nbrow;
660 invecfile >> temp >> nbcol;
662 return IO_MISMATCH_SIZE;
664 getline(invecfile,data_title[j]);
665 if( (nbrow != data[j].Nrows()) ||
666 (nbcol != data[j].Ncols()) )
667 data[j] = Matrix(nbrow, nbcol*nb_iterations_read);
672 for(
unsigned int ii = 0; ii < data.size(); ii++)
673 for(
int jj = 1; jj <= data[ii].Nrows(); jj++)
674 invecfile >> data[ii](jj,k);
678 cerr <<
"IO_matrix_file::read_all, can not open file " <<
filename.c_str() << endl;
679 return IO_COULD_NOT_OPEN_FILE;
699 cerr <<
"Plot_file::Plot_file: problem in reading file " << filename.c_str() <<
"." << endl;
705 const short y,
const short x_start,
const short y_start,
713 cerr <<
"Plot_file::graph: number of rows of xdata and ydata does not match" << endl;
714 return X_Y_DATA_NO_MATCH;
722 for(
int i = y_start; i <= y_end; i++)
725 istr << label << i-y_start+1;
737 cerr <<
"Plot_file::graph: data file buffer is empty." << endl;
738 return PROBLEM_FILE_READING;
744 short set_plot2d(
const char *title_graph,
const char *x_axis_title,
const char *y_axis_title,
745 const char *label, LineType_en enLineType,
const Matrix &xdata,
const Matrix &ydata,
746 int start_y,
int end_y)
753 legend =
new char[strlen(label)+1];
757 cerr <<
"set_plot2d:: new ran out of memory" << endl;
758 return OUT_OF_MEMORY;
761 if(xdata.Ncols() != ydata.Ncols())
763 cerr <<
"set_plot2d:: number of rows of xdata and ydata does not match" << endl;
764 return X_Y_DATA_NO_MATCH;
771 for(
int i = start_y; i <= end_y; i++)
773 snprintf(legend,
sizeof(legend),
"%s%d", label, i-start_y+1);
776 plotgraph.
addcurve((xdata & ydata.SubMatrix(i,i,1,ydata.Ncols())).t(), legend, enLineType);
785 short set_plot2d(
const char *title_graph,
const char *x_axis_title,
const char *y_axis_title,
786 const vector<char *> label, LineType_en enLineType,
const Matrix &xdata,
787 const Matrix &ydata,
const vector<int> & data_select)
795 if(xdata.Ncols() != ydata.Ncols())
797 cerr <<
"set_plot2d:: number of rows of xdata and ydata does not match" << endl;
798 return X_Y_DATA_NO_MATCH;
800 if(data_select.size() != label.size())
802 cerr <<
"set_plot2d:: number of labels does not match" << endl;
803 return LABELS_NBR_NO_MATCH;
806 for(
unsigned int i = 0; i < data_select.size(); i++)
807 plotgraph.
addcurve((xdata & ydata.SubMatrix(data_select[i],data_select[i],
808 1,ydata.Ncols())).t(), label[i], enLineType);
815 short set_plot3d(
const Matrix & xyz,
const string & title_graph,
const string & x_axis_title,
816 const string & y_axis_title,
const string & z_axis_title)