Re: simple graphics for fortran on windows
- From: Michael Prager <Mike.Prager.indigo@xxxxxxxx>
- Date: Thu, 25 Sep 2008 11:34:06 -0400
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.
.
- Follow-Ups:
- Re: simple graphics for fortran on windows
- From: michels
- Re: simple graphics for fortran on windows
- From: Michael Prager
- Re: simple graphics for fortran on windows
- References:
- simple graphics for fortran on windows
- From: peter . king
- simple graphics for fortran on windows
- Prev by Date: Re: simple graphics for fortran on windows
- Next by Date: Re: simple graphics for fortran on windows
- Previous by thread: Re: simple graphics for fortran on windows
- Next by thread: Re: simple graphics for fortran on windows
- Index(es):
Relevant Pages
|