Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!unmvax!ariel.unm.edu!ghostwheel.unm.edu!john From: john@ghostwheel.unm.edu (John Prentice) Newsgroups: comp.lang.fortran Subject: Re: Fortran vs. C for numerical work (SUMMARY) Message-ID: <1990Dec3.191100.22176@ariel.unm.edu> Date: 3 Dec 90 19:11:00 GMT References: <1990Nov21.220816.15220@rice.edu> <2173@tuvie> <1990Nov30.183032.5420@ccu.umanitoba.ca> <4421@goanna.cs.rmit.oz.au> Sender: news@ariel.unm.edu (USENET News System) Organization: University of New Mexico Physic Dept., Albuquerque, NM Lines: 59 In article <4421@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: >In article <1990Nov30.183032.5420@ccu.umanitoba.ca>, salomon@ccu.umanitoba.ca (Dan Salomon) writes: >> I remember once trying to translate a FORTRAN fast-fourier analysis >> procedure into PL/I. Sounds like a piece of cake, right? The problem >> was that the FORTRAN procedure accepted arrays with not only any size >> of dimensions, but also with any number of dimensions. > >I don't recall that being legal in F77. To be sure, I've met compilers >that didn't bother to check, and I think there was a special case for >DATA statements, but argument passing? >-- Assuming I am reading the original posting correctly, there is nothing to preclude this in Fortran. Specifically, imagine the following code: program ralph real*8 a pointer (a,ipnt) integer imax,jmax,kmax,factor,nlen c c memory will be allocated to array a of length imax*jmax*kmax c imax=20 jmax=40 kmax=60 c c factor=8 if dynamic memory allocation wants values in bytes, c otherwise factor=1. nlen is the number of whatever unit the c dynamic memory allocation routine wants c factor=8 nlen=factor*imax*jmax*kmax ... a call to malloc to allocate nlen words/bytes at the location a call fred (a,imax,jmax,kmax) end subroutine fred (john,imax,jmax,kmax) real*8 john(imax,jmax,kmax) .... do whatever he wants with the array john end I am here using Cray/Sun type Fortran pointers along with a call to malloc (either directly or using the Cray or Sun Fortran interfaces) to allocate nlen number of bytes or words (as appropiate) starting at the location of the local variable a. I then call the subroutine and reference the array john as a multidimensional array. Since Fortran calls by reference, not by value, you can do this. This particular example is how I do most of my memory management nowadays in Fortran. It is not ANSI Fortran, but it is something which every compiler I work on has in one form or the other (I have not yet found one that doesn't, at least on workstations, though they may not have the pointer capability and therefore there may be other avenues required. However, most all Fortran compilers allow you some capability of this sort. Fortran Extended has this built in (the allocate function). ). In general I would not recommend changing the dimension of an array when you make a subroutine call, but there are times that it is either necessary (like the above case) or desireable for performance reasons (to avoid the Cray limitation on only vectorizing the inner loop of a do-loop). John Prentice john@unmfys.unm.edu Brought to you by Super Global Mega Corp .com