* ------------------------------------------------------------------ * File snmain.f (Unix version) * This is a main program to illustrate the use of subroutine SNOPT, * which is part of the SNOPT package. * * 31 Jul 1996: First version. * 12 Feb 1998: Current version. * ------------------------------------------------------------------ program snmain implicit double precision (a-h,o-z) parameter ( maxm = 1000, & maxn = 1000, & maxne = 3000, & nName = 1 ) character*8 Prob, Names(nName) integer ha(maxne) , hs(maxn+maxm) integer ka(maxn+1) double precision a(maxne) , bl(maxn+maxm), bu(maxn+maxm), & x(maxn+maxm), pi(maxm) , rc(maxn+maxm) * SNOPT workspace parameter ( lenrw = 20000) double precision rw(lenrw) parameter ( leniw = 10000) integer iw(leniw) parameter ( lencw = 500) character*8 cw(lencw) logical byname character*20 lfile external HexCon, HexObj * ------------------------------------------------------------------ * Specify some of the SNOPT files. * iSpecs is the Specs file (0 if none). * iPrint is the Print file (0 if none). * iSumm is the Summary file (0 if none). * * nout is an output file used here by snmain. iSpecs = 4 iPrint = 15 iSumm = 6 nout = 6 byname = .true. if ( byname ) then * Unix and DOS systems. Open the Specs and print files. lfile = 'snmain.spc' open( iSpecs, file=lfile, status='OLD', err=800 ) lfile = 'snmain.out' open( iPrint, file=lfile, status='UNKNOWN', err=800 ) end if * ------------------------------------------------------------------ * First, snInit MUST be called to initialize optional parameters * to their default values. * ------------------------------------------------------------------ call snInit( iPrint, iSumm, & cw, lencw, iw, leniw, rw, lenrw ) * ------------------------------------------------------------------ * Read a Specs file (Optional). * ------------------------------------------------------------------ call snSpec( iSpecs, inform, & cw, lencw, iw, leniw, rw, lenrw ) if (inform .ge. 2) then write(nout, *) 'iSpecs > 0 but no Specs file found' go to 990 end if * Set up the data structure for the sparse Jacobian. * Assign dummy values for the nonlinear elements. call HexDat( Prob, maxm, maxn, maxne, inform, & m, n, ne, nnCon, nnObj, nnJac, iObj, ObjAdd, & a, ha, ka, bl, bu, hs, x, pi ) * ------------------------------------------------------------------ * Specify any options not set in the Specs file. * i1 and i2 may refer to the Print and Summary file respectively. * Setting them to 0 suppresses printing. * ------------------------------------------------------------------ itnlim = 250 i1 = 0 i2 = 0 call snseti( 'Iterations ', itnlim, i1, i2, inform, & cw, lencw, iw, leniw, rw, lenrw ) * ------------------------------------------------------------------ * Go for it, using a Cold start. * hs need not be set if a basis file is to be input. * Otherwise, each hs(1:n) should be 0, 1, 2, 3, 4, or 5. * The values are used by the Crash procedure m2crsh * to choose an initial basis B. * If hs(j) = 0 or 1, column j is eligible for B. * If hs(j) = 2, column j is initially superbasic (not in B). * If hs(j) = 3, column j is eligible for B and is given * preference over columns with hs(j) = 0 or 1. * If hs(j) = 4 or 5, column j is initially nonbasic. * ------------------------------------------------------------------ call snopt ( 'Cold', m, n, ne, nName, & nnCon, nnObj, nnJac, & iObj, ObjAdd, Prob, & HexCon, HexObj, & a, ha, ka, bl, bu, Names, & hs, x, pi, rc, & inform, mincw, miniw, minrw, & nS, nInf, sInf, Obj, & cw, lencw, iw, leniw, rw, lenrw, & cw, lencw, iw, leniw, rw, lenrw ) if (inform .eq. 42 .or. inform .eq. 43 .or. inform .eq. 44) then write(nout, *) ' ' write(nout, *) 'Estimate of required lencw:', mincw write(nout, *) 'Estimate of required leniw:', miniw write(nout, *) 'Estimate of required lenrw:', minrw go to 910 end if write(nout, *) ' ' write(nout, *) 'snopt finished.' write(nout, *) 'inform =', inform write(nout, *) 'nInf =', nInf write(nout, *) 'sInf =', sInf write(nout, *) 'Obj =', Obj if (inform .ge. 20) go to 910 stop * ------------------------------------------------------------------ * Error exit. * ------------------------------------------------------------------ 800 write(nout, 4000) 'Error while opening file', lfile stop 910 write(nout, *) ' ' write(nout, *) 'STOPPING because of error condition' 990 stop 4000 format(/ a, 2x, a ) * end of main program to test subroutine snopt end