      subroutine easyminos2(n,x,l,u,mp,lambdap,rhop,equatnp,linearp,ml,
     +meq,alin2,acol2,aval2,annz2,b,epsgpsn,fmin,f,g,gpsupn,icase,ninf,
     +sinf,inform)

C     SCALAR ARGUMENTS
      integer annz2,icase,inform,mp,meq,ml,n,ninf
      double precision epsgpsn,f,fmin,gpsupn,sinf

C     ARRAY ARGUMENTS
      logical equatnp(mp),linearp(mp)
      integer alin2(annz2),acol2(annz2)
      double precision aval2(annz2),b(ml),g(n),l(n),lambdap(mp),
     +        rhop(mp),u(n),x(n)

C     PARAMETERS
      integer mmaxt,nmaxt,annzmaxt,nwcore
      parameter ( mmaxt    =           1000 )
      parameter ( nmaxt    =           1000 )
      parameter ( annzmaxt =  nmaxt * mmaxt )
      parameter ( nwcore   =         500000 )

C     There is another nmax declaration within subroutine coo2csc below.

C     LOCAL SCALARS
      integer annz,i,ispecs,iobj,iprint,isumm,mm,mincor,nb,
     +        nname,nncon,nnobj,nnjac,ns
      double precision objadd

C     LOCAL ARRAYS
      character * 8 names(5)
      integer alin(annzmaxt),acol(annzmaxt),asta(nmaxt),hs(nmaxt+mmaxt),
     +        name1(1),name2(1)
      double precision aval(annzmaxt),blow(mmaxt),bupp(mmaxt),
     +        bl(nmaxt+mmaxt),bu(nmaxt+mmaxt),pi(mmaxt),xn(nmaxt+mmaxt),
     +        rc(nmaxt+mmaxt),z(nwcore)

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer m

C     COMMON ARRAYS
      logical equatn(mmax),linear(mmax)
      double precision lambda(mmax),rho(mmax)

C     COMMON BLOCK
      common /aldata/ lambda,rho,equatn,linear,m

C     COPY AUGMENTED LAGRANGIAN ARGUMENTS INTO A COMMON BLOCK

      m = mp
      do i = 1,m
          lambda(i) = lambdap(i)
          rho(i)    = rhop(i)
          equatn(i) = equatnp(i)
          linear(i) = linearp(i)
      end do

C     ===================================================
C     P R O B L E M   D E F I N I T I O N
C     ===================================================

      mm = ml

C     Define blow and bupp to translate from:
C
C     (ai)^t x  = bi, i = 1,meq
C     (ai)^t x >= bi, i =meq+1,ml
C
C     to blow <= Ax <= bupp.
 
      do i = 1,meq
          blow(i) = b(i)
          bupp(i) = b(i)
      end do

      do i = meq + 1,ml
          blow(i) = b(i)
          bupp(i) = 1.0d+20
      end do

C     Copy sparse matrix

      annz = annz2
 
      do i = 1,annz2
          alin(i) = alin2(i)
          acol(i) = acol2(i)
          aval(i) = aval2(i)
      end do

C     ===================================================
C     E N D   O F   P R O B L E M   D E F I N I T I O N
C     ===================================================

C     Set problem related data

      names(1) = 'MyTest  '
      names(2) = 'funobj  '
      names(3) = 'rhs     '
      names(4) = 'ranges  '
      names(5) = 'bounds  '

      ispecs = 0
C     iprint = 9
C     isumm  = 6
      iprint = 0
      isumm  = 0

      call mispec(ispecs,iprint,isumm,nwcore,inform)
      call miopt ('Jacobian    Sparse',iprint,isumm,inform)

      nname  = 0
      nncon  = 0
      nnjac  = 0
      nnobj  = n

      objadd = 0.0d0

      iobj = 0
      nb   = n + mm

C     Add slacks coefficients

      do i = 1,mm
          annz = annz + 1

          alin(annz) = i
          acol(annz) = n + i
          aval(annz) = 1.0d0
      end do

C     Convert to compressed sparse column format

      call coo2csc(nb,annz,alin,acol,aval,asta)

C     Set bounds on x

      do i = 1,n
          bl(i) = l(i)
          bu(i) = u(i)
      end do

C     Set slacks bounds

      do i = 1,mm
          bl(n+i) = - bupp(i)
          bu(n+i) = - blow(i)
      end do

C     Call MINOS

      call minoss('Cold',mm,n,nb,annz,nname,nncon,nnobj,nnjac,iobj,
     +            objadd,names,aval,alin,asta,bl,bu,name1,name2,
     +            hs,xn,pi,rc,icase,mincor,ns,ninf,sinf,f,z,nwcore)

C     Write final values

c     write(*,*) ' icase  = ', icase
c     write(*,*) ' ninf   = ', ninf
c     write(*,*) ' sinf   = ', sinf
c     write(*,*) ' obj    = ', f

c     write(*,*) ' Solution: ',(xn(i),i=1,n)

      do i = 1,n
          x(i) = xn(i)
      end do

      end

C     ******************************************************************
C     ******************************************************************

      SUBROUTINE FUNOBJ( MODE, N, X, F, G, NSTATE, NPROB, Z, NWCORE )
      IMPLICIT           NONE
      INTEGER MODE,N,NSTATE,NPROB,NWCORE
      DOUBLE PRECISION F
      DOUBLE PRECISION   X(N), G(N), Z(NWCORE)

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer m

C     COMMON ARRAYS
      logical equatn(mmax),linear(mmax)
      double precision lambda(mmax),rho(mmax)

C     COMMON BLOCK
      common /aldata/ lambda,rho,equatn,linear,m

C     LOCAL SCALARS
      integer flag

      call evalun(n,x,m,lambda,rho,equatn,linear,f,flag)
      call evalnun(n,x,m,lambda,rho,equatn,linear,g,flag)

      END

C     ******************************************************************
C     ******************************************************************

      SUBROUTINE FUNCON( MODE, M, N, NJAC, X, F, G,
     *                   NSTATE, NPROB, Z, NWCORE )
      IMPLICIT           NONE
      INTEGER MODE,M,N,NJAC,NSTATE,NPROB,NWCORE
      DOUBLE PRECISION   X(N), F(M), G(NJAC), Z(NWCORE)

      END

C     ******************************************************************
C     ******************************************************************

      SUBROUTINE MATMOD( NCYCLE, NPROB, FINISH,
     *                   M, N, NB, NE, NKA, NS, NSCL,
     *                   A, HA, KA, BL, BU,
     *                   ASCALE, HS, ID1, ID2,
     *                   X, PI, Z, NWCORE )

      IMPLICIT           NONE
      INTEGER NCYCLE, NPROB, M, N, NB, NE, NKA, NS, NSCL, NWCORE
      INTEGER*2          HA(NE), HS(NB)
      INTEGER            KA(NKA), ID1(NB), ID2(NB)
      DOUBLE PRECISION   A(NE), ASCALE(NSCL), BL(NB), BU(NB)
      DOUBLE PRECISION   X(NB), PI(M), Z(NWCORE)
      LOGICAL            FINISH

      END
