473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

calling GNUPLOT from a c++ program

Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question is
how would i call GNUPLOT from my C++ program. I know in some operating
systems you can do system("gnuplot"); But not with red hat 7.3. So could
some kind soul help me out? After it starts up GNUPLOT my program will
terminate.
Thanks

Jul 19 '05 #1
6 10676
Hi,

"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:AR******************@twister.nyroc.rr.com...
Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question is how would i call GNUPLOT from my C++ program. I know in some operating
systems you can do system("gnuplot"); But not with red hat 7.3. So could
some kind soul help me out? After it starts up GNUPLOT my program will
terminate.
Strange, that shouldn't happen. Did you try to intercept all signals? Likely
your program terminates because it gets a signal that it isn't expecting.
Here is some code:

void CCSFilt::SignalReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFilters );

}

signal( SIGUSR1, SignalReloadFilters );

Do this for all signals and see which one is sent.
Thanks

Regards, Ron AF Greve.

Jul 19 '05 #2
are you talking to me?
I don't get it
"Moonlit" <al******@jupiter.universe> wrote in message
news:3f***********************@news.xs4all.nl...
Hi,

"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:AR******************@twister.nyroc.rr.com...
Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question
is
how would i call GNUPLOT from my C++ program. I know in some operating
systems you can do system("gnuplot"); But not with red hat 7.3. So
could some kind soul help me out? After it starts up GNUPLOT my program will
terminate.


Strange, that shouldn't happen. Did you try to intercept all signals?

Likely your program terminates because it gets a signal that it isn't expecting.
Here is some code:

void CCSFilt::SignalReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFilters );

}

signal( SIGUSR1, SignalReloadFilters );

Do this for all signals and see which one is sent.
Thanks

Regards, Ron AF Greve.

Jul 19 '05 #3
Hi,
"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:Nt******************@twister.nyroc.rr.com...
are you talking to me?
Yes.
I don't get it
What I meant is that your program shouldn't terminate when it uses the
system command. Likely that your program receives a signal. Some signals may
terminate (abort) your program when you do not intercept them. Use "man
signal" (I believe it is man 5 signal but am not sure) to see the signals
that might be sent.

Try to intercept them so they do not terminate your program. This you can do
with the following code.

void SignalCHLD( int Dummy )
{
signal( SIGCHLD, SignalCHLD );
fprintf( stderr, "SIGCHLD received" ); // Not actually allowed
normally, but will work most of the time.
}

signal( SIGCHLD, SignalCHLD ); // Do this for all possible signals!
system( "gnuplot" );

Do this for all signals and see what signals your program receives.

Regards, Ron AF Greve.


"Moonlit" <al******@jupiter.universe> wrote in message
news:3f***********************@news.xs4all.nl...
Hi,

"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:AR******************@twister.nyroc.rr.com...
Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question
is
how would i call GNUPLOT from my C++ program. I know in some operating systems you can do system("gnuplot"); But not with red hat 7.3. So could some kind soul help me out? After it starts up GNUPLOT my program will terminate.


Strange, that shouldn't happen. Did you try to intercept all signals?

Likely
your program terminates because it gets a signal that it isn't

expecting.

Here is some code:

void CCSFilt::SignalReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFilters );

}

signal( SIGUSR1, SignalReloadFilters );

Do this for all signals and see which one is sent.
Thanks

Regards, Ron AF Greve.


Jul 19 '05 #4
well my original problem still exists how do i start GNUPLOT from my C++
program?

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f***********************@news.xs4all.nl...
Hi,
"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:Nt******************@twister.nyroc.rr.com...
are you talking to me?
Yes.
I don't get it


What I meant is that your program shouldn't terminate when it uses the
system command. Likely that your program receives a signal. Some signals

may terminate (abort) your program when you do not intercept them. Use "man
signal" (I believe it is man 5 signal but am not sure) to see the signals
that might be sent.

Try to intercept them so they do not terminate your program. This you can do with the following code.

void SignalCHLD( int Dummy )
{
signal( SIGCHLD, SignalCHLD );
fprintf( stderr, "SIGCHLD received" ); // Not actually allowed
normally, but will work most of the time.
}

signal( SIGCHLD, SignalCHLD ); // Do this for all possible signals!
system( "gnuplot" );

Do this for all signals and see what signals your program receives.

Regards, Ron AF Greve.


