Reputation: 127
I would like to call a gnuplot script from a program in Fortran. The program is supposed to perform a linear fit, to obtain the linear parameters and to send them back to the main program. I know that gnuplot can be called from Fortran using the command
call system ('gnuplot script.gnu')
what I don't know is how to send parameters to gnuplot in this call (let's say a real variable called t
) and to return back to the main program the values of the fitted parameters (two real values a
and b
).
Note: I would like to avoid the use of files to communicate between the programs: I don't want gnuplot to write a file that it is then read by the Fortran program.
My script for the linear fitting:
f(x)=a*x+b
fit [t:*] f(x) "data.txt" u 1:2 via a,b;
Upvotes: 0
Views: 597
Reputation: 60078
You can use the -e
command line argument of gnuplot
call system (`gnuplot -e "t=1" script.gnu')
to pass a parameter to gnuplot. I am not aware of any way to return a value though.
(To make it really useful you will have to get the numbers into the string, see Convert integers to strings to create output filenames at run time and many related question in the "Linked" tab about how you can do that.)
It should be very easy to do your linear fit in Fortran, the formula is very simple and there are also libraries available, and avoid all these complications.
Upvotes: 1