Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!exodus-bb!khb From: khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) Newsgroups: comp.lang.fortran Subject: Re: Dimensioning arrays at run-time, best way? Message-ID: Date: 18 Sep 90 17:11:00 GMT References: <1990Sep18.115704.20642@msuinfo.cl.msu.edu> Sender: news@exodus.Eng.Sun.COM Organization: Sun MegaSystems Lines: 55 In-reply-to: fox@DASHER.NSCL.MSU.EDU's message of 18 Sep 90 12:53:24 GMT In article <1990Sep18.115704.20642@msuinfo.cl.msu.edu> fox@DASHER.NSCL.MSU.EDU writes: In article <1990Sep17.150155.10220@alchemy.chem.utoronto.ca>, mroussel@alchemy.chem.utoronto.ca (Marc Roussel) writes... > >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. I have often done well the "other way around" instead of > > PROGRAM EXAMPLE > read(*,*)n > call sub1(n) > END > > SUBROUTINE SUB1(N,X) > real X(N) ..... > END program example print*,"how many bytes ?" read(*,*) nbytes x=malloc(nbytes) call realprog(x,nbytes/4) end subroutine realprog(x,n) c c this is where the "real program" begins c real x(n) c do processing, including all calls c return end The "spelling" of how to procure the memory varies, malloc works on Sun and most unix boxes; I forget which sys$ call does the trick on VMS, and etc. but it is usually easy to find. Only a few lines in the formal main program need to adjusted from system to system. -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043