"Moonlit" <al******@jupiter.universe> wrote in message
news:3f***********************@news.xs4all.nl...
Hi,

"Joseph Suprenant" <la******@yahoo.com> wrote in message
news:AR******************@twister.nyroc.rr.com...
> Hello all,
> I have a C++ program, it does some calculations on things and then > prints out a file in the format in which GNUPLOT can use. So my

question
is
> how would i call GNUPLOT from my C++ program. I know in some operating > systems you can do system("gnuplot"); But not with red hat 7.3. So

could
> some kind soul help me out? After it starts up GNUPLOT my program will > terminate.

Strange, that shouldn't happen. Did you try to intercept all signals?

Likely
your program terminates because it gets a signal that it isn't expecting.

Here is some code:

void CCSFilt::SignalReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFilters );

}

signal( SIGUSR1, SignalReloadFilters );

Do this for all signals and see which one is sent.

> Thanks
>
>
>
Regards, Ron AF Greve.



Jul 19 '05 #5
"Joseph Suprenant" <la******@yahoo.com> writes:
well my original problem still exists how do i start GNUPLOT from my C++
program?


Please don't top post.
Using system() is the right way to call an external program like gnuplot
from C++ - if it doesn't work properly, your problem must lie elsewhere.
Post some code.

regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #6
Joseph Suprenant wrote:
Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question is
how would i call GNUPLOT from my C++ program. I know in some operating
systems you can do system("gnuplot"); system is useless since then you can't pass any commands to GNUplot
But not with red hat 7.3. So could
some kind soul help me out? After it starts up GNUPLOT my program will
terminate.


I've done this on Linux using the popen() function (which is not
standard C++, but POSIX-standard)

class GNUplot {
public:
GNUplot() throw(string);
~GNUplot();
void operator ()(const string& command);
// send any command to gnuplot
protected:
FILE *gnuplotpipe;
};

GNUplot::GNUplot() throw(string) {
gnuplotpipe=popen("gnuplot","w");
if (!gnuplotpipe) {
throw("Gnuplot not found !");
}
}

GNUplot::~GNUplot() {
fprintf(gnuplotpipe,"exit\n");
pclose(gnuplotpipe);
}

void GNUplot::operator() (const string& command) {
fprintf(gnuplotpipe,"%s\n",command.c_str());
fflush(gnuplotpipe);
// flush is necessary, nothing gets plotted else
};
You simply construct one object and invoke it with operator () like

GNUplot plotter;
plotter("plot sin(x)");

Note that GNUplot will be killed as soon as your program terminates. So
you need to wait for keystroke or similar, otherwise you will only see
short flashing of the graph. If you need that the graph window stays on
screen after your pragram fnished, then instead of "gnuplot" in the
constructor invoke "gnuplot -persist".

--
Vale !
Christianus Auriocus

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rama Calaga | last post by:
Hi, I use both python and gnuplot a lot, but I am unable to find a way to embed gnuplot "window/canvas" into tkinter. BLT option in PMW is not so powerful and not so great, any suggestions ?? ...
10
by: Sanyi Benczik | last post by:
Is there a standard way in C++ to call an external program or is this platform dependent? If it is platform dependent, can somebody drop a line what to use or where to look for info for GNU C++...
3
by: Bernhard Hidding | last post by:
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...
1
by: Nicola Kaiser | last post by:
Hi, I´m using Gnuplot via gnuplot.py and I´m looking for a way to get the plotting output (terminal set to png in my case) piped in a string instead of to stdout or a file. Is there any...
5
by: Anton81 | last post by:
Hi, it seems to be a FAQ, but I still haven't found a solution. I want to control gnuplot with a python program. The following at least gives me the gnuplot output: ...
18
by: utab | last post by:
Dear all, I am making a system call to the well known Gnuplot with system("gnuplot"); gnuplot opens if I only supply this command but I would like to pipe that command line in my C++...
2
by: Blah | last post by:
I'm trying to use the system() in a C++ program to execute gnuplot on a file of data on OSX and have the graph pop up but so far the only thing I've managed to do is get gnuplot to open. as I...
0
by: Santix | last post by:
I am doing a python program that save the data in a text file in columns and I want to do a gnuplot to plot the results. But I want the program in python to show the result with gnuplot. I have...
0
by: matthew43 | last post by:
You might want to try g.reset() or something of the sort. i saw this post because I'm also trying to figure out gnuplot.py I can't seem to find proper documentation anywhere. unless its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.