C***********************************************************************
C*                                                                     *
C*                            OUTPUT.FOR                               *
C*                                                                     *
C*       Impressao de Resultados                                       *
C*                                                                     *
C*       Autor: Oswaldo Vernet                                         *
C*       Em:    21.09.93                                               *
C*                                                                     *
C***********************************************************************
C
C***********************************************************************
C*       Imprime Resultados Parciais                                   *
C***********************************************************************
C
      SUBROUTINE ITROUT (N, X, FX, GX, CONT)
C
      IMPLICIT REAL*8 (A-H, O-Z)
C
C     Declaracoes de parametros e Variaveis Locais
C
      INTEGER N, I
      LOGICAL CONT
      REAL*8  X(N), GX(N), FX, GNORM
C
C     Declaracoes de Variaveis Globais
C
      COMMON /ESTAT/ IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS,
     *               NITER, MAXITR
      INTEGER IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS, NITER, MAXITR
C
C     Saida de dados para um arquivo de dados
C
      OPEN (UNIT = LP,FILE = 'SAIDA.OUT')

      CONT = .TRUE.
C
      WRITE (LP,1000) NITER
      WRITE (LP,1010)

      GNORM = 0.0D0
      DO 10 I = 1, N
         WRITE (LP,1020) I, X(I), GX(I)
         GNORM = GNORM + GX(I) ** 2
10    CONTINUE
      GNORM = DSQRT (GNORM)
C
20    WRITE (LP,1030) FX, GNORM
      WRITE (LP,1040) NFUN, NGRAD, NHESS
      WRITE (LP,1050)
C
C      CALL WAITKB (CONT)
C
      CLOSE ( UNIT = LP )

      RETURN
C
C     Formatos para Impressao
C
1000  FORMAT ('0************* ITERACAO ',I8, ' *****************')
1010  FORMAT ('0              X               G(X)')
1020  FORMAT (' ', I2, '   ', 2E18.10)
1030  FORMAT ('0   F(X)          =', E18.10,/,
     *        '    Norma de G(X) =', E18.10)
1040  FORMAT ('0   # Avaliacoes da funcao    =',I8,/,
     *        '    # Avaliacoes do gradiente =',I8,/,
     *        '    # Avaliacoes da Hesseana  =',I8)
1050  FORMAT ('0************************************************')
C
      END
C
C***********************************************************************
C*       Imprime Resultados Parciais                                   *
C***********************************************************************
C
      SUBROUTINE ITROU1 (N, X, FX, CONT)
C
      IMPLICIT REAL*8 (A-H, O-Z)
C
C     Declaracoes de parametros e Variaveis Locais
C
      INTEGER N, I
      LOGICAL CONT
      REAL*8  X(N), FX
C
C     Declaracoes de Variaveis Globais
C
      COMMON /ESTAT/ IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS,
     *               NITER, MAXITR
      INTEGER IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS, NITER, MAXITR
C
C
      OPEN (UNIT = LP,FILE = 'SAIDA.OUT')
C
      CONT = .TRUE.
C
      WRITE (LP,1000) NITER
      WRITE (LP,1010)

      DO 10 I = 1, N
         WRITE (LP,1020) I, X(I)
10    CONTINUE
C
20    WRITE (LP,1030) FX
      WRITE (LP,1040) NFUN
      WRITE (LP,1050)
C
C      CALL WAITKB (CONT)
C
      CLOSE ( UNIT = LP )

      RETURN
C
C     Formatos para Impressao
C
1000  FORMAT ('0************* ITERACAO ',I8, ' *****************')
1010  FORMAT ('0              X')
1020  FORMAT (' ', I2, '   ', E18.10)
1030  FORMAT ('0   F(X)          =', E18.10)
1040  FORMAT ('0   # Avaliacoes da funcao    =',I8)
1050  FORMAT ('0************************************************')
C
      END
C
C***********************************************************************
C*       Imprime os Resultados Finais                                  *
C***********************************************************************
C
      SUBROUTINE PRINTR (N, X, FX, GX, IERROR, METODO)
C
      IMPLICIT REAL*8 (A-H, O-Z)
C
C     Declaracoes de Parametros e Variaveis Locais
C
      INTEGER N, IERROR, I
      REAL*8 X(N), GX(N), FX, GNORM
C
C     Variaveis Globais
C
      COMMON /ESTAT/ IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS,
     *               NITER, MAXITR
      INTEGER IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS, NITER, MAXITR

      LP = 1
      OPEN (UNIT = LP,FILE = 'SAIDA.OUT')

      WRITE (LP,1000) METODO
      WRITE (6,*) ' '
      WRITE (6,*) ' '
      WRITE (6,1000) METODO
C
C     Da' informacoes sobre a convergencia.
C
      IERROR = IERROR + 1
      GOTO (10, 20, 30, 40, 50, 60), IERROR
C
10    WRITE (LP,2000)
      WRITE (6,2000)
      GOTO 100
20    WRITE (LP,2010) MAXITR
      WRITE (6,2010) MAXITR
      GOTO 100
30    WRITE (LP,2020)
      WRITE (6,2020)
      GOTO 100
40    WRITE (LP,2030) MAXFUN
      WRITE (6,2030) MAXFUN
      GOTO 100
50    WRITE (LP,2040)
      WRITE (6,2040)
      GOTO 100
60    WRITE (LP,2050)
      WRITE (6,2050)
      GOTO 100
C
100   WRITE (LP,1010) NITER, NFUN, NGRAD, NHESS
      WRITE (6,1010) NITER, NFUN, NGRAD, NHESS
C
      WRITE (LP, 1020)
      WRITE (6, 1020)
      GNORM = 0.0D0
      DO 200 I = 1, N
         WRITE (LP,1030) I, X(I), GX(I)
         WRITE (6,1030) I, X(I), GX(I)
200      GNORM = GNORM + GX(I) ** 2
      GNORM = DSQRT (GNORM)
C
      WRITE (LP,1040) FX, GNORM
      WRITE (6,1040) FX, GNORM
      WRITE (6,*) ' '
      WRITE (6,*) ' '
C     WRITE (LP,1050)
C
C     WRITE (*, 3000)
C     READ (*, *)
C
      CLOSE (LP)

      RETURN
C
C     Formatos para Impressao de Resultados
C
1000  FORMAT ('************* METODO =', I8 , '****************')
1010  FORMAT ('    # Iteracoes               =', I8,/,
     *        '    # Avaliacoes da funcao    =', I8,/,
     *        '    # Avaliacoes do gradiente =', I8,/,
     *        '    # Avaliacoes da Hesseana  =', I8)
1020  FORMAT ('          X               G(X)')
1030  FORMAT (' ', I2, '   ', 2E18.10)
1040  FORMAT ('    F(X)          =', E18.10,/,
     *        '    Norma de G(X) =', E18.10)
C050  FORMAT ('0************************************************')
C
2000  FORMAT ('    O PROCESSO CONVERGIU')
2010  FORMAT ('    NAO CONVERGIU EM', I8, ' ITERACOES')
2020  FORMAT ('    NAO CONVERGIU: FALHA NA BUSCA LINEAR')
2030  FORMAT ('    NAO CONVERGIU: FUNCAO AVALIADA MAIS DE', I8,
     *        ' VEZES')
2040  FORMAT ('    PROCESSO INTERROMPIDO')
2050  FORMAT ('     NAO CONVERGIU: HESSEANA NAO ERA DEFINIDA POSITIVA')
C
3000  FORMAT (' Tecle <Enter> para prosseguir')
C
      END
C
C***********************************************************************
C*       Imprime os Resultados Finais                                  *
C***********************************************************************
C
      SUBROUTINE PRT1 (N, X, FX, IERROR, METODO)
C
      IMPLICIT REAL*8 (A-H, O-Z)
C
C     Declaracoes de Parametros e Variaveis Locais
C
      INTEGER N, IERROR, I
      REAL*8 X(N), FX
C
C     Variaveis Globais
C
      COMMON /ESTAT/ IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS,
     *               NITER, MAXITR
      INTEGER IPRINT, LP, MAXFUN, NFUN, NGRAD, NHESS, NITER, MAXITR

      LP = 1
      OPEN (UNIT = LP,FILE = 'SAIDA.OUT')
C
      WRITE (LP,1000) METODO	
      WRITE (6,*) ' '
      WRITE (6,*) ' '
      WRITE (6,1000) METODO
C
C     Da' informacoes sobre a convergencia.
C
      IERROR = IERROR + 1
      GOTO (10, 20, 30, 40, 50, 60), IERROR
C
10    WRITE (LP,2000)
      WRITE (6,2000)
      GOTO 100
20    WRITE (LP,2010) MAXITR
      WRITE (6,2010) MAXITR
      GOTO 100
30    WRITE (LP,2020)
      WRITE (6,2020)
      GOTO 100
40    WRITE (LP,2030) MAXFUN
      WRITE (6,2030) MAXFUN
      GOTO 100
50    WRITE (LP,2040)
      WRITE (6,2040)
      GOTO 100
60    WRITE (LP,2050)
      WRITE (6,2050)
      GOTO 100
C
100   WRITE (LP,1010) NITER, NFUN, NGRAD, NHESS
      WRITE (6,1010) NITER, NFUN, NGRAD, NHESS
C
      WRITE (LP, 1020)
      DO 200 I = 1, N
         WRITE (LP,1030) I, X(I)
         WRITE (6,1030) I, X(I)
200   CONTINUE
C
      WRITE (LP,1040) FX
      WRITE (6,1040) FX
C     WRITE (LP,1050)
C
C     WRITE (*, 3000)
C     READ (*, *)
C
      CLOSE (LP)

      RETURN
C
C     Formatos para Impressao de Resultados
C
1000  FORMAT ('************* METODO = ', I8 , '****************')
1010  FORMAT ('   # Iteracoes               =', I8,/,
     *        '    # Avaliacoes da funcao    =', I8,/,
     *        '    # Avaliacoes do gradiente =', I8,/,
     *        '    # Avaliacoes da Hesseana  =', I8)
1020  FORMAT ('              X')
1030  FORMAT (' ', I2, '   ', E18.10)
1040  FORMAT ('   F(X)          =', E18.10,//)
C050  FORMAT ('0************************************************')
C
2000  FORMAT ('   O PROCESSO CONVERGIU')
2010  FORMAT ('   NAO CONVERGIU EM', I8, ' ITERACOES')
2020  FORMAT ('   NAO CONVERGIU: FALHA NA BUSCA LINEAR')
2030  FORMAT ('   NAO CONVERGIU: FUNCAO AVALIADA MAIS DE', I8,
     *        ' VEZES')
2040  FORMAT ('   PROCESSO INTERROMPIDO')
2050  FORMAT ('    NAO CONVERGIU: HESSIANA NAO ERA DEFINIDA POSITIVA')
C
3000  FORMAT ('Tecle <Enter> para prosseguir')
C
      END
C
C***************************************************************
C*       Faz uma pausa, esperando teclado                      *
C***************************************************************
C
      SUBROUTINE WAITKB (CONT)
C
      LOGICAL     CONT
      CHARACTER*1 LETRA
C
      WRITE (*, 10)
      READ (*, 20) LETRA
C
      IF (LETRA .EQ. 'n' .OR. LETRA .EQ. 'N') GOTO 100
         CONT = .TRUE.
         RETURN
C     ELSE
100      CONT = .FALSE.
         RETURN
C     ENDIF
C
10    FORMAT  ('0Continua (s/n) ? ')
20    FORMAT  (A1)
      END
