Homepage Demos Overview Downloads Tutorials Reference
Credits

gnugraph.cpp

Go to the documentation of this file.
00001 /*
00002 ROBOOP -- A robotics object oriented package in C++
00003 Copyright (C) 1996-2004  Richard Gourdeau
00004 
00005 This library is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU Lesser General Public License as
00007 published by the Free Software Foundation; either version 2.1 of the
00008 License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 
00020 Report problems and direct all questions to:
00021 
00022 Richard Gourdeau
00023 Professeur Agrege
00024 Departement de genie electrique
00025 Ecole Polytechnique de Montreal
00026 C.P. 6079, Succ. Centre-Ville
00027 Montreal, Quebec, H3C 3A7
00028 
00029 email: richard.gourdeau@polymtl.ca
00030 
00031 -------------------------------------------------------------------------------
00032 Revision_history:
00033 
00034 2003/02/03: Etienne Lachance
00035    -Added functions set_plot2d and classe IO_matrix_file.
00036 
00037 2003/29/04: Etienne Lachance
00038    -Class definitions, functions prototype, ... now in gnugraph.h
00039    -Improved class IO_matrix_file.
00040    -Class Plot2d, GNUcurve are now using STL string instead of char*.
00041    -Added class Plot_graph, to create a graph from a data file.
00042    -Replaced all NULL by 0.
00043    -Use mkstemp instead of tmpnam in void Plot2d::gnuplot(void).
00044 
00045 2003/15/08: Etienne Lachance
00046    -The member function IO_matrix_file::write writes data in column of each 
00047     variables, instead of only one. This way it is possible to load a dat file
00048     in Matlab.
00049 
00050 2004/07/01: Etienne Lachance
00051    -Added doxygen documentation.
00052 
00053 2004/07/01: Ethan Tira-Thompson
00054     -Added support for newmat's use_namespace #define, using ROBOOP namespace
00055 -------------------------------------------------------------------------------
00056 */
00057 
00058 /*!
00059   @file gnugraph.cpp
00060   @brief Graphics functions.
00061 */
00062 
00063 #include "gnugraph.h"
00064 
00065 #ifdef use_namespace
00066 namespace ROBOOP {
00067   using namespace NEWMAT;
00068 #endif
00069   //! @brief RCS/CVS version.
00070   static const char rcsid[] __UNUSED__ = "$Id: gnugraph.cpp,v 1.3 2005/07/26 03:22:08 ejt Exp $";
00071 
00072 char *curvetype[] =
00073    {"lines",
00074     "points",
00075     "linespoints",
00076     "impulses",
00077     "dots",
00078     "steps",
00079     "boxes"};
00080 
00081 
00082 GNUcurve::GNUcurve(void)
00083 //!  @brief Constructor.
00084 {
00085    ctype = LINES;
00086    clabel = "";
00087 }
00088 
00089 
00090 GNUcurve::GNUcurve(const Matrix & data, const string & label, int type)
00091 //!  @brief Constructor.
00092 {
00093    xy = data;
00094    if(data.Ncols() > 2) 
00095       cerr << "GNUcurve::Warning: Only the first two columns are used in GNUcurve\n";
00096 
00097    ctype = type;
00098    clabel = label;
00099 }
00100 
00101 
00102 GNUcurve::GNUcurve(const GNUcurve & gnuc)
00103 //!  @brief Copy Constructor.
00104 {
00105    xy = gnuc.xy;
00106    ctype = gnuc.ctype;
00107    clabel = gnuc.clabel;
00108 }
00109 
00110 
00111 GNUcurve & GNUcurve::operator=(const GNUcurve & gnuc)
00112 //!  @brief Overload = operator.
00113 {
00114    xy = gnuc.xy;
00115    ctype = gnuc.ctype;
00116    clabel = gnuc.clabel;
00117 
00118    return *this;
00119 }
00120 
00121 
00122 void GNUcurve::dump(void)
00123 //!  @brief Method to dump the content of a curve to stdout
00124 {
00125    cout << "Curve label: " << clabel.c_str() << "\n";
00126    cout << "Curve type:  " << curvetype[ctype] << "\n";
00127    cout << "Curve data points: \n";
00128    cout << xy;
00129    cout << "\n\n";
00130 }
00131 
00132 
00133 Plot2d::Plot2d(void)
00134 //!  @brief Constructor.
00135 {
00136    ncurves = 0;
00137    try
00138    {
00139       curves = new GNUcurve[NCURVESMAX];
00140    }
00141    catch(bad_alloc ex)
00142    {
00143       cerr << "Plot2d::Plot2d:: new ran out of memory" << endl;
00144    }
00145 
00146 }
00147 
00148 
00149 Plot2d::~Plot2d(void)
00150 //!  @brief  Destructor.
00151 {
00152    delete [] curves;
00153 }
00154 
00155 
00156 void Plot2d::gnuplot(void)
00157 //!  @brief Creates a GNUplot graphic.
00158 {
00159    int i, strl;
00160 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__)
00161    char filename[L_tmpnam];
00162 #else
00163    char filename[] = "tmpfileXXXXXX";
00164 #endif
00165    char * filedata=0;
00166    char * wibsl;
00167    char bsl = '\\';
00168 
00169 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__WATCOMC__)
00170    tmpnam(filename); /* generate a temporary file name */
00171 #else
00172    mkstemp(filename);
00173 #endif
00174    /* replacing \ by / */
00175    while((wibsl = strchr(filename,bsl)) != 0) {
00176       wibsl[0] = '/';
00177    }
00178 
00179    {
00180       ofstream fileout(filename); /* write the command file */
00181       fileout << gnucommand.c_str();
00182       fileout << "set title \"" << title << "\"\n";
00183       fileout << "set xlabel \"" << xlabel << "\"\n";
00184       fileout << "set ylabel \"" << ylabel << "\"\n";
00185       fileout << "plot \\\n";
00186       for(i = 0; i < ncurves; i++) {
00187          fileout << "\"" << filename << "." << i << "\" ";
00188          fileout << "title \"" << curves[i].clabel << "\" ";
00189          fileout << "with " << curvetype[curves[i].ctype] << " ";
00190          if( i+1 < ncurves){
00191             fileout << ", \\\n";
00192          }
00193       }
00194       fileout << "\n";
00195    }
00196    try
00197    {
00198       filedata = new char[strlen(filename)+3];
00199    }
00200    catch(bad_alloc ex)
00201    {
00202       cerr << "Plot2d::gnuplot:: new ran out of memory" << endl;
00203    }
00204    strcpy(filedata,filename);
00205    strcat(filedata,".");
00206    strl = strlen(filedata);
00207    for(i = 0; i < ncurves; i++) { /* write the data files */
00208       sprintf(&filedata[strl],"%d",i);
00209       ofstream fileout(filedata);
00210 #ifndef _MSC_VER // MSVC++ chokes on the next line !
00211       fileout << curves[i].xy;
00212 #else
00213       for(int j = 1; j <= curves[i].xy.Nrows(); j++) {
00214          for(int k = 1; k <= curves[i].xy.Ncols(); k++) {
00215             fileout << curves[i].xy(j,k) << " ";
00216          }
00217          fileout << "\n";
00218       }
00219 #endif
00220    }
00221    /* all command and data files are ready for the call to gnuplot */
00222 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__) || defined(__CYGWIN__)
00223    /* Windows 95/98/NT/2000 etc */
00224    char c[L_tmpnam+15];
00225    char *d;
00226    HWND hwndm, hwnd;
00227    if (WinExec(GNUPLOT, SW_SHOWNORMAL) <= 32) { /* start gnuplot */
00228       /* failed */
00229       cout << "Cannot find the gnuplot application\n";
00230       cout << "Press Enter to continue" << endl;
00231       getchar();
00232       remove(filename); /* clean up the files and return */
00233       for(i = 0; i < ncurves; i++) {
00234          sprintf(&filedata[strl],"%d",i);
00235          remove(filedata);
00236       }
00237       delete filedata;
00238       return;
00239    } else { /* succeed */
00240       /* get gnuplot main window handle */
00241       hwndm = FindWindow((LPSTR) 0, (LPSTR) "gnuplot");
00242    }
00243    hwnd= GetWindow(hwndm, GW_CHILD); /* get gnuplot command area handle */
00244    if(hwnd == 0) cout << "OUPS!!!\n"; /* something wrong happened */
00245    sprintf(c,"load \"%s\" \n",filename); /* load command for the plot */
00246 
00247 #ifdef __GNUG__        /* Cygnus Gnu C++ for win32*/
00248    char ccygnus[] = "cd \"c:\"\n"; /* this string should reflect
00249                                       the drive used to mount / 
00250                                       where /tmp is located */
00251    d = ccygnus;
00252    while(*d != '\0') { /* sending the command through windows messages */
00253       SendMessage(hwnd,WM_CHAR,*d,1L);
00254       d++;
00255    }
00256 #endif
00257    d = c;
00258    while(*d != '\0') { /* sending the command through windows messages */
00259       SendMessage(hwnd,WM_CHAR,*d,1L);
00260       d++;
00261    }
00262    cout << "Press Enter to continue..." << endl;
00263    getchar();
00264 #else      /*  using a pipe under Unix */
00265    FILE *command;
00266 
00267    command = popen(GNUPLOT,"w");
00268    fprintf(command,"load \"%s\"\n",filename); fflush(command);
00269    fprintf(stderr,"Press Enter to continue...\n"); fflush(stderr);
00270    getchar();
00271    pclose(command);
00272 #endif
00273    remove(filename);
00274    for(i = 0; i < ncurves; i++) {
00275       sprintf(&filedata[strl],"%d",i);
00276       remove(filedata);
00277    }
00278    delete filedata;
00279 }
00280 
00281 
00282 void Plot2d::addcurve(const Matrix & data, const string & label, int type)
00283 //!  @brief Add a curve on the graphic.
00284 {
00285    ncurves++;
00286    if(ncurves <= NCURVESMAX) {
00287       curves[ncurves-1] = GNUcurve(data,label,type);
00288    } else {
00289       cout << "Too many curves in your Plot2d (maximum 10)\n";
00290       exit(1);
00291    }
00292 }
00293 
00294 void Plot2d::addcommand(const string & gcom)
00295 //!  @brief Add GNUplot command.
00296 {
00297    gnucommand += gcom;
00298 }
00299 
00300 void Plot2d::settitle(const string & t)
00301 //!  @brief Set the title.
00302 {
00303    title = t;
00304 }
00305 
00306 void Plot2d::setxlabel(const string & t)
00307 //!  @brief Set the x axis name.
00308 {
00309    xlabel = t;
00310 }
00311 
00312 void Plot2d::setylabel(const string & t)
00313 //!  @brief Set the y axis name.
00314 {
00315    ylabel = t;
00316 }
00317 
00318 void Plot2d::dump(void)
00319 //!  @brief Method to dump the content of Plot2d to stdout
00320 {
00321    cout << "gnuplot commands:\n" << gnucommand.c_str();
00322    cout << "Plot title: " << title.c_str() << "\n";
00323    cout << "X label:    " << xlabel.c_str() << "\n";
00324    cout << "Y label:    " << ylabel.c_str() << "\n";
00325    for (int i = 0; i < ncurves; i++) {
00326       cout << "\nCurve #" << i << "\n";
00327       curves[i].dump();
00328    }
00329 }
00330 
00331 
00332 // ---------------------------------------------------------------------------------------
00333 
00334 IO_matrix_file::IO_matrix_file(const string & filename_)
00335 //!  @brief  Constructor.
00336 {
00337    filename = filename_;
00338    position_read = 0;
00339    nb_iterations_write = 0;
00340    nb_iterations_read = 0;
00341    nb_element = 0;
00342 }
00343 
00344 
00345 short IO_matrix_file::write(const vector<Matrix> & data)
00346 //!  @brief Write data on disk using a default data name..
00347 {
00348    vector<string> title;
00349    string tmp;
00350    for(int i = 1; i <= (int)data.size(); i++)
00351    {
00352       tmp = "data#";  // Provide a default name
00353       tmp += i;
00354       title.push_back(tmp);
00355    }
00356 
00357    return IO_matrix_file::write(data, title);
00358 }
00359 
00360 
00361 short IO_matrix_file::write(const vector<Matrix> & data, const vector<string> & title)
00362 /*!
00363   @brief Write data on disk.
00364   @param data: Data.
00365   @param title: Name of each data member (ie: speed, position, ...)
00366 */  
00367 {
00368    /*
00369    If the file "filename" does not exist yet, created it. The first lines of the file
00370    contain the following informations (for each line):
00371       1) the number of iterations.
00372       2) second line is empty.
00373       3) the number(n) of matrix/iteration
00374       4) number of rows and number of columns of Matrix 1.
00375       5)  "                                         "   i.
00376       6)  "                                         "   n.
00377       7)---------------------------------   (end of header file)
00378 
00379    example of header file;
00380    1120
00381        
00382    2
00383    6 1 titre#1
00384    6 1 titre#1
00385    ---------------------------------
00386    */
00387    const char *ptr_filename = filename.c_str(); // transform string to *char
00388    if(data.size())
00389    {
00390       if(!nb_iterations_write)
00391       {
00392          struct stat buf;
00393          if(stat(ptr_filename, &buf) )  // File does not exist
00394          {
00395             ofstream outvecfile(ptr_filename);
00396             if(outvecfile)
00397             {
00398                outvecfile << "nd_iterations " << nb_iterations_write
00399                << "        " << endl;
00400                outvecfile << "nb_vector " << data.size() << endl;
00401                for(int i = 0; i < (int)data.size(); i++)
00402                   outvecfile << "nb_rows " << data[i].Nrows() << "  "
00403                   << "nb_cols " << data[i].Ncols() <<  "  "
00404                   << title[i] << endl;
00405                outvecfile << "---------------------------------\n";
00406             }
00407             else
00408             {
00409                cerr << "IO_matrix_file::write: can not open file " << filename.c_str() << endl;
00410                return IO_COULD_NOT_OPEN_FILE;
00411             }
00412          }
00413          else
00414          {
00415             ifstream invecfile(ptr_filename, ios::in);
00416             if(invecfile)
00417                invecfile >> nb_iterations_write;
00418          }
00419       }
00420 
00421       ofstream outvecfile(ptr_filename, ios::in | ios::out);
00422       if(outvecfile)
00423       {
00424          outvecfile.seekp(strlen("nb_iterations ")); // position at start of fileObject
00425          outvecfile << ++nb_iterations_write << endl;
00426          outvecfile.seekp(0, std::ios::end); // position at end of fileObject
00427          for(int i = 0; i < (int)data.size(); i++)
00428          {
00429             for(int j = 1; j <= data[i].Nrows(); j++) {
00430                for(int k = 1; k <= data[i].Ncols(); k++) {
00431                   outvecfile << data[i](j,k) << " ";
00432                }
00433             }
00434          }
00435          outvecfile << endl;
00436          outvecfile << endl;
00437       }
00438       else
00439       {
00440          cerr << "IO_matrix_file::write: can not open file " << filename.c_str() << endl;
00441          return IO_COULD_NOT_OPEN_FILE;
00442       }
00443    }
00444    else
00445    {
00446       cerr << "IO_matrix_file::write: vector data is empty" << endl;
00447       return IO_DATA_EMPTY;
00448    }
00449 
00450    return 0;
00451 }
00452 
00453 
00454 short IO_matrix_file::read(vector<Matrix> & data)
00455 //! @brief Read one sequence of data per call.
00456 {
00457    vector<string> data_title;
00458    string tmp;
00459    for(int i = 1; i <= (int)data.size(); i++)
00460    {
00461       tmp = "data#";  // Provide a default name
00462       tmp += i;
00463       data_title.push_back(tmp);
00464    }
00465 
00466    return IO_matrix_file::read(data, data_title);
00467 }
00468 
00469 
00470 short IO_matrix_file::read(vector<Matrix> & data, vector<string> & data_title)
00471 //! @brief Read one sequence of data per call.
00472 {
00473    /*
00474    If the file "filename does not exist yet, created it and fill the first line
00475    with the number of rows and columns for each element of "data".
00476    ex: 6x1;3x1;3x3;
00477    This line indidate that data has 3 elements Matrix. The first one has 6 rows and
00478    1 columns, the second one has 3 rows and 1 columns ...
00479    */
00480    static const char *ptr_filename = filename.c_str(); // transform string to *char
00481    ifstream invecfile(ptr_filename, ios::in);
00482 
00483    if(invecfile)
00484    {
00485       if(!position_read)
00486       {
00487 #ifdef __WATCOMC__
00488          char temp[256];
00489 #else
00490          string temp;
00491 #endif
00492          int nbcol = 0, nbrow = 0;
00493          invecfile >> temp >> nb_iterations_read;
00494          invecfile >> temp >> nb_element;
00495          Matrix mat_tmp;
00496          data.clear();
00497          data_title.clear();
00498          for(int i = 1; i <= nb_element; i++)
00499          {
00500             data.push_back(mat_tmp);
00501             data_title.push_back(temp);
00502          }
00503          for(int j = 0; j < nb_element; j++)
00504          {
00505             invecfile >> temp >> nbrow;
00506             invecfile >> temp >> nbcol;
00507 #ifdef __WATCOMC__
00508             invecfile >> temp >> data_title[j];
00509 #else
00510             getline(invecfile,data_title[j]);
00511 #endif
00512             if( (nbrow != data[j].Nrows()) ||
00513                   (nbcol != data[j].Ncols()) )
00514                data[j] = Matrix(nbrow, nbcol);
00515          }
00516          invecfile >> temp;  //------------------------
00517          position_read = invecfile.tellg();
00518       }
00519 
00520       if(position_read > 0)
00521       {
00522          invecfile.seekg(position_read); // position for reading
00523          for(int ii = 0; ii < (int)data.size(); ii++)
00524             for(int jj = 1; jj <= data[ii].Nrows(); jj++)
00525                for(int kk = 1; kk <= data[ii].Ncols(); kk++)
00526                   invecfile >> data[ii](jj,kk);
00527 
00528          position_read = invecfile.tellg(); // position for next reading
00529       }
00530    }
00531    else
00532    {
00533       cerr << "IO_matrix_file::read, can not open file" << filename.c_str() << endl;
00534       return IO_COULD_NOT_OPEN_FILE;
00535    }
00536    return 0;
00537 }
00538 
00539 
00540 short IO_matrix_file::read_all(vector<Matrix> & data, vector<string> & data_title)
00541 /*!
00542   @brief Reads all sequences of data.
00543   
00544    If the file "filename does not exist yet, created it and fill the first line
00545    with the number of rows and columns for each element of "data".
00546    ex: 6x1;3x1;3x3;
00547    This line indidate that data has 3 elements Matrix. The first one has 6 rows and
00548    1 columns, the second one has 3 rows and 1 columns ...
00549 */
00550 {
00551    static const char *ptr_filename = filename.c_str(); // transform string to *char
00552    ifstream invecfile(ptr_filename, ios::in);
00553 
00554    if(invecfile)
00555    {
00556 #ifdef __WATCOMC__
00557       char temp[256];
00558 #else
00559       string temp;
00560 #endif
00561       int nbcol = 0, nbrow = 0;
00562       invecfile >> temp >> nb_iterations_read;
00563       invecfile >> temp >> nb_element;
00564 
00565       Matrix mat_tmp;
00566       data.clear();
00567       data_title.clear();
00568       for(int i = 1; i <= nb_element; i++)
00569       {
00570          data.push_back(mat_tmp);
00571          data_title.push_back(" ");
00572       }
00573 
00574       for(int j = 0; j < nb_element; j++)
00575       {
00576          invecfile >> temp >> nbrow;
00577          invecfile >> temp >> nbcol;
00578          if(nbcol >1)
00579             return IO_MISMATCH_SIZE;
00580 
00581 #ifdef __WATCOMC__
00582          invecfile >> temp >> data_title[j];
00583 #else
00584          getline(invecfile,data_title[j]);
00585 #endif
00586          if( (nbrow != data[j].Nrows()) ||
00587                (nbcol != data[j].Ncols()) )
00588             data[j] = Matrix(nbrow, nbcol*nb_iterations_read);
00589       }
00590       invecfile >> temp;  //---------------------------------
00591 
00592       for(int k = 1; k <= nb_iterations_read; k++)
00593          for(int ii = 0; ii < (int)data.size(); ii++)
00594             for(int jj = 1; jj <= data[ii].Nrows(); jj++)
00595                invecfile >> data[ii](jj,k);
00596    }
00597    else
00598    {
00599       cerr << "IO_matrix_file::read_all, can not open file " << filename.c_str() << endl;
00600       return IO_COULD_NOT_OPEN_FILE;
00601    }
00602    return 0;
00603 }
00604 
00605 // ---------------------------------------------------------------------------------------
00606 
00607 /*!
00608   @fn Plot_file::Plot_file(const string & filename)
00609   @brief Constructor.
00610 
00611   Reads all the data of the file filename.
00612 */
00613 Plot_file::Plot_file(const string & filename) : IO_matrix_file(filename), Plot2d()
00614 {
00615    //clear the buffers in case of error while reading the file
00616    if(read_all(data_from_file, data_title))
00617    {
00618       data_from_file.clear();
00619       data_title.clear();
00620       cerr << "Plot_file::Plot_file: problem in reading file " << filename.c_str() << "." << endl;
00621    }
00622 }
00623 
00624 
00625 short Plot_file::graph(const string & title_graph, const string & label, const short x,
00626                        const short y, const short x_start, const short y_start,
00627                        const short y_end)
00628 //!  @brief Creates a graphic.
00629 {
00630    if(data_from_file.size())
00631    {
00632       if(data_from_file[x].Ncols() != data_from_file[y].Ncols())
00633       {
00634          cerr << "Plot_file::graph: number of rows of xdata and ydata does not match" << endl;
00635          return X_Y_DATA_NO_MATCH;
00636       }
00637 
00638       settitle(title_graph.c_str());
00639       setxlabel(data_title[x]);
00640       setylabel(data_title[y]);
00641 
00642       string legend;
00643       for(int i = y_start; i <= y_end; i++)
00644       {
00645 #ifdef __WATCOMC__
00646          ostrstream istr;
00647          {
00648             char temp[256];
00649             sprintf(temp,"%d",i-y_start+1);
00650             istr << temp;
00651          }
00652 #else
00653          ostringstream istr;
00654          istr << label << i-y_start+1;
00655 #endif
00656          legend = istr.str();
00657 
00658          addcurve((data_from_file[x].SubMatrix(x_start,x_start,1,data_from_file[x].Ncols())
00659                    & data_from_file[y].SubMatrix(i,i,1,data_from_file[y].Ncols())).t(),
00660                   legend, POINTS);
00661       }
00662       gnuplot();
00663       return 0;
00664    }
00665    else
00666    {
00667       cerr << "Plot_file::graph: data file buffer is empty." << endl;
00668       return PROBLEM_FILE_READING;
00669    }
00670 }
00671 
00672 // ---------------------------------------------------------------------------------------------
00673 
00674 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00675                  const char *label, int type, const Matrix &xdata, const Matrix &ydata,
00676                  int start_y, int end_y)
00677 {
00678 
00679    Plot2d plotgraph;
00680    char *legend=0;
00681    try
00682    {
00683       legend = new char[strlen(label)+1];
00684    }
00685    catch(bad_alloc ex)
00686    {
00687       cerr << "set_plot2d:: new ran out of memory" << endl;
00688       return OUT_OF_MEMORY;
00689    }
00690 
00691    if(xdata.Ncols() != ydata.Ncols())
00692    {
00693       cerr << "set_plot2d:: number of rows of xdata and ydata does not match" << endl;
00694       return X_Y_DATA_NO_MATCH;
00695    }
00696 
00697    plotgraph.settitle(title_graph);
00698    plotgraph.setxlabel(x_axis_title);
00699    plotgraph.setylabel(y_axis_title);
00700 
00701    for(int i = start_y; i <= end_y; i++)
00702    {
00703       snprintf(legend, sizeof(legend), "%s%d", label, i-start_y+1);
00704       plotgraph.addcurve((xdata & ydata.SubMatrix(i,i,1,ydata.Ncols())).t(), legend, type);
00705    }
00706    plotgraph.gnuplot();
00707 
00708    delete [] legend;
00709 
00710    return 0;
00711 }
00712 
00713 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00714                  const vector<char *> label, int type, const Matrix &xdata, const Matrix &ydata,
00715                  const vector<int> & data_select)
00716 {
00717    Plot2d plotgraph;
00718 
00719    plotgraph.settitle(title_graph);
00720    plotgraph.setxlabel(x_axis_title);
00721    plotgraph.setylabel(y_axis_title);
00722 
00723    if(xdata.Ncols() != ydata.Ncols())
00724    {
00725       cerr << "set_plot2d:: number of rows of xdata and ydata does not match" << endl;
00726       return X_Y_DATA_NO_MATCH;
00727    }
00728    if(data_select.size() != label.size())
00729    {
00730       cerr << "set_plot2d:: number of labels does not match" << endl;
00731       return LABELS_NBR_NO_MATCH;
00732    }
00733 
00734    for(int i = 0; i < (int)data_select.size(); i++)
00735       plotgraph.addcurve((xdata & ydata.SubMatrix(data_select[i],data_select[i],
00736                           1,ydata.Ncols())).t(), label[i], type);
00737    plotgraph.gnuplot();
00738 
00739    return 0;
00740 }
00741 
00742 #ifdef use_namespace
00743 }
00744 #endif
00745 
00746 
00747 
00748 
00749 
00750 
00751 
00752 
00753 
00754 
00755 
00756 
00757 

ROBOOP v1.21a
Generated Tue Aug 16 16:32:14 2005 by Doxygen 1.4.4