From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,86e8c626be2471ae X-Google-Attributes: gid1094ba,public X-Google-Thread: 103376,fc050a66c3b5d87d X-Google-Attributes: gid103376,public From: Dick Hendrickson Subject: Re: F9X twister & ADA (was: n-dim'l vectors) Date: 2000/04/08 Message-ID: <38EF6B75.DD12DD25@att.net>#1/1 X-Deja-AN: 608420369 Content-Transfer-Encoding: 7bit References: <8cctts$ujr$1@nnrp1.deja.com> <38EA0440.1ECBC158@ncep.noaa.gov> <38ED4ECA.ADB698C9@sdynamix.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 955214717 12.75.130.249 (Sat, 08 Apr 2000 17:25:17 GMT) Organization: AT&T Worldnet MIME-Version: 1.0 NNTP-Posting-Date: Sat, 08 Apr 2000 17:25:17 GMT Newsgroups: comp.lang.fortran,comp.lang.ada Date: 2000-04-08T00:00:00+00:00 List-Id: 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