1

I have a Fortran 90 program that outputs some data to a .txt file. The data is to be plotted with gnuplot.

I was able to launch gnuplot with

CALL SYSTEM("start wgnuplot")

which is equivalent to type

start gnuplot 

in the Windows command line prompt.

But then, I would like to have the program telling gnuplot what to do next, i.e., changing directory to the right one, and plotting my file.txt.

All in all this boils down to a simpler question:

How do I pass a command line in Windows that launches gnuplot and gives it some additional commands?

I tried to do that with something even easier like plotting y=x. In a normal gnuplot windows this is just plot x.

From the cmd.exe (which is what is called by Fortran's CALL SYSTEM() )I've tried:

start wgnuplot plot x
start wgnuplot plot x -pause
start wgnuplot plot x -persist
start wgnuplot plot x -noend
start wgnuplot plot x /noend

And others, including every possible variant with or without quotation marks, for instance

start wgnuplot "plot x -persist" 

etc.

So far the only one that works is the basic

start gnuplot

Which starts gnuplot indeed. But then I don't know how to add the next commands. Once I have a working command line input I believe I will just have to plop it into the CALL SYSTEM argument to have my Fortran program doing all the work.

I could only find instructions on how to achieve this on a UNIX-like machine, but not on Windows. Any help would be appreciated.

Background info: Windows 8, Code::Blocks, gnuplot 5.0 patchlevel 1

F. Valenti
  • 11
  • 1
  • 4
  • Always use tag [tag:fortran] and add a version tag only when it is necessary to distinguish the version (not really here). – Vladimir F Героям слава Jan 24 '16 at 19:33
  • You can run simple instructions with option `-e`, like `gnuplot -p -e "plot x"`. Since you are using gnuplot 5.0, I would recommend using option `-c` with a script (see [this answer](http://stackoverflow.com/a/31815067/2174266), although I don't know if it works with windows) – vagoberto Jan 25 '16 at 05:04

1 Answers1

1

you need to use named pipes which are very easy in C and unix:

http://tldp.org/LDP/lpg/node11.html and see this answer: https://stackoverflow.com/a/14027358/2743307

in Fortran and UNIX you can use the shell mkfifo command: https://genomeek.wordpress.com/2012/05/07/tips-reading-compressed-file-with-fortran-and-named-pipe/

Community
  • 1
  • 1
bibi
  • 3,671
  • 5
  • 34
  • 50
  • Thank you for your answers, however I had already checked out that question, and it's quite complicated; I don't seem to be able to implement it in Fortran. Supposing there's no coding involved, isn't there a way to do that simply from the command line, something like "start wgnuplot AND do this and that"? – F. Valenti Jan 24 '16 at 19:24
  • The best way is to use Fortran to write a file `file.gp` with all the gnuplot commands and then use `CALL system("wgnuplot -p file.gp")` – bibi Jan 24 '16 at 20:33