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

ROBOOP v1.21a
Generated Tue Oct 19 14:18:25 2004 by Doxygen 1.3.9.1