473,666 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10695
Hi,

"Joseph Suprenant" <la******@yahoo .com> wrote in message
news:AR******** **********@twis ter.nyroc.rr.co m...
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::Signal ReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFil ters );

}

signal( SIGUSR1, SignalReloadFil ters );

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******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

"Joseph Suprenant" <la******@yahoo .com> wrote in message
news:AR******** **********@twis ter.nyroc.rr.co m...
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::Signal ReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFil ters );

}

signal( SIGUSR1, SignalReloadFil ters );

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******** **********@twis ter.nyroc.rr.co m...
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******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

"Joseph Suprenant" <la******@yahoo .com> wrote in message
news:AR******** **********@twis ter.nyroc.rr.co m...
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::Signal ReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFil ters );

}

signal( SIGUSR1, SignalReloadFil ters );

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******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,
"Joseph Suprenant" <la******@yahoo .com> wrote in message
news:Nt******** **********@twis ter.nyroc.rr.co m...
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******@jupit er.universe> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

"Joseph Suprenant" <la******@yahoo .com> wrote in message
news:AR******** **********@twis ter.nyroc.rr.co m...
> 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::Signal ReloadFilters( int Dummy )
{
GoReloadFilters = true; // Reload on next alarm
signal( SIGUSR1, SignalReloadFil ters );

}

signal( SIGUSR1, SignalReloadFil ters );

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::GNUplo t() throw(string) {
gnuplotpipe=pop en("gnuplot","w ");
if (!gnuplotpipe) {
throw("Gnuplot not found !");
}
}

GNUplot::~GNUpl ot() {
fprintf(gnuplot pipe,"exit\n");
pclose(gnuplotp ipe);
}

void GNUplot::operat or() (const string& command) {
fprintf(gnuplot pipe,"%s\n",com mand.c_str());
fflush(gnuplotp ipe);
// 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
4755
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 ?? thanks ram
10
8251
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++ on RedHat? I am doing some numerical calculations and need to invoke an external plotting program (gnuplot) and return to the numerics. Sorry if I posted twice.
3
2535
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 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...
1
3357
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 method in gnuplot.py that does this for me? If not, I tried something like:
5
4914
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: subp=Popen("gnuplot",stdin=None,stderr=PIPE,stdout=PIPE) .... subp.stderr.readline()
18
7515
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++ program. For example I want to run a very simple command like "plot sin(x)". So after running another program, what is the way to pipe that with some commands from inside the c++
2
6972
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 minor test I did (unrelated stuff excised) #include <stdlib.h> int system(const char *string);
0
1211
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 tried this: g.load(power.p) but it gives me this error: Traceback (most recent call last):
0
1707
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 telling me to run "demo.py" and analyse the code. does any1 have any idea where else I could look? A comprehensive tutorial/online documentation would be ideal
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.