Newsgroups: comp.lang.fortran Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel) Subject: Re: Dimensioning arrays at run-time, best way? Message-ID: <1990Sep17.150155.10220@alchemy.chem.utoronto.ca> Organization: Department of Chemistry, University of Toronto References: <614@keele.keele.ac.uk> Date: Mon, 17 Sep 90 15:01:55 GMT In article <614@keele.keele.ac.uk> phd11@.uk.ac.keele (Zipzoid) writes: >I think this question may have been asked many times before, >but what is the best way of dimensioning an array whose maximum >memory requirement (size) would be read in at run-time? Let your PROGRAM block be a dummy. (I.E. don't put any code into it that does anything but set N (the array size) and calls a subroutine which does the real work.) Then call your subroutine. Most FORTRAN compilers don't check for the right number of parameters in a subroutine call, so the following may not be portable, but it should do the work on most computers. Now for the example: PROGRAM EXAMPLE read(*,*)n call sub1(n) END SUBROUTINE SUB1(N,X) real X(N) C Do the work in this subroutine. C Of course you can't use common blocks so you'll have to pass X C around as an argument. END Good luck! Marc R. Roussel mroussel@alchemy.chem.utoronto.ca