468,765 Members | 1,461 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

gnuplot parameter interchange

Hello,
my c++ programm produces a variable number of ASCII files with variable file
names. These are to be plotted in with gnuplot. I use

system("gnuplot -persist my_gnuplot_script.gpl");

to open gnuplot, and "my_gnuplot_script.gpl" contains a list of files to be
plotted (e.g. plot "array13.dat", "array87.dat",...). However, each time the
program runs, different files are to be plotted, so I have to change the
file names in my gnuplot script manually each time. How can I hand over some
parameters to gnuplot? Or would it be the easiest way to modify my .gpl
script by my c++ program? If so, how do I do that?
Thanks in advance,
Bernhard Hidding

-------------------------
SuSE 9.1, g++ compiler
Jul 22 '05 #1
3 2336
Bernhard Hidding wrote:

Hello,
my c++ programm produces a variable number of ASCII files with variable file
names. These are to be plotted in with gnuplot. I use

system("gnuplot -persist my_gnuplot_script.gpl");

to open gnuplot, and "my_gnuplot_script.gpl" contains a list of files to be
plotted (e.g. plot "array13.dat", "array87.dat",...). However, each time the
program runs, different files are to be plotted, so I have to change the
file names in my gnuplot script manually each time. How can I hand over some
parameters to gnuplot? Or would it be the easiest way to modify my .gpl
script by my c++ program? If so, how do I do that?


What you pass to system() is a string. Of course you can use a string
variable also. And thus you have every freedom you want to come
up with that string.

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
std::string CommandLine;
std::string FileName;

CommandLine = "gnuplot -persist ";

cout << "Which file to plot?\n";
cin >> FileName;

CommandLine += FileName;

cout << "Executing command: " << CommandLine << endl;
system( CommandLine.c_str() );
}

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2
Thank you,
but that is not quite what I intend to do. Maybe I did not make myself clear
enough.
In this case it is not enough to be able to chose between different gnuplot
script files, but to generate a script file on the fly. Each time my program
runs, a different script file would be needed, because each time new ASCII
files with different names are being created which shall be plotted. My c++
program contains all the data that the gnuplot script file would need to
know. So, is it the easiest way to let my c++ program create the gnuplot
script file and write it to disk, and call it after that? Or is there a
convenient way to pass variables over to gnuplot?

Bernhard
Jul 22 '05 #3
Bernhard Hidding wrote:

Thank you,
but that is not quite what I intend to do. Maybe I did not make myself clear
enough.
In this case it is not enough to be able to chose between different gnuplot
script files, but to generate a script file on the fly.
open script file
write commands as text to script file
close script file

use system() to execute script file
Each time my program
runs, a different script file would be needed, because each time new ASCII
files with different names are being created which shall be plotted. My c++
program contains all the data that the gnuplot script file would need to
know. So, is it the easiest way to let my c++ program create the gnuplot
script file and write it to disk, and call it after that? Or is there a
convenient way to pass variables over to gnuplot?


C++ knows nothing about gnuplot. There may be some way to control gnuplot
through some interprocess mechanism.

The simplest thing is .... see above

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rama Calaga | last post: by
3 posts views Thread by Blues | last post: by
6 posts views Thread by Joseph Suprenant | last post: by
1 post views Thread by Nicola Kaiser | last post: by
reply views Thread by bwaha | last post: by
reply views Thread by Titi Anggono | last post: by
2 posts views Thread by Blah | last post: by
3 posts views Thread by arslanburney | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.