From: fretz@virgo.hks.com (Kurt Fretz)
Newsgroups: comp.lang.fortran
Subject: Re: passing arrays as parameters
Date: 16 Oct 1992 12:00:27 GMT
Organization: HKS, Inc.
Distribution: world
Reply-To: fretz@virgo.hks.com (Kurt Fretz)
NNTP-Posting-Host: virgo.hks.com


In article <16OCT92.07182890.0071@VM1.MCGILL.CA>, UBCF@MUSICB.MCGILL.CA (UBCF) writes:
>Path: argo.hks.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!cs.utexas.edu!uunet!olivea!charnel!sifon!VM1.MCGILL.CA
>From: UBCF@MUSICB.MCGILL.CA (UBCF)
>Newsgroups: comp.lang.fortran
>Subject: passing arrays as parameters
>Message-ID: <16OCT92.07182890.0071@VM1.MCGILL.CA>
>Date: Fri, 16 Oct 92 07:39:02 GMT+5:00
>Sender: usenet@MUSICB.MCGILL.CA
>Organization: McGill University
>Lines: 35
>Nntp-Posting-Host: vm1.mcgill.ca
>
>
>     I've got a bit of a problem with a program I'm working on. I have
>to use some external routines (ie LINPACK) to solve a set of equations
>in a program I'm writing using the VSFORT 2.0 compiler, which implements
>the F77 standard. I'm trying to solve Ax=b, where A is a matrix and x
>and b are vectors. I have to pass A and b to the routines, which then
>solve for x. The problem is that I'm trying to write a general purpose
>routine, since the size of x can vary anywhere from 5 to 100. At the
>start of the program I tried to declare
>
>       DIMENSION A(100,100),x(100),b(100)
>
>so that all of my cases would be covered. The problem is that the
>external routine crash and burn unless A,x and b are dimensioned to
>exactly the size that they have for the current case. What I mean, is
>that if the current size is 5, everything blows up unless the
>initial declaration of the variables is A(5,5),x(5),b(5). What I don't
>understand is that the external routine also requires that you pass
>the CURRENT dimensions of the variables. So, if I initially have
>
>     dimension A(100,100),x(100),b(100)
>     .
>     .
>     {read in current value of size, N}
>     call routine (A,b,N)
>
>then the program doesn't work. What I'd like to know is is there any
>way that I can run this under the fortran 77 standard without
>manually changing the dimensions and recompiling for each case? Since
>I've got about 70 different cases that I have to test, I don't really
>want to have to run the program 70 times. Anyway, thanks in advance.
>
>Scot Hughes
>UBCF@MUSICB.MCGILL.CA
>scot@emf.lan.mcgill.ca
>

The problem is probably that routine assumes a is NxN and looks something like:

     subroutine routine(a,b,n)
     dimension a(n,n), b(n)
      
       (etc.)

The arrays are adjustable arrays.  Since the memory layout is determeined by the
first dimension this must match the problem size n. One way to get around this
is to dimension one array in your calling progrma and use indicies into it. e.g.

      parameter (maxsiz = 100)
      parameter (ntotal = maxsiz*maxsiz + 2*maxsiz)
      dimension array(ntotal)
      .
      (read in size n)
      iaindx = 1
      (fill in array(iaindx) with n x n values - may need sub. call to do this)
       .
       ibindx = iaindx + n*n
       ixindx = ibindx + n
       .
       call routine( array(iaindx), array(ibindx), n )
       (array(ibindx) will contina the n values for b)
       .
        
This should allow you to use the same program to handle any size problem up to
maxsiz.

Kurt Fretz, Hibbitt, Karlsson and Sorensen, Inc.  <frretz@hks.com>
From: bigelow@hpfcso.FC.HP.COM (Jim Bigelow)
Date: Thu, 15 Oct 1992 20:52:19 GMT
Subject: Mutiplication with character constants
Organization: Hewlett-Packard, Fort Collins, CO, USA