diff --git a/pub/lib/dualplot.cpp b/pub/lib/dualplot.cpp index 16ad5342dfb606480050f01a4c78eee82aca89c9..8393137cb7b766e933f769b14facc3d638f04d4c 100644 --- a/pub/lib/dualplot.cpp +++ b/pub/lib/dualplot.cpp @@ -40,6 +40,13 @@ CPlot::CPlot( int _iPlot, bool _logx, bool _logy ) : if (mkfifo( fn_fifo.c_str(), 0666 )) throw "SYSTEM ERROR cannot make fifo "+fn_fifo+": will not be able to print"; + // Check that Gnuplot supports X11. + string out = triv::system_read( "gnuplot -e 'help X11' 2>&1 < /dev/null" ); + if ( out.substr(0,5)=="Sorry" || out.length()<80 ) { + cerr << "Gnuplot seems not to support X11\n"; + exit(1); + } + // Start a Gnuplot that will read from our pipe. triv::system( "gnuplot -title "+S(iPlot)+" -noraise < "+fn_fifo+"&" ); diff --git a/pub/trivia/file_ops.cpp b/pub/trivia/file_ops.cpp index 1fb548c4ac8b79b15168cf7c59dd195d415313e6..bffb31e175383ec889fd762711845216e47ef22b 100644 --- a/pub/trivia/file_ops.cpp +++ b/pub/trivia/file_ops.cpp @@ -40,6 +40,23 @@ void triv::system( string cmd, bool debug ) cout << "DEBUG system call -> return value " << ret << "\n"; } +//! Execute operation system call, and return its stdout. + +string triv::system_read( string cmd, bool debug ) +{ + if( debug ) + cout << "DEBUG system call '" + cmd + "'\n"; + FILE *f = ::popen( cmd.c_str(), "r" ); + + string ret; + char buf[1024]; + while( fgets( buf, 1024, f ) ) + ret += buf; + + pclose( f ); + return ret; +} + //**************************************************************************// //* file names, globbing *// diff --git a/pub/trivia/file_ops.hpp b/pub/trivia/file_ops.hpp index bed6811feb90b0fc717aefa29e5d650dab350de0..fdb50586f4fbe69f4033d7d758c5005b6da7f6d9 100644 --- a/pub/trivia/file_ops.hpp +++ b/pub/trivia/file_ops.hpp @@ -11,14 +11,12 @@ namespace triv { // Improved libc calls: void system( string cmd, bool debug=false ); + string system_read( string cmd, bool debug=false ); // File names, globbing: bool file_exists( const string& fname ); - void fname_divide( const string& fname, string *fdir, - string *fshort, string *fext); - void glob_file_list( const string& pattern, - const string& extension, - vector<string> *fnames ); + void fname_divide( const string& fname, string *fdir, string *fshort, string *fext); + void glob_file_list( const string& pattern, const string& extension, vector<string> *fnames ); string wordexp_unique( const string& s ); string next_tmp_file( const string& path_format );