📄 gnuplotdriver.cpp
字号:
/* Context : Fuzzy Clustering Algorithms Author : Frank Hoeppner, see also AUTHORS file Description : implementation of class module GnuplotDriver History : Comment : This file was generated automatically. DO NOT EDIT. Copyright : Copyright (C) 1999-2000 Frank Hoeppner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* The University of Applied Sciences Oldenburg/Ostfriesland/Wilhelmshaven hereby disclaims all copyright interests in the program package `fc' (tool package for fuzzy cluster analysis) written by Frank Hoeppner. Prof. Haass, President of Vice, 2000-Mar-10*/#ifndef GnuplotDriver_SOURCE#define GnuplotDriver_SOURCE/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include "GnuplotDriver.hpp"#include <fstream.h>#include <stdlib.h> // system#include <string>#include "TurnIntoPointMap.hpp"#include "Chars.hpp"// data#define GSV_DATA_NONE 0#define GSV_DATA_HAS_ALL 7#define GSV_DATA_HAS_POINTS 1#define GSV_DATA_HAS_LINES 2#define GSV_DATA_Z_NOT_CONSTANT 4// implementationtemplate < class ANALYSIS >GnuplotDriver< ANALYSIS >::GnuplotDriver ( Algorithm<ANALYSIS>* ap_alg ) : mp_succ_alg(ap_alg) { }template < class ANALYSIS >GnuplotDriver< ANALYSIS >::~GnuplotDriver ( ) { FUNCLOG("~GnuplotDriver"); delete mp_succ_alg; }template < class ANALYSIS >voidGnuplotDriver< ANALYSIS >::operator() ( ANALYSIS& a_analysis ) { FUNCLOG("GnuplotDriver"); if (a_analysis.options().empty()) return; // quick exit a_analysis.bbox().enlarge_percent(5.0); typename ANALYSIS::time_map_type::const_iterator i_mesh_map(a_analysis.grid().begin()), i_data_map(a_analysis.data().begin()), i_prot_map(a_analysis.prototypes().begin()); typename ANALYSIS::option_map_type::const_iterator i_option(a_analysis.options().begin()); bool plot_mesh,plot_data,plot_prot,plot_contour,postscript(false); bool legend; bool shared_cosys( (*a_analysis.options().begin()).second.m_constants[5] ); ofstream outfile(".gsv-0.tmp"); #define range2d "["<<a_analysis.bbox().minimum(AXIS_X)<<":"<<a_analysis.bbox().maximum(AXIS_X)<<"] ["\ <<a_analysis.bbox().minimum(AXIS_Y)<<":"<<a_analysis.bbox().maximum(AXIS_Y)<<"]" #define range3d range2d<<" ["<<a_analysis.bbox().minimum(AXIS_Z)<<":"<<a_analysis.bbox().maximum(AXIS_Z)<<"]" outfile << "set key below" << endl << "set ticslevel 0" << endl; for (int time=(int)a_analysis.bbox().minimum(AXIS_T); time<=(int)a_analysis.bbox().maximum(AXIS_T); ++time) { i_mesh_map = a_analysis.grid().find(time); i_data_map = a_analysis.data().find(time); i_prot_map = a_analysis.prototypes().find(time); i_option = a_analysis.options().find(time); plot_mesh = (i_mesh_map!=a_analysis.grid().end()) && (!(*i_mesh_map).second.empty()); plot_data = (i_data_map!=a_analysis.data().end()) && (!(*i_data_map).second.empty()); plot_prot = (i_prot_map!=a_analysis.prototypes().end()) && (!(*i_prot_map).second.empty()); // not necessarily for each time own option structure, therefore: if (i_option==a_analysis.options().end()) i_option = a_analysis.options().begin(); if (m_first_analysis_name.empty()) { m_first_analysis_name = (*i_option).second.analysis_name(); m_first_analysis_name += ".gp.tmp"; } plot_contour = (plot_mesh) && ((*i_option).second.graph_mode()==2); if (plot_mesh || plot_data || plot_prot) { int data_spec(GSV_DATA_NONE), prot_spec(GSV_DATA_NONE), mesh_spec(GSV_DATA_NONE); if (plot_data) data_spec = get_spec((*i_data_map).second); if (plot_prot) prot_spec = get_spec((*i_prot_map).second); if (plot_mesh) mesh_spec = get_spec((*i_mesh_map).second); if ((*i_option).second.postscript()) { if (!postscript) { outfile << "set term postscript default"; if ((*i_option).second.m_constants[3]>0) outfile << " \"Helvetica\" " << (*i_option).second.m_constants[3]; outfile << endl << "set out \"" << (*i_option).second.analysis_name() << ".ps.tmp\"" << endl; postscript = true; } } else { if (postscript) { outfile << "set term x11" << endl; postscript = false; } } if (((*i_option).second.m_constants[0]!=-1) && ((*i_option).second.m_constants[1]!=-1)) { outfile << "set view " << (*i_option).second.m_constants[0] << "," << (*i_option).second.m_constants[1] << endl; } if ((*i_option).second.m_constants[2]!=-1) { outfile << "set size " << (*i_option).second.m_constants[2] << ",1" << endl; } if (plot_mesh) { create_plot((*i_mesh_map).second,true,(*i_option).second.m_constants[6], (*i_option).second.m_constants[7],(*i_option).second.m_constants[8]); } legend = (*i_option).second.m_constants[4]; if (legend) { // in case of 3d graph or 2d with contour lines => write title if (plot_mesh || ((*i_option).second.graph_mode()==3)) { outfile << "set title \"" << (*i_option).second.m_selector[AXIS_Z].get_description() << "\"" << endl; } outfile << "set xlabel \"" << (*i_option).second.m_selector[AXIS_X].get_description() << "\"" << endl; outfile << "set ylabel \"" << (*i_option).second.m_selector[AXIS_Y].get_description() << "\"" << endl; } if ((*i_option).second.graph_mode() == 3) outfile << "s"; outfile << "plot "; if (shared_cosys) if ((*i_option).second.graph_mode() == 2) outfile << range2d; else outfile << range3d; bool sublegend( ((*i_option).second.m_selector[AXIS_X].get_type()==SELECT_ATTR) || ((*i_option).second.m_selector[AXIS_Y].get_type()==SELECT_ATTR) ); bool first(true); // first plot command if (plot_data) { if (IS_TAG(data_spec,GSV_DATA_HAS_LINES)) { first=false; outfile << "'-' " << ((legend&&sublegend)?"title \"line data\"":"notitle") << " with linespoints lt 3 lw 0.5 pt 2 ps 0.5"; } if (IS_TAG(data_spec,GSV_DATA_HAS_POINTS)) { if (!first) outfile << ", "; first=false; outfile << "'-' " << ((legend&&sublegend)?"title \"data\"":"notitle") << " with points pt 2 ps 0.5"; } } if (plot_prot) { if (IS_TAG(prot_spec,GSV_DATA_HAS_LINES)) { if (!first) outfile << ", "; first=false; outfile << "'-' " << ((legend&&sublegend)?"title \"line prototypes\"":"notitle") << " with linespoints lt 1 lw 2 pt 1 ps 2"; } if (IS_TAG(prot_spec,GSV_DATA_HAS_POINTS)) { if (!first) outfile << ", "; first=false; outfile << "'-' " << ((legend&&sublegend)?"title \"prototypes\"":"notitle") << " with points pt 1 ps 2"; } } if ((plot_mesh) && ((*i_option).second.graph_mode()==3)) { Chars<128> title; if (plot_data || plot_prot) outfile << ", "; if (legend) { title = "title \""; title +=(*i_option).second.m_selector[AXIS_Z].get_description(); title += "\""; } else title = "notitle"; outfile << "'-' " << title << " with lines 1"; } if ((plot_contour) && (IS_TAG(mesh_spec,GSV_DATA_Z_NOT_CONSTANT))) { outfile << ", "; outfile.close(); if (legend) system("awk '/^###/ { if ($3>1) printf(\",\"); printf(\"\\\"-\\\" title \\\"%s\\\" with lines %d\",$2,$3) }' < .gsv-3.tmp >> .gsv-0.tmp"); else system("awk '/^###/ { if ($3>1) printf(\",\"); printf(\"\\\"-\\\" notitle with lines %d\",$3) }' < .gsv-3.tmp >> .gsv-0.tmp"); outfile.open(".gsv-0.tmp",ios::app); } outfile << endl; if (plot_data) { if (IS_TAG(data_spec,GSV_DATA_HAS_LINES)) write_inlined_data(outfile,(*i_data_map).second,false,true); if (IS_TAG(data_spec,GSV_DATA_HAS_POINTS)) write_inlined_data(outfile,(*i_data_map).second,false,false); } if (plot_prot) { if (IS_TAG(prot_spec,GSV_DATA_HAS_LINES)) write_inlined_data(outfile,(*i_prot_map).second,false,true); if (IS_TAG(prot_spec,GSV_DATA_HAS_POINTS)) write_inlined_data(outfile,(*i_prot_map).second,false,false); } if ((plot_mesh) && ((*i_option).second.graph_mode()==3)) { /* system("mv .gsv-3.tmp .gsv-x.tmp"); create_plot((*i_mesh_map).second,false); system("cat .gsv-3.tmp >> .gsv-0.tmp"); system("mv .gsv-x.tmp .gsv-3.tmp"); */ write_inlined_data(outfile,(*i_mesh_map).second,true,false); } if ((plot_contour) && (IS_TAG(mesh_spec,GSV_DATA_Z_NOT_CONSTANT))) { outfile.close(); system("cat .gsv-3.tmp >> .gsv-0.tmp"); outfile.open(".gsv-0.tmp",ios::app); } if (!(*i_option).second.postscript()) { outfile << "pause -1" << endl; } } } outfile.close(); string command; command = "mv .gsv-0.tmp "; command += m_first_analysis_name; system(command.c_str()); system("rm -f .gsv-?.tmp"); command = "gnuplot -persist "; command += m_first_analysis_name; system(command.c_str()); }template < class ANALYSIS >voidGnuplotDriver< ANALYSIS >::write_inlined_data ( ofstream& os, const typename ANALYSIS::display_tuple_set_type& a_set, bool a_mesh, // draw mesh, insert new lines with new x-coordinate bool a_delta // draw delta lines ) const { if (!a_set.empty()) { real_type oldx(-1E10),oldy,oldz,dx,dy,dz; typename ANALYSIS::display_tuple_set_type::const_iterator i; for (i=a_set.begin();i!=a_set.end();++i) { if ((oldx != (*i)(AXIS_X)) && (a_mesh)) os << endl; oldx = (*i)(AXIS_X); oldy = (*i)(AXIS_Y); oldz = (*i)(AXIS_Z); dx = (*i)(AXIS_DX); dy = (*i)(AXIS_DY); dz = (*i)(AXIS_DZ); if ((dx!=0) || (dy!=0) || (dz!=0)) // line type { if ((a_delta) && (((*i)(AXIS_I)>0.5) || (a_mesh))) { os << oldx << " " << oldy << " " << oldz << endl << oldx+dx << " " << oldy+dy << " " << oldz+dz << endl << endl; } } else if ((!a_delta) && (((*i)(AXIS_I)>0.5) || (a_mesh))) { os << oldx << " " << oldy << " " << oldz << endl; } } os << "e" << endl; // end of data (gnuplot) } }template < class ANALYSIS >intGnuplotDriver< ANALYSIS >::get_spec ( const typename ANALYSIS::display_tuple_set_type& a_set ) const { real_type dx,dy,dz,z; int spec(GSV_DATA_NONE); typename ANALYSIS::display_tuple_set_type::const_iterator i(a_set.begin()); z=((i==a_set.end())?0:(*i)(AXIS_Z)); while (i!=a_set.end()) { dx = (*i)(AXIS_DX); dy = (*i)(AXIS_DY); dz = (*i)(AXIS_DZ); if ((dx==0) && (dy==0) && (dz==0)) SET_TAG(spec,GSV_DATA_HAS_POINTS); else SET_TAG(spec,GSV_DATA_HAS_LINES); if ((*i)(AXIS_Z)!=z) SET_TAG(spec,GSV_DATA_Z_NOT_CONSTANT); if ((spec&GSV_DATA_HAS_ALL)==GSV_DATA_HAS_ALL) i=a_set.end(); // quick exit else ++i; } return spec; }template < class ANALYSIS >voidGnuplotDriver< ANALYSIS >::create_plot ( const typename ANALYSIS::display_tuple_set_type& a_mesh, bool contour, // true : contour, false : hidden3d real_type start, real_type delta, real_type end ) const { ofstream ctrfile(".gsv-1.tmp"); if (contour) { ctrfile << "set contour base" << endl << "set nosurface"; if ((end>start) && (delta>0)) ctrfile << endl << "set cntrparam levels incremental " << start << ", " << delta << ", " << end; } else ctrfile << "set hidden3d"; ctrfile << endl << "set term table" << endl << "set out \".gsv-2.tmp\"" << endl << "splot '-' with lines" << endl; write_inlined_data(ctrfile,a_mesh,true,false); if (contour) { ctrfile << "! awk '" << "/[-+0-9.]+ [-+0-9.]+ [-+0-9.]+/ " << "{ if ($3!=H) { if (H!=0) { print \"e\" }; " << "H=$3 ; i=i+1; printf(\"### %.2f %d\\n\",H,i); } " << "else print $1, $2, -1 ; } " << "/^$/ { print }; " // blank lines << "/^#/ { print }; " // comments << "END { print \"e\" }" // closing e << "' < .gsv-2.tmp > .gsv-3.tmp" << endl; } else { ctrfile << "! mv .gsv-2.tmp .gsv-3.tmp" << endl; } system("gnuplot .gsv-1.tmp"); }// template instantiationtemplate class GnuplotDriver< PointMap<basic_analysis_type::opt_type,AXIS_END> >;#endif // GnuplotDriver_SOURCE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -