[g77] Passing parameter statements through common block

From: Iain Day (iain.day_at_hertford.ox.ac.uk)
Date: 04/23/04


Date: Thu, 22 Apr 2004 23:47:58 +0100

Dear All,

I have a quick question about parameter statements and common blocks in
g77. I am using the subroutine below in this short demo program below to
convert a decimal integer into an array in a particular base.

As long as the arrays y and out are the same dimension it works fine.
The question is, can I put a parameter statement into a common block to
size both arrays with the same parameter?

Thanks,

Iain

        program conv
        

        integer x, y(10), b
        
        b = 3
        
        do x=0, 10
                call convbase(x, b, y)
        end do

        stop
        end
        
* Subroutine convbase
* Converts a decimal number to base 2 to base 9
        
        subroutine convbase(decnum, base, out)

        
        integer maxnum, decnum, base, i
        parameter (maxnum = 10)
        integer out(maxnum)

        do i=1, maxnum
                out(i) = 0
        end do

        i=1
        out(1) = decnum

* Convert the decimal number to base-b
        
        do while (out(i) .ge. base)
                out(i+1) = out(i) / base
                out(i) = out(i) - (base * out(i+1))
                i = i + 1
        end do
        return
        end
        


Quantcast