        FUNCTION LHS(R,I) result (RES)
            DOUBLE PRECISION R, I
            LOGICAL RES

            RES = R < 0.0
        END FUNCTION

        SUBROUTINE WRITE_MAT (A)
            INTEGER I, J
            DOUBLE PRECISION A(4,4)

            DO I =  1, 4
                DO J = 1, 4
                write(6,100, advance='no') A(I,J)
100             FORMAT(E15.9'    ')
                END DO
                print*
            END DO
        END SUBROUTINE


        PROGRAM TEST
            IMPLICIT NONE

            CHARACTER   JOBVS, SORT
            INTEGER INFO, LDA, SDIM, LDVS, LWORK, N
            LOGICAL LHS
            EXTERNAL LHS


            DOUBLE PRECISION A(4, 4), VS(4, 4), WI (4), WR (4), WORK(12), &
                BWORK(4)

            JOBVS = 'V'
            SORT = 'S'

            N = 4
            LDA = 4
            LDVS = LDA
            LWORK = LDA * 3

            A = reshape((/ 4.0, -4.5, 9.0, 6.0, 3.0, -3.5, 6.0, 4.0, 1.0, &
                -1.0, -4.0, -3.0, -1.0, 1.0, 4.5, 3.5 /), (/4, 4/))
            CALL WRITE_MAT(A)

            CALL DGEES(JOBVS, SORT, LHS, N, A, LDA, SDIM, WR, WI, VS, LDVS, &
                WORK, LWORK, BWORK, INFO)

            print*
            CALL WRITE_MAT(A)
            print*
            CALL WRITE_MAT(VS)
            print*
            print*,'INFO: ', INFO


        END PROGRAM TEST


