Question

I want to run m*n matrix to do QR decomposition in fortran

PROGRAM SUBDEM 
    INTEGER  key, n, m, loopA
    REAL resq
    REAL A(3,2)     
    REAL B(3)
    REAL X(2) 
    key  = 0
    n    = 2
    m    = 3
    resq = 0   
    CALL QR(m, n, A, B, X, resq) 
END

The QR routine is:

subroutine QR(m, n, a, b, x, resq)
     implicit double precision (a-h, o-z)                              
      dimension a(m,n),b(m),x(n)
      double precision sum, dot
      resq=-2.0
      if (m .lt. n) then 
        return
      endif  
      resq=-1.0
!  Loop ending on 1800 rotates  a  into upper triangular form.
      do 1800 j=1, n
!  Find constants for rotation and diagonal entry.
        sq=0.0
        do 1100 i=j, m
          sq=a(i,j)**2 + sq
 1100   continue
        if (sq .eq. 0.0) then 
            return
        endif
        qv1=-sign(sqrt(sq), a(j,j))
        u1=a(j,j) - qv1
        a(j,j)=qv1
        j1=j + 1
! Rotate remaining columns of sub-matrix.
        do 1400 jj=j1, n
          dot=u1*a(j,jj)
          do 1200 i=j1, m
            dot=a(i,jj)*a(i,j) + dot
 1200     continue
          const=dot/abs(qv1*u1)
          do 1300 i=j1, m
            a(i,jj)=a(i,jj) - const*a(i,j)
 1300     continue
          a(j,jj)=a(j,jj) - const*u1
 1400   continue
! Rotate  b  vector.
        dot=u1*b(j)
        do 1600 i=j1, m
          dot=b(i)*a(i,j) + dot
 1600   continue
        const=dot/abs(qv1*u1)
        b(j)=b(j) - const*u1
        do 1700 i=j1, m
          b(i)=b(i) - const*a(i,j)
 1700   continue
 1800 continue
! Solve triangular system by back-substitution.
      do 2200 ii=1, n
        i=n-ii+1
        sum=b(i)
        do 2100 j=i+1, n
          sum=sum - a(i,j)*x(j)
 2100   continue
        if (a(i,i).eq. 0.0) then
            return
        endif
         x(i)=sum/a(i,i)
 2200 continue
! Find residual in overdetermined case.
      resq=0.0
      do 2300 i=n+1, m
        resq=b(i)**2 + resq
 2300 continue
      return
      end  subroutine  

However I am getting:

Error 1 error #6633: The type of the actual argument differs from the type of the dummy argument. [A] Error 2 error #6633: The type of the actual argument differs from the type of the dummy argument.
[B] Error 3 error #6633: The type of the actual argument differs from the type of the dummy argument. [X] Error 4 error #6633: The type of the actual argument differs from the type of the dummy argument. [RESQ]

What Am I doing wrong?

Was it helpful?

Solution

I will sum the comments of @george and @M.S.B.

The types and kinds of dummy arguments of procedures must match the actual arguments used by the calling code. The compiler can check this when having an explicit interface, when the procedure is in a module, for example, and some compilers can do that also for external procedures, which is your case.

Placing the subroutines in modules is the preferred way for making this check possible at all conditions and all compilers.

By using implicit double precision (a-h, o-z) you declare all variables with name beginning with a-h or o-z as being double precision. In your main program you are using real for calling the procedure. This is the error, the types have to match.

It is strongly discouraged to use any other form of the implicit other than implicit none, which is the form that should be present at the beginning of every compilation unit (program, module, external procedures).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top