C NCLFORTSTART
      SUBROUTINE DGELSI( M, N, NRHS, A, B )
      IMPLICIT   NONE
      INTEGER    M, N, NRHS
      DOUBLE PRECISION   A( M, N ), B( M, NRHS)
C NCLEND
C                        ==> f90 <===
      DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) ::  WORK, TEMP
      INTEGER     LWORK, MN, INFO, LDA, LDB, I, J
      CHARACTER*1 TRANS

      LDA   =  M
      LDB   =  M
      TRANS = "N"
C                       Determine optimal workspace 
      LWORK = -1
      allocate ( TEMP(100) )
      CALL DGELS(TRANS, M,N,NRHS,A,LDA,B,LDB,TEMP,LWORK,INFO)
      LWORK = INT(TEMP(1))
      allocate ( WORK(LWORK) )

      CALL DGELS(TRANS, M,N,NRHS,A,LDA,B,LDB,WORK,LWORK,INFO)

      RETURN
      END

C NCLFORTSTART
      SUBROUTINE DGELSIW( M, N, NRHS, A, B, LWORK, WORK )
      IMPLICIT   NONE
      INTEGER    M, N, NRHS, LWORK
      DOUBLE PRECISION   A( M, N ), B( M, NRHS), WORK(LWORK)
C NCLEND
C                        ==> f77 <===

      INTEGER     MN, INFO, LDA, LDB, I, J
      CHARACTER*1 TRANS

      LDA   =  M
      LDB   =  M
      TRANS = "N"

      CALL DGELS(TRANS, M,N,NRHS,A,LDA,B,LDB,WORK,LWORK,INFO)

      RETURN
      END

