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

ROBOOP v1.21a
Generated Thu Nov 22 00:51:28 2007 by Doxygen 1.5.4