Topic: Running plot

I am on a Macintosh. When my program runs it would be very nice to have feedback on how it is doing, or if it has gotten hung up. In the past I have gotten both by having the program make a running plot, that it plotting some basic results on the screen as the program runs. How do I do that in Simply Fortran for the Mac? I only need 5 routines: Open a plotting window, change the pen color, move the pen, draw a line, and close the window.

Re: Running plot

This works well for me.  http://gnuplot.info/ You just have to write the plot data to a file in the format gnuplot likes which is really simple.  I mostly write motion control programs using FORTRAN for CNC machines, so I use WPCVIEW for sanity checks.

Re: Running plot

I do not think that will work for me. Even if the data file is linked to gnuplot, the data does not appear in the data file when fortran executes a write statement, it is held in a buffer, sometimes until the program terminates. I want the plot to appear step by step, as the fortran program runs. A good analogy would be: Think of writing a game in fortran with simple vector graphics. You want the graphics to appear instantly, not after it has been buffered, written to a file, then read by another code.

Re: Running plot

Hibbs wrote:

How do I do that in Simply Fortran for the Mac? I only need 5 routines: Open a plotting window, change the pen color, move the pen, draw a line, and close the window.

Simply Fortran ships with a plotting package, but it does not support running graphs or closing/replacing existing ones on macOS, so that won't work.  You would need a third-party plotting library.

Hibbs wrote:

I do not think that will work for me. Even if the data file is linked to gnuplot, the data does not appear in the data file when fortran executes a write statement, it is held in a buffer, sometimes until the program terminates.

Indeed the output is buffered.  You can, however, use the GNU extension FLUSH to force a unit to flush to disk or screen (depending on the unit).  Writing to a data file that GNUPlot reads might be preferable to trying to directly integrate or call a library just due to the simplicity.

Jeff Armstrong
Approximatrix, LLC

Re: Running plot

I will keep gnuplot in mind. It may solve other issues with my plotting as well. But I am also interested in doing very simple plotting directly by the fortran code, in real time. How do I do that?

Re: Running plot

You can use Aplot that comes with Simply Fortran, but it does require user interaction (your program will pause while the plot is shown).  The plots in Aplot cannot be updated, though; you would need to close them and create an entirely new plot.

The alternative would be a third-party library like PLplot, which does provide a Fortran interface.  You'll need to build that as well on macOS first, though, or use a package manager like Homebrew or MacPorts to install it as a binary. 

There is a library called fplot that allows for interacting with GNUPlot from within Fortran.  I've never personally used it, but it looks promising.

Jeff Armstrong
Approximatrix, LLC