      program procbratu

C     LOCAL SCALARS
      integer i,j,nprob,id
      double precision tmin1,tmax1,tave1,fmin1,fmax1,fave1,
     +                 tmin2,tmax2,tave2,fmin2,fmax2,fave2,
     +                 tmin3,tmax3,tave3,fmin3,fmax3,fave3,
     +                 tmin4,tmax4,tave4,fmin4,fmax4,fave4,
     +                 tmin5,tmax5,tave5,
     +                 timetmp,dd

C     LOCAL ARRAYS
      integer sc1(10),sc2(10),sc3(10),sc4(10)
      double precision time1(10) ,time2(10) ,time3(10) ,time4(10),
     +                 f1(10)    ,f2(10)    ,f3(10)    ,f4(10),
     +                 cnorm1(10),cnorm2(10),cnorm3(10),cnorm4(10),
     +                 gnorm1(10),gnorm2(10),gnorm3(10),gnorm4(10),
     +                 compl2(10),compl3(10),alpr3(10)

      open(10,file="algencand8-bratu-table.out")
      open(20,file="ipopt-bratu-table.out")
      open(30,file="algencand4-bratu-table.out")
      open(40,file="ipoptws-bratu-table.out")
      open(50,file="algnew-bratu-table.out")
      open(60,file="bratu-table.out")

      nprob = 16

      do i = 1,nprob

          do j = 1,10

C            ALGENCAN WITH PRECISION 1.0d-08:

             read(10,*) time1(j),sc1(j),id,id,id,id,id,id,id,f1(j),
     +       cnorm1(j),gnorm1(j),id,id,id,id

             if ( sc1(j) .ne. 0 .or. 
     +       cnorm1(j) .gt. 1.0d-08 .or. gnorm1(j) .gt. 1.0d-08 ) then
                 write(*,*) 'WARNING: algencand8 ',
     +           sc1(j),cnorm1(j),gnorm1(j),i,j
             end if

C            IPOPT:

             read(20,*) time2(j),sc2(j),id,id,id,f2(j),gnorm2(j),
     +       cnorm2(j),compl2(j)

             if ( sc2(j) .ne. 0 .or. cnorm2(j) .gt. 1.0d-08 .or.
     +       gnorm2(j) .gt. 1.0d-08 .or. compl2(j) .gt. 1.0d-08 ) then
                 write(*,*) 'WARNING: IPOPT ',
     +           sc2(j),cnorm2(j),gnorm2(j),compl2(j),i,j
             end if

C            IPOPT WITH WARM START

C            Algencan with precision 1.0d-04 to add the time to ipopt.
             read(30,*) timetmp,id,id,id,id,id,id,id,id,dd,dd,dd,id,id,
     +       id,id

             read(40,*) time3(j),sc3(j),id,id,id,f3(j),gnorm3(j),
     +       cnorm3(j),compl3(j)

             time3(j) = time3(j) + timetmp
             if ( timetmp .eq. 0.0d0 ) then
                 alpr3(j) = 0.0d0
             else
                 alpr3(j) = timetmp / time3(j)
             end if

             if ( sc3(j) .ne. 0 .or. cnorm3(j) .gt. 1.0d-08 .or.
     +       gnorm3(j) .gt. 1.0d-08 .or. compl3(j) .gt. 1.0d-08 ) then
                 write(*,*) 'WARNING: IPOPTWS ',
     +           sc3(j),cnorm3(j),gnorm3(j),compl3(j),i,j
             end if

C            ALGENCAN+NEWTON:

             read(50,*) time4(j),sc4(j),id,id,id,id,id,id,id,f4(j),
     +       cnorm4(j),gnorm4(j),id,id,id,id

             if ( sc4(j) .ne. 0 .or. 
     +       cnorm4(j) .gt. 1.0d-08 .or. gnorm4(j) .gt. 1.0d-08 ) then
                 write(*,*) 'WARNING: algencan+newton ',
     +           sc4(j),cnorm4(j),gnorm4(j),i,j
             end if

          end do

          call statd(10,time1, tmin1,tmax1,tave1)
          call statd(10,f1,    fmin1,fmax1,fave1)

          call statd(10,time2, tmin2,tmax2,tave2)
          call statd(10,f2,    fmin2,fmax2,fave2)

          call statd(10,time3, tmin3,tmax3,tave3)
          call statd(10,alpr3, tmin5,tmax5,tave5)
          call statd(10,f3,    fmin3,fmax3,fave3)

          call statd(10,time4, tmin4,tmax4,tave4)
          call statd(10,f4,    fmin4,fmax4,fave4)

          write(60,200) tave1,tave2,tave3,tave4,tave5,
     +                  fave1,fave2,fave3,fave4

      end do

      close(10)
      close(20)
      close(30)
      close(40)
      close(50)
      close(60)

 100  format(F8.2,1X,1P,D10.4,1X, F8.2,1X,1P,D10.4,1X,
     +       F8.2,1X,1P,D10.4,1X, F8.2,1X,1P,D10.4,1X, F8.2,1X)

 200  format(5(F8.2,1X),4(1P,D10.4,1X))

      end

      subroutine statd(n,v,vmin,vmax,vave)

C     SCALAR ARGUMENTS
      integer n
      double precision vmin,vmax,vave

C     ARRAY ARGUMENTS
      double precision v(n)

C     LOCAL SCALARS
      integer i

      vmin =   1.0d+99
      vmax = - 1.0d+99 
      vave =   0.0d0

      do i = 1,n
          vmin = min( vmin, v(i) )
          vmax = max( vmax, v(i) )
          vave = vave + v(i)
      end do

      vave = vave / n

      end

      subroutine stati(n,v,vmin,vmax,vave)

C     SCALAR ARGUMENTS
      integer n,vmin,vmax
      double precision vave

C     ARRAY ARGUMENTS
      integer v(n)

C     LOCAL SCALARS
      integer i

      vmin =   1000000
      vmax = - 1000000 
      vave =   0.0d0

      do i = 1,n
          vmin = min( vmin, v(i) )
          vmax = max( vmax, v(i) )
          vave = vave + v(i)
      end do

      vave = vave / n

      end
