From: Dick Hendrickson <dick.hendrickson@att.net>
Subject: Re: F9X twister & ADA (was: n-dim'l vectors)
Date: 2000/04/08
Date: 2000-04-08T00:00:00+00:00 [thread overview]
Message-ID: <38EF6B75.DD12DD25@att.net> (raw)
In-Reply-To: Pine.BSF.4.21.0004071503540.28379-100000@shell5.ba.best.com
Brian Rogoff wrote:
>
> On 6 Apr 2000, Richard Maine wrote:
[snip]
>
> > The elided sample is not, of course, the only way to write the code in
> > question. Nor is it particularly close to the way I'd suggest writing
> > it. I rarely write out interface bodies - that's what modules are for.
>
> I'd be interested in seeing the snippet rewritten in a more elegant
> feature using the F9X features. I haven't used any Fortran since F77,
> with a little bit of Connection Machine Fortran while in grad school,
> so explanations of any subtleties would be appreciated.
>
Here's what I'd try to do to modify the original F90 sample
module some_functions ! put the function in a module
! and it's characteristics are
! available by magic to users.
contains ! we could declare global variables
! and data types above the "contains"
! but we don't have any in this simple
! case. Also, we could put any related
! functions or subroutines here.
! We could also declare things PUBLIC
! or PRIVATE to control access.
! Also, I prefer lower case keywords
> > FUNCTION my_func ( x, y ) RESULT ( z )
> >
> > IMPLICIT NONE
> > INTEGER, INTENT( IN ), DIMENSION( : ) :: x, y
> > INTEGER, DIMENSION( SIZE( x ) ) :: z
> >
> > z(:) = x(:) + y(:) ! Assumes x and y are the same size
! I prefer z = x + y
! The (:) makes it explicit that x, y, and z are arrays, some people
! like to know for sure what is going on, others like a little mystery
! in their life.
> >
> > RETURN ! this isn't needed, but again adds clarity
> >
> > END FUNCTION my_func !this implies return
end module some_functions
> >
> > and then in the calling program:
> >
> > PROGRAM blah
> >
> > IMPLICIT NONE
> >
use some_functions !this brings in the stuff from the module
! we could have done use some_functions, only :: my_func
> >
> > INTEGER, DIMENSION( 5 ) :: x = (/ -1, 1, -1, 1, -1 /), &
> > y = (/ 1, -1, 1, -1, 1 /)
> >
> > WRITE( *, '( 5i5 )' ) my_func( x, y )
> >
> > END PROGRAM blah
The rest of it looks OK to my style tastes. I think the key fact
is that using a module allows the compiler to know about procedure
interfaces by magic; no need for explicit declarations.
If you want to see some simple examples of "modern" fortran try
looking at the F subset language. Basically, F requires use of
the new Fortran 90 features and forbids use of the old FORTRAN 77
features. We probably should have called it F13, ;-).
The Imagine1 web page
www.imagine1.com/imagine1
has some example code.
Dick Hendrickson
dick@imagine1.com
next prev parent reply other threads:[~2000-04-08 0:00 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <8cctts$ujr$1@nnrp1.deja.com>
[not found] ` <38EA0440.1ECBC158@ncep.noaa.gov>
2000-04-06 0:00 ` F9X twister & ADA (was: n-dim'l vectors) bv
2000-04-06 0:00 ` Richard Maine
2000-04-07 0:00 ` Brian Rogoff
2000-04-08 0:00 ` Dick Hendrickson [this message]
2000-04-08 0:00 ` Richard Maine
2000-04-09 0:00 ` Gary Scott
2000-04-09 0:00 ` Richard Maine
2000-04-09 0:00 ` Geoff Bull
2000-04-09 0:00 ` Dick Hendrickson
2000-04-09 0:00 ` Robert Dewar
2000-04-09 0:00 ` Gordon Sande
2000-04-09 0:00 ` James Giles
2000-04-10 0:00 ` tmoran
2000-04-15 0:00 ` Aidan Skinner
2000-04-17 0:00 ` Robert I. Eachus
2000-04-16 0:00 ` Ken Garlington
2000-04-12 0:00 ` Robert I. Eachus
2000-04-10 0:00 ` bv
2000-04-10 0:00 ` James Van Buskirk
2000-04-11 0:00 ` James Giles
2000-04-11 0:00 ` Dale Stanbrough
2000-04-11 0:00 ` James Giles
2000-04-12 0:00 ` Robert A Duff
2000-04-11 0:00 ` Geoff Bull
2000-04-11 0:00 ` James Giles
2000-04-11 0:00 ` Larry Kilgallen
2000-04-11 0:00 ` James Giles
2000-04-11 0:00 ` Larry Kilgallen
2000-04-12 0:00 ` Robert A Duff
2000-04-12 0:00 ` Geoff Bull
2000-04-12 0:00 ` James Giles
2000-04-12 0:00 ` Geoff Bull
2000-04-12 0:00 ` James Giles
2000-04-12 0:00 ` Geoff Bull
2000-04-12 0:00 ` James Giles
2000-04-13 0:00 ` Geoff Bull
2000-04-13 0:00 ` Debugging (was: F9X twister & ADA) James Giles
2000-04-13 0:00 ` F9X twister & ADA (was: n-dim'l vectors) James Giles
2000-04-14 0:00 ` Geoff Bull
2000-04-12 0:00 ` Marin D. Condic
2000-04-12 0:00 ` James Giles
2000-04-12 0:00 ` James Giles
2000-04-14 0:00 ` bv
2000-04-07 0:00 ` Erik Edelmann
2000-04-07 0:00 ` Robert Dewar
2000-04-07 0:00 ` Erik Edelmann
2000-04-07 0:00 ` Paul van Delst
2000-04-10 0:00 ` bv
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox