gnuplot parameter interchange

B

Bernhard Hidding

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
 
K

Karl Heinz Buchegger

Bernhard said:
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() );
}
 
B

Bernhard Hidding

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
 
K

Karl Heinz Buchegger

Bernhard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top