 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Joseph Suprenant Guest
|
Posted: Sun Oct 26, 2003 3:36 pm Post subject: 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
|
|
| Back to top |
|
 |
Moonlit Guest
|
Posted: Sun Oct 26, 2003 4:43 pm Post subject: Re: calling GNUPLOT from a c++ program |
|
|
Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote
| Quote: | 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.
| Quote: | Thanks
Regards, Ron AF Greve. |
|
|
| Back to top |
|
 |
Joseph Suprenant Guest
|
Posted: Sun Oct 26, 2003 5:27 pm Post subject: Re: calling GNUPLOT from a c++ program |
|
|
are you talking to me?
I don't get it
"Moonlit" <alt.spam (AT) jupiter (DOT) universe> wrote
| Quote: | Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote in message
news:ARRmb.35086$%a2.6446 (AT) twister (DOT) 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.
|
|
|
| Back to top |
|
 |
Moonlit Guest
|
Posted: Sun Oct 26, 2003 6:40 pm Post subject: Re: calling GNUPLOT from a c++ program |
|
|
Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote
| Quote: | are you talking to me?
|
Yes.
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.
| Quote: | "Moonlit" <alt.spam (AT) jupiter (DOT) universe> wrote in message
news:3f9bf9bd$0$58713$e4fe514c (AT) news (DOT) xs4all.nl...
Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote in message
news:ARRmb.35086$%a2.6446 (AT) twister (DOT) 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.
|
|
|
| Back to top |
|
 |
Joseph Suprenant Guest
|
Posted: Sun Oct 26, 2003 7:13 pm Post subject: Re: calling GNUPLOT from a c++ program |
|
|
well my original problem still exists how do i start GNUPLOT from my C++
program?
"Moonlit" <alt.spam (AT) jupiter (DOT) universe> wrote
| Quote: | Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote in message
news:NtTmb.82096$Hs.60115 (AT) twister (DOT) 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" <alt.spam (AT) jupiter (DOT) universe> wrote in message
news:3f9bf9bd$0$58713$e4fe514c (AT) news (DOT) xs4all.nl...
Hi,
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> wrote in message
news:ARRmb.35086$%a2.6446 (AT) twister (DOT) 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.
|
|
|
| Back to top |
|
 |
Frank Schmitt Guest
|
Posted: Tue Oct 28, 2003 9:35 am Post subject: Re: calling GNUPLOT from a c++ program |
|
|
"Joseph Suprenant" <laclac01 (AT) yahoo (DOT) com> writes:
| Quote: | 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
|
|
| Back to top |
|
 |
Christian Gollwitzer Guest
|
Posted: Fri Oct 31, 2003 8:07 am Post subject: Re: calling GNUPLOT from a c++ program |
|
|
Joseph Suprenant wrote:
| Quote: | 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 |
| Quote: | 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,"exitn");
pclose(gnuplotpipe);
}
void GNUplot::operator() (const string& command) {
fprintf(gnuplotpipe,"%sn",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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|