#include <gnuplot.h>
Public Member Functions | |
GnuPlot () | |
~GnuPlot () | |
string | getDataFileName () |
std::string | newDataFile (std::ofstream &fout) |
void | plot (std::string expr, std::string name="", std::string comp="") |
void | splot (std::string expr, std::string name="", std::string comp="") |
void | setIntervalX (double minX, double maxX) |
void | setInterval (double minX, double maxX, double minY=0, double maxY=0) |
void | Draw () |
void | runSystemCommand (const char *) |
std::string | plotPoints (double X[], int lines, int cols, std::string name="", std::string comp="", std::string with="", int bRowOrder=0, int bTrans=0, int blockSize=2147483640) |
std::string | plotPoints3d (double X[], int lines, int cols, std::string name="", std::string comp="", std::string with="", int bRowOrder=0, int bTrans=0, int blockSize=2147483640) |
void | plotPoints (std::string strFileName, std::string name="", std::string comp="") |
void | plotPoints (std::string strFileName, std::string name, int index1, int index2, int col1, int col2, std::string comp="") |
void | plotPoints3d (std::string strFileName, std::string name="", std::string comp="") |
void | pause (double dSec, std::string str_comment="") |
void | NextScene () |
void | NextPlot () |
void | xRange (double a, double b) |
void | yRange (double a, double b) |
void | zRange (double a, double b) |
void | define (std::string var, std::string expr) |
void | define (std::string var, double num) |
void | set (std::string var, std::string value) |
void | set (std::string var, int value) |
void | unset (std::string var) |
void | setOutput (std::string strOutput) |
void | setTitle (std::string strTitle) |
void | setArg (std::string strArg) |
void | setFont (string font) |
void | setOutputEpsMono (std::string strOutput) |
void | finalize () |
void | leaveFiles (int bLeave) |
Protected Attributes | |
int | m_bPlot |
int | m_bLeave |
int | m_bPlot3D |
std::string | m_arg |
string | m_dir |
double | m_MinX |
double | m_MaxX |
double | m_MaxY |
double | m_MinY |
FILE * | m_file |
std::vector< std::string > | m_List |
Private Attributes | |
string | m_font |
Static Private Attributes | |
static int | m_count = 0 |
Definition at line 11 of file gnuplot.h.
GnuPlot::GnuPlot | ( | ) |
Definition at line 13 of file gnuplot.cpp.
00015 { 00016 m_font = ""; 00017 char aux[100]; 00018 m_dir = "./GnuPlot"; 00019 string tmp = m_dir; 00020 tmp+="/TMP_00001"; 00021 00022 00023 //sprintf(aux,"mkdir %s ",m_dir.c_str()); 00024 //runSystemCommand(aux); 00025 sprintf(aux,"rm %s/TMP* %s/DAT* ",m_dir.c_str(),m_dir.c_str()); 00026 runSystemCommand(aux); 00027 00028 00029 m_MinX = m_MinY = -10; 00030 m_MaxX = m_MinY = 10; 00031 m_file = fopen(tmp.c_str(),"wr"); 00032 if (m_file == NULL) { 00033 throw new Exception("GnupPlot: Arquivo temporario %s nao pode ser criado.... Exiting",tmp.c_str()); 00034 00035 } 00036 m_List.push_back(tmp); 00037 m_bPlot = false; 00038 m_bPlot3D = false; 00039 m_bLeave = true; 00040 00041 }
GnuPlot::~GnuPlot | ( | ) |
Definition at line 44 of file gnuplot.cpp.
void GnuPlot::define | ( | std::string | var, | |
double | num | |||
) |
void GnuPlot::define | ( | std::string | var, | |
std::string | expr | |||
) |
void GnuPlot::Draw | ( | ) |
Reimplemented in GnuPlotAnim.
Definition at line 404 of file gnuplot.cpp.
00405 { 00406 int result; 00407 m_bPlot = false; 00408 00409 fclose(m_file); 00410 00411 string str("gnuplot -background white "); 00412 str+=m_arg; 00413 str+= m_List.front(); 00414 result=system(str.c_str()); 00415 00416 if (result!=0){ 00417 cout << "Erro no Script.\nImprimindo:\n"; 00418 string str("cat < "); 00419 str+= m_List.front(); 00420 result=system(str.c_str()); 00421 } 00422 else 00423 { 00424 cout << "GnuPlot Sucessful :-) " << endl; 00425 } 00426 if (!m_bLeave) 00427 runSystemCommand("rm TMP_* DAT_* "); 00428 00429 };
void GnuPlot::finalize | ( | ) |
Objetivo: Finalizar o programa pelo mal uso do gnuplot
Parametros: Nenhum
Retorno:
Definition at line 616 of file gnuplot.cpp.
00617 { 00618 std::for_each(m_List.begin(),m_List.end(),RemoveFiles()); 00619 exit(1); 00620 }
string GnuPlot::getDataFileName | ( | ) |
void GnuPlot::leaveFiles | ( | int | bLeave | ) |
Definition at line 623 of file gnuplot.cpp.
00624 { 00625 m_bLeave = bLeave; 00626 }
std::string GnuPlot::newDataFile | ( | std::ofstream & | fout | ) |
Definition at line 676 of file gnuplot.cpp.
00677 { 00678 std::string str = getDataFileName(); 00679 m_List.push_back(str); 00680 fout.open(str.c_str()); 00681 return str; 00682 }
void GnuPlot::NextPlot | ( | ) |
void GnuPlot::NextScene | ( | ) |
Reimplemented in GnuPlotAnim.
Definition at line 534 of file gnuplot.cpp.
void GnuPlot::pause | ( | double | dSec, | |
std::string | str_comment = "" | |||
) |
void GnuPlot::plot | ( | std::string | expr, | |
std::string | name = "" , |
|||
std::string | comp = "" | |||
) |
Definition at line 49 of file gnuplot.cpp.
00049 { 00050 if (m_bPlot3D) 00051 { 00052 cerr << "Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00053 this->finalize(); 00054 } 00055 00056 00057 if (!m_bPlot){ 00058 fprintf(m_file,"plot %s title \"%s\" %s",expr.c_str(),name.c_str(),comp.c_str()); 00059 m_bPlot = true; 00060 } 00061 else{ 00062 fprintf(m_file,", %s title \"%s\" %s",expr.c_str(),name.c_str(),comp.c_str()); 00063 } 00064 }
void GnuPlot::plotPoints | ( | std::string | strFileName, | |
std::string | name, | |||
int | index1, | |||
int | index2, | |||
int | col1, | |||
int | col2, | |||
std::string | comp = "" | |||
) |
Funcao plotPoints Plota pontos. Parametros: strFileName = Nome do arquivo contendo os pontos. name = titulo do programa comp = Complemento informando como se plotar index1 = Início do primeiro record index2 = Fim do primeiro record col1 = coluna sendo usada col2 = coluna sendo usada
Definition at line 336 of file gnuplot.cpp.
00337 { 00338 if (m_bPlot3D) 00339 { 00340 cerr << "Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00341 this->finalize(); 00342 } 00343 00344 00345 if (!m_bPlot) { 00346 fprintf(m_file,"plot \"%s\" index %d:%d using %d:%d %s title \"%s\" ",strFileName.c_str(),index1,index2,col1,col2,comp.c_str(),name.c_str()); 00347 m_bPlot = true; 00348 } 00349 else { 00350 fprintf(m_file,", \"%s\" index %d:%d using %d:%d %s title \"%s\" ",strFileName.c_str(),index1,index2,col1,col2,comp.c_str(),name.c_str()); 00351 } 00352 return; 00353 }
void GnuPlot::plotPoints | ( | std::string | strFileName, | |
std::string | name = "" , |
|||
std::string | comp = "" | |||
) |
Funcao plotPoints Plota pontos. Parametros: strFileName = Nome do arquivo contendo os pontos. name = titulo do programa comp = Complemento informando como se plotar
Definition at line 306 of file gnuplot.cpp.
00307 { 00308 if (m_bPlot3D) 00309 { 00310 cerr << "Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00311 this->finalize(); 00312 } 00313 00314 if (!m_bPlot) { 00315 fprintf(m_file,"plot \"%s\" title \"%s\" %s ",strFileName.c_str(),name.c_str(),comp.c_str()); 00316 m_bPlot = true; 00317 } 00318 else { 00319 fprintf(m_file,", \"%s\" title \"%s\" %s",strFileName.c_str(),name.c_str(),comp.c_str()); 00320 } 00321 return; 00322 }
std::string GnuPlot::plotPoints | ( | double | X[], | |
int | lines, | |||
int | cols, | |||
std::string | name = "" , |
|||
std::string | comp = "" , |
|||
std::string | with = "" , |
|||
int | bRowOrder = 0 , |
|||
int | bTrans = 0 , |
|||
int | blockSize = 2147483640 | |||
) |
Funcao plotPoints Plota pontos. Parametros: X = Matriz de pontos, colocadas num vetor na ordem de linhas cols = Numero de colunas lines = Numero de linhas. name = titulo do programa comp = Complemento informando como se plotar blockSize = Imprimir em blocos de blockSize linhas cada bRowOrder = Se a matriz e orientada por linhas ou colunas Retorno: Nome do arquivo criado
Definition at line 119 of file gnuplot.cpp.
00120 { 00121 if (lines ==0 || cols ==0) 00122 return ""; 00123 00124 int i,j,iEnd,jEnd,iInc,jInc; 00125 int blCount=0; 00126 string strName = getDataFileName(); 00127 FILE* fDat = fopen(strName.c_str(),"wr"); 00128 m_List.push_back(strName); 00129 00130 if (m_bPlot3D) 00131 { 00132 cerr << "Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00133 this->finalize(); 00134 } 00135 00136 if (!bRowOrder) { 00137 if (bTrans) 00138 { 00139 iEnd = lines*cols; 00140 iInc = lines; 00141 jEnd = lines; 00142 jInc = 1; 00143 } 00144 else 00145 { 00146 iEnd = lines; 00147 iInc = 1; 00148 jEnd = lines*cols; 00149 jInc = lines; 00150 } 00151 } 00152 else { 00153 if (bTrans) 00154 { 00155 iEnd = cols; 00156 iInc = 1; 00157 jEnd = cols*lines; 00158 jInc = cols; 00159 } 00160 else 00161 { 00162 iEnd = lines*cols; 00163 iInc = cols; 00164 jEnd = cols; 00165 jInc = 1; 00166 } 00167 } 00168 for (i=0;i<iEnd;i+=iInc) 00169 { 00170 for (j=0;j<jEnd;j+=jInc) 00171 { 00172 fprintf(fDat,"%lf \t",X[i+j]); 00173 } 00174 00175 fprintf(fDat,"\n"); 00176 if (++blCount == blockSize) 00177 { 00178 fprintf(fDat,"\n"); 00179 blCount=0; 00180 } 00181 } 00182 00183 fclose(fDat); 00184 00185 if (!m_bPlot) { 00186 if (!with.empty()) 00187 fprintf(m_file,"plot \"%s\" %s title \"%s\" %s",strName.c_str(),comp.c_str(),name.c_str(),with.c_str()); 00188 else 00189 fprintf(m_file,"plot \"%s\" %s title \"%s\"",strName.c_str(),comp.c_str(),name.c_str()); 00190 m_bPlot = true; 00191 } 00192 else { 00193 if (with.empty()) 00194 fprintf(m_file,", \"%s\" %s title \"%s\"",strName.c_str(),comp.c_str(),name.c_str()); 00195 else 00196 fprintf(m_file,", \"%s\" %s title \"%s\" %s",strName.c_str(),comp.c_str(),name.c_str(),with.c_str()); 00197 } 00198 return m_List.back(); 00199 };
void GnuPlot::plotPoints3d | ( | std::string | strFileName, | |
std::string | name = "" , |
|||
std::string | comp = "" | |||
) |
Funcao plotPoints3d Plota pontos. Parametros: strFileName = Nome do arquivo contendo os pontos. name = titulo do programa comp = Complemento informando como se plotar
Definition at line 367 of file gnuplot.cpp.
00368 { 00369 if (m_bPlot) 00370 { 00371 cerr << "Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00372 this->finalize(); 00373 } 00374 00375 if (!m_bPlot3D) { 00376 fprintf(m_file,"splot \"%s\" %s title \"%s\" ",strFileName.c_str(),comp.c_str(),name.c_str()); 00377 m_bPlot3D = true; 00378 } 00379 else { 00380 fprintf(m_file,", \"%s\" %s title \"%s\"",strFileName.c_str(),comp.c_str(),name.c_str()); 00381 } 00382 return; 00383 }
std::string GnuPlot::plotPoints3d | ( | double | X[], | |
int | lines, | |||
int | cols, | |||
std::string | name = "" , |
|||
std::string | comp = "" , |
|||
std::string | with = "" , |
|||
int | bRowOrder = 0 , |
|||
int | bTrans = 0 , |
|||
int | blockSize = 2147483640 | |||
) |
Funcao plotPoints3D Plota pontos em 3 Dimensoes. Parametros: X = Matriz de pontos, colocadas num vetor na ordem de linhas cols = Numero de colunas lines = Numero de linhas. name = titulo do programa comp = Complemento informando como se plotar with = With clause bRowOrder = Se a matriz e orientada por linhas ou colunas btrans = Transpor matriz blockSize = Imprimir em blocos de blockSize linhas cada Pre: Ser impresso um arquivo de pelo menos 3 colunas
Definition at line 217 of file gnuplot.cpp.
00218 { 00219 int i,j,iEnd,jEnd,iInc,jInc; 00220 int blCount=0; 00221 string strName = getDataFileName(); 00222 FILE* fDat = fopen(strName.c_str(),"wr"); 00223 m_List.push_back(strName); 00224 00225 if (!bRowOrder) { 00226 if (bTrans) 00227 { 00228 iEnd = lines*cols; 00229 iInc = lines; 00230 jEnd = lines; 00231 jInc = 1; 00232 } 00233 else 00234 { 00235 iEnd = lines; 00236 iInc = 1; 00237 jEnd = lines*cols; 00238 jInc = lines; 00239 } 00240 } 00241 else { 00242 if (bTrans) 00243 { 00244 iEnd = cols; 00245 iInc = 1; 00246 jEnd = cols*lines; 00247 jInc = cols; 00248 } 00249 else 00250 { 00251 iEnd = lines*cols; 00252 iInc = cols; 00253 jEnd = cols; 00254 jInc = 1; 00255 } 00256 } 00257 for (i=0;i<iEnd;i+=iInc) 00258 { 00259 for (j=0;j<jEnd;j+=jInc) 00260 { 00261 fprintf(fDat,"%lf \t",X[i+j]); 00262 } 00263 00264 fprintf(fDat,"\n"); 00265 if (++blCount == blockSize) 00266 { 00267 fprintf(fDat,"\n\n"); 00268 blCount=0; 00269 } 00270 } 00271 00272 fclose(fDat); 00273 if (m_bPlot) 00274 { 00275 std::cerr << "Nao se pode misturar graficos 2D com graficos 3D\n"; 00276 this->finalize(); 00277 } 00278 00279 if (!m_bPlot3D) { 00280 if (!with.empty()) 00281 fprintf(m_file,"splot \"%s\" %s title \"%s\" with %s",strName.c_str(),comp.c_str(),name.c_str(),with.c_str()); 00282 else 00283 fprintf(m_file,"splot \"%s\" %s title \"%s\"",strName.c_str(),comp.c_str(),name.c_str()); 00284 m_bPlot3D = true; 00285 } 00286 else { 00287 if (with.empty()) 00288 fprintf(m_file,", \"%s\" %s title \"%s\"",strName.c_str(),comp.c_str(),name.c_str()); 00289 else 00290 fprintf(m_file,", \"%s\" %s title \"%s\" with %s",strName.c_str(),comp.c_str(),name.c_str(),with.c_str()); 00291 } 00292 return m_List.back(); 00293 00294 00295 }
void GnuPlot::runSystemCommand | ( | const char * | aux | ) |
Definition at line 688 of file gnuplot.cpp.
void GnuPlot::set | ( | std::string | var, | |
int | value | |||
) |
void GnuPlot::set | ( | std::string | var, | |
std::string | value | |||
) |
set: Configura determinada variavel usando o comando set
Argumentos: var = Variavel a ser configurada value = Valor a ser atribuido a variavel
Definition at line 481 of file gnuplot.cpp.
void GnuPlot::setArg | ( | std::string | strArg | ) |
Definition at line 585 of file gnuplot.cpp.
00586 { 00587 m_arg = strArg; 00588 }
void GnuPlot::setFont | ( | string | font | ) |
Objetivo:
Parametros:
Retorno:
Definition at line 671 of file gnuplot.cpp.
00672 { 00673 m_font = font; 00674 }
void GnuPlot::setInterval | ( | double | minX, | |
double | maxX, | |||
double | minY = 0 , |
|||
double | maxY = 0 | |||
) |
Definition at line 88 of file gnuplot.cpp.
00088 { 00089 if (m_bPlot||m_bPlot3D) 00090 { 00091 cerr << "Erro, funcao ja definida, nao se pode modificar o intervalo.\n"; 00092 this->finalize(); 00093 } 00094 else { 00095 00096 m_MinX = minX; 00097 m_MaxX = maxX; 00098 m_MaxY = maxY; 00099 m_MinY = minY; 00100 fprintf(m_file,"set yrange [%lf:%lf];\n",m_MinY,m_MaxY); 00101 fprintf(m_file,"set xrange [%lf:%lf];\n",m_MinX,m_MaxX); 00102 } 00103 };
void GnuPlot::setIntervalX | ( | double | minX, | |
double | maxX | |||
) |
Definition at line 591 of file gnuplot.cpp.
00592 { 00593 if (m_bPlot || m_bPlot3D) 00594 { 00595 cerr << "Erro, funcao ja definida, nao se pode modificar o intervalo.\n"; 00596 this->finalize(); 00597 00598 } 00599 else { 00600 00601 m_MinX = minX; 00602 m_MaxX = maxX; 00603 fprintf(m_file,"set xrange [%lf:%lf];\n",m_MinX,m_MaxX); 00604 } 00605 00606 }
void GnuPlot::setOutput | ( | std::string | strOutput | ) |
void GnuPlot::setOutputEpsMono | ( | std::string | strOutput | ) |
Configura saida para eps preto e branco Argumentos: strOutput Nome do arquivo
Definition at line 524 of file gnuplot.cpp.
void GnuPlot::setTitle | ( | std::string | strTitle | ) |
Definition at line 567 of file gnuplot.cpp.
00567 { 00568 if (m_bPlot || m_bPlot3D) 00569 { 00570 cerr << "(GnuPlot::setTitle) Feche o grafico primeiro com a funcao NextScreen"; 00571 this->finalize(); 00572 } 00573 if (m_font.empty()) 00574 { 00575 fprintf(m_file,"set title \"%s\";\n",strTitle.c_str()); 00576 } 00577 else //Configure o tipo da fonte. 00578 { 00579 fprintf(m_file,"set title \"%s\" font \"%s\";\n",strTitle.c_str(),m_font.c_str()); 00580 } 00581 }
void GnuPlot::splot | ( | std::string | expr, | |
std::string | name = "" , |
|||
std::string | comp = "" | |||
) |
Objetivo: Imprimir uma superficie dado uma expressao.
Definition at line 70 of file gnuplot.cpp.
00071 { 00072 if (m_bPlot) 00073 { 00074 cerr << "splot:: Graficos 2D e 3D na mesma cena nao pode ser feito\n"; 00075 this->finalize(); 00076 } 00077 if (!m_bPlot3D){ 00078 fprintf(m_file,"splot %s title \"%s\" %s",expr.c_str(),name.c_str(),comp.c_str()); 00079 m_bPlot3D = true; 00080 } 00081 else{ 00082 fprintf(m_file,", %s title \"%s\" %s",expr.c_str(),name.c_str(),comp.c_str()); 00083 } 00084 }
void GnuPlot::unset | ( | std::string | var | ) |
void GnuPlot::xRange | ( | double | a, | |
double | b | |||
) |
void GnuPlot::yRange | ( | double | a, | |
double | b | |||
) |
void GnuPlot::zRange | ( | double | a, | |
double | b | |||
) |
std::string GnuPlot::m_arg [protected] |
int GnuPlot::m_bLeave [protected] |
int GnuPlot::m_bPlot [protected] |
int GnuPlot::m_bPlot3D [protected] |
int GnuPlot::m_count = 0 [static, private] |
string GnuPlot::m_dir [protected] |
FILE* GnuPlot::m_file [protected] |
string GnuPlot::m_font [private] |
std::vector<std::string> GnuPlot::m_List [protected] |
double GnuPlot::m_MaxX [protected] |
double GnuPlot::m_MaxY [protected] |
double GnuPlot::m_MinX [protected] |
double GnuPlot::m_MinY [protected] |