Solved

# FORTRAN 77 Question

Posted on 2004-03-24

I'm writing a program that will take arguments from the command line for the dimensions and values of an n*n matrix. The problem is that the intrinsic getarg(integer variable, character variable) as I am using it in my program gives me the following error at compile time when using the Einsys Fortran 1.0 IDE trial version:

Statement at (2) invalid in context established by statement at (1)

C:\PROGRA~1\EINSYS~1\p2m2.f:34:

CALL GETARG(N*(I-1)+J+1,R)

^

Reference to intrinsic `GETARG' at (^) invalid -- one or more arguments have incorrect type

----- End of Compile

This is my source:

PROGRAM P2M2

PARAMETER (MAX = 10) ! maximum row/column dimension is 10

REAL A(MAX,MAX) ! initialize three matrices

REAL B(MAX,MAX)

REAL C(MAX,MAX)

CHARACTER P, D

INTEGER I,J,N

c Begin main..................................................

CALL GETARG(1,P)

N = INTEGER(P)

IF (N.GT.MAX) THEN

PRINT*,'n greater than',MAX,', program will exit'

STOP

ENDIF

DO I=1,N

DO J=1,N

CHARACTER R

CALL GETARG(N*(I-1)+J+1,R)

A(I,J) = REAL(R)

ENDDO

ENDDO

CALL FILLB(A,B,N,MAX) ! call to fillb

CALL MULTIPLY(A,B,C,N,MAX) ! call to multiply

DO I=1,N

DO J=1,N

WRITE (6,10) C(I,J) ! print product matrix2

10 FORMAT(F9.3,$)

ENDDO

PRINT*

PRINT*

ENDDO

END

SUBROUTINE FILLB(X,Y,N,MAX) ! fill matrix b

REAL X(MAX,MAX), Y(MAX,MAX), TEMP

PRINT*

DO I=1,N

DO J=1,N

Y(I,J)=SQRT(X(I,J)) ! fill with square roots of matrix a

ENDDO

ENDDO

END

SUBROUTINE MULTIPLY(X,Y,Z,N,MAX) ! multiply two matrices

REAL X(MAX,MAX), Y(MAX,MAX), Z(MAX,MAX)

DO I=1,N

DO J=1,N

Z(I,J)=X(I,J)*Y(I,J) ! fill third matrix with products

ENDDO ! of the first and second matrices

ENDDO

END

Any suggestions you might have to correct the type of one or both arguments would be greatly appreciated. Supr