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,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fc050a66c3b5d87d,start X-Google-Attributes: gid103376,public X-Google-Thread: 1094ba,86e8c626be2471ae X-Google-Attributes: gid1094ba,public From: bv Subject: F9X twister & ADA (was: n-dim'l vectors) Date: 2000/04/06 Message-ID: <38ED4ECA.ADB698C9@sdynamix.com>#1/1 X-Deja-AN: 607830058 Content-Transfer-Encoding: 7bit References: <8cctts$ujr$1@nnrp1.deja.com> <38EA0440.1ECBC158@ncep.noaa.gov> X-Accept-Language: en X-Server-Date: 7 Apr 2000 02:59:32 GMT Content-Type: text/plain; charset=us-ascii Organization: Eclipse Software Mime-Version: 1.0 Newsgroups: comp.lang.fortran,comp.lang.ada Date: 2000-04-07T02:59:32+00:00 List-Id: Paul van Delst wrote: > > nsavvinv2@my-deja.com wrote: > > Can a function return an n-dimensional vector? > > Sure - in f90 at least....dunno about f77. I got it to work for vectors > by using INTERFACE blocks in the code that calls the function, e.g. > > 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 > > RETURN > > END FUNCTION my_func > > and then in the calling program: > > PROGRAM blah > > IMPLICIT NONE > > INTERFACE > ! Interface body for my_func > FUNCTION my_func ( x, y ) RESULT ( z ) > IMPLICIT NONE > INTEGER, INTENT( IN ), DIMENSION( : ) :: x, y > INTEGER, DIMENSION( SIZE( x ) ) :: z > END FUNCTION my_func > END INTERFACE > > INTEGER, DIMENSION( 5 ) :: x = (/ -1, 1, -1, 1 /), & > y = (/ 1, -1, 1, -1 /) > > WRITE( *, '( 5i5 )' ) my_func( x, y ) > > END PROGRAM blah What a slaughter of Fortran, showing every symptom of design by ignorant and incompetent committee. What happened, where they too busy with themselves to bother and learn from ADA?? If they did, they'd see something along these lines: function normalize(v: in vector) return vector is vni: float; begin vni := 1./norm(v) return (v(x)*vni, v(y)*vni, v(z)*vni); end normalize; -- somewhere in your code u,v: vector; . . . u := normalize(v); The difference speaks for itself!! My advise to Fortran committee is to head F9X for the nearest trash bin and start raising funds to compensate the vendors for costs incurred to implement their vision of language abuse. btw, note a duality of the ADA & F77 fcn. A similar extension for returning user types couldn't be crafted? But one would have to be aware of the prior art of course... -- Dr.B.Voh ----------------------------------------------- Modeling * Simulation * Analysis http://www.sdynamix.com -----------------------------------------------