Re: simple graphics for fortran on windows



peter.king@xxxxxxxxxxxxxx wrote:

I am using Windows XP professional and a free Fortran compiler FORCE
(2.08 I think it is a front end for the g-77 compiler). I am trying to
find a simple library of basics graphics routines (xy plots, basic
symbol plotting etc) for use with this (or any other easy to use
Fortran compiler). I am not a computer scientist and just want
something very easy to use without knowledge of c, unix or similar.

Peter,

I'll add a little to what has already been said. I am far from
an expert in this area, but have looked into libraries and used
a couple.

Most graphics routines callable directly from high-level
languages such as Fortran are not simpleto use. They require a
great deal of setup to define what you want plotted.

Routines that plot directly to a physical device (and I would
include a file as a physical device) are complex enough. The
ones that plot to a window on the screen are even more complex,
as you have to specify all the window properties before you
specify what should be plotted.

I generally write data from Fortran and then use R to plot them.
R is a free and flexible statistics language with excellent
graphics. I have written libraries to export complicated data
structures to R, but for simple data, an ASCII file works just
as well.

Appended is a short Fortran 90 program that generates random
data, writes the data and a short R script to two files, and
issues a SYSTEM call to plot the data. The plot is then saved to
a PNG file. If you have any interest in R, you will find this a
more rewarding path to follow than learning arcane graphics
library.

Unless I have made errors (not uncommon), the program is
standard conforming except for the SYSTEM call, but every
compiler offers that in some form.

However, to use the appended program with a Fortran 77 compiler,
you will need to change the array operations to DO loops and
revise the declarations and comment characters.

Finally, many of us would recommend updating to Fortran 95,
which is very close to a superset of Fortran 77. It has many
useful new features, including far better error checking and
some quite useful array operations.

Hope that helps.

Mike P.

P.S. Note that my or your newsreader may cause some Fortran
lines to wrap inappropriately. I hope that if that occurs, it
will be clear enough where the problem is.

program rplot

implicit none
integer, parameter :: ndat = 100
integer :: i
real, dimension(ndat) :: x, y, error

! Generate data w/ array operations (Fortran-90 or higher)
call random_number(x)
call random_number(error)
y = 5.0 * x + error

! Write the data to a file
open(unit = 20, file = "fortran.dat", action = "write",
status = "unknown")
write(20, *) "x y error"
do i = 1, ndat
write(20, 500) x(i), y(i), error(i)
end do
close(20)
500 format(3(3x, es12.4))

! Write an R script file
open(unit = 30, file = "myprogram.r", action = "write",
status = "unknown")
write(30, *) "xy = read.table('fortran.dat', header = TRUE)"
write(30, *) "windows()"
write(30, *) "with(xy, plot(x,y))"
write(30, *) "savePlot(filename = 'myplot.png', type = 'png')
write(30, *) "winDialog('ok', 'Click to quit')"
close(30)

! Use a system call to run R and plot the data
call system("rterm.exe --no-restore --no-save --vanilla <
myprogram.r")

stop
end program rplot

--
Mike Prager, NOAA, Beaufort, NC
Address spam-trapped; remove color to reply.
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.
.



Relevant Pages

  • Re: Matlab Vectorisation Speed - How is it done in c++?
    ... Beating the performance of vectorized Matlab code is very ... Matlab makes calls to optimized C and Fortran libraries ... Use optimization level 3 on numerical code and level 2 on non- ...
    (comp.soft-sys.matlab)
  • Re: can somebody verify this C program which calls dsaupd_ ? (longish)
    ... >>>(terribly sorry for this long post which includes my two source files, ... > is NOT relevant to FORTRAN language newsgroup. ... More importantly, if your libraries compiled correctly, they were fine. ... > FORTRAN libs. ...
    (sci.math.num-analysis)
  • NAG on Fortran for finance quants
    ... Malcolm Cohen of NAG has written an article on the advantages of a ... matrix-oriented language like Fortran 2003 for quantitative finance ... promoting Fortran in QF. ... adding NEW procedures ONLY to the F77 and C libraries. ...
    (comp.lang.fortran)
  • Re: C versus FORTRAN90
    ... FORTRAN90 version of these libraries. ... Are there other more subtle benefits for FORTRAN over C? ... If the answer to if f95 heavy, then maybe some sort of cost-benefit analysis of a wholesale switch from f95 to C at your company should be done to convince them otherwise. ...
    (comp.lang.fortran)
  • Re: Link problem with Compaq Visual Fortran
    ... > | yet one of the source codes is a Fortran program. ... > in Fortran and C run-time libraries (CVF uses both despite the fact ... GCG.lib: error LNK2001: unresolved external symbol ...
    (comp.lang.fortran)