Walter, thank you for your reply.
First, I don't care if the data are binary or not - "external function" is
implemented by me. I can output whatever needed, be it text, binary,
tertiary, anything.
What I do need is probably a bidirectional interprocess communication.
Gnuplot (splot) sends the argument list for each grid point and my program
sends back the function evaluated for these arguments.
<a> popen() is 1-way
<b> I don't know how to invoke popen from gnuplot
The function can not be effectively precomputed because the data range
is not specified beforehand. And actually contour plotting requires a
grid, and if I understand correctly (?) a grid can not be stored in the
data file, this requires explicit (resource-expensive) conversion.
For example, this works:
f(x,y)=real(system(sprintf("./func %f %f",y,x)))
splot(f(x,y))
where the external program func is below:
#include <stdio.h>
#include <stdlib.h>
main(int argc, char **argv)
{
double x,y;
if(3!=argc)
exit(-1);
x=atof(argv[1]);
y=atof(argv[2]);
printf("%g",x*x+y*y);
return(0);
}
I only want to speed it up. Possible?
Thanks
-Lev
wh> I am not sure that i understand what you are trying to archive
wh>
wh> Writing the data to a file and reading that as matrix should be pretty fast.
wh> I assume you are aware that you can use binary data ? (http://gnuplot.sourceforge.net/demo_4.6/binary.html)
wh>
wh> if you can write a gnuplot script you can uses popen() that should be
wh> much better that system().
wh>
wh> Am 30.07.2012 22:42, schrieb Lev A. Melnikovsky:
wh> > Hi,
wh> >
wh> > the function I need to plot is a result of nontrivial computation (each data
wh> > point is obtained by solving an ODE). I have implemented it in C, but executing
wh> > the program with
wh> >
wh> > real(system(sprintf("somecommand %f %f", x, y)))
wh> >
wh> > once for each data point (this is a 3d surface) implies a significant overhead.
wh> > My program is statically linked, still this is too slow. I need grid data (to
wh> > create contours), so building the datafile is inefficient.
wh> >
wh> > Ideally I'd like to see an option to open a pipe and write the arguments to it
wh> > and read the results from it. My program would be glad to work in this mode. Is
wh> > this possible?
wh> >
wh> > I'm using Linux if this matters.
wh> >
wh>
wh> re,
wh> wh
wh>
|