/* iter8.f -- translated by f2c (version of 3 February 1990  3:36:42).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    integer ielmnt, isbckt, nsbckt, iunsat, nunsat, itemps, numtem, isens, 
	    nsens, ifour, nfour, ifield, icode, idelim, icolum, insize, 
	    junode, lsbkpt, numbkp, iorder, jmnode, iur, iuc, ilc, ilr, 
	    numoff, isr, nmoffc, iseq, iseq1, neqn, nodevs, ndiag, iswap, 
	    iequa, macins, lvnim1, lx0, lvn, lynl, lyu, lyl, lx1, lx2, lx3, 
	    lx4, lx5, lx6, lx7, ld0, ld1, ltd, imynl, imvn, lcvn, nsnod, 
	    nsmat, nsval, icnod, icmat, icval, loutpt, lpol, lzer, irswpf, 
	    irswpr, icswpf, icswpr, irpt, jcpt, irowno, jcolno, nttbr, nttar, 
	    lvntmp;
} tabinf_;

#define tabinf_1 tabinf_

struct {
    doublereal twopi, xlog2, xlog10, root2, rad, boltz, charge, ctok, gmin, 
	    reltol, abstol, vntol, trtol, chgtol, eps0, epssil, epsox, pivtol,
	     pivrel;
} knstnt_;

#define knstnt_1 knstnt_

struct {
    integer locate[50], jelcnt[50], nunods, ncnods, numnod, nstop, nut, nlt, 
	    nxtrm, ndist, ntlin, ibr, numvs, numalt, numcyc;
} cirdat_;

#define cirdat_1 cirdat_

struct {
    doublereal omega, time, delta, delold[7], ag[7], vt, xni, egfet, xmu, 
	    sfactr;
    integer mode, modedc, icalc, initf, method, iord, maxord, noncon, iterno, 
	    itemno, nosolv, modac, ipiv, ivmflg, ipostp, iscrch, iofile;
} status_;

#define status_1 status_

struct {
    doublereal atime, aprog[3], adate, atitle[10], defl, defw, defad, defas, 
	    rstats[50];
    integer iwidth, lwidth, nopage;
} miscel_;

#define miscel_1 miscel_

struct {
    integer iprnta, iprntl, iprntm, iprntn, iprnto, limtim, limpts, lvlcod, 
	    lvltim, itl1, itl2, itl3, itl4, itl5, itl6, igoof, nogo, keof;
} flags_;

#define flags_1 flags_

struct {
    doublereal value[200000];
} blank_;

#define blank_1 blank_

/* Table of constant values */

static integer c__1 = 1;

/*<       subroutine iter8(itlim) >*/
/* Subroutine */ int iter8_(itlim)
integer *itlim;
{
    /* Format strings */
    static char fmt_301[] = "(\0020warning:  underflow occurred \002,i4,\002\
 time(s)\002)";

    /* System generated locals */
    integer i_1;
    doublereal d_1, d_2;

    /* Builtin functions */
    integer s_wsfe(), do_fio(), e_wsfe();

    /* Local variables */
    extern /* Subroutine */ int load_();
    static doublereal vold, vnew;
    extern /* Subroutine */ int copy8_();
    static integer i, j, k;
    extern /* Subroutine */ int dcsol_();
    static integer ipass, ntemp;
    extern /* Subroutine */ int dcdcmp_();
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    static integer ndrflo;
    extern /* Subroutine */ int sizmem_();
    static integer nic;
    static doublereal tol;

    /* Fortran I/O blocks */
    static cilist io__13 = { 0, 0, 0, fmt_301, 0 };


/*<       implicit double precision (a-h,o-z) >*/

/*     this routine drives the newton-raphson iteration technique used to 
*/
/* solve the set of nonlinear circuit equations. */

/* spice version 2g.6  sccsid=tabinf 3/15/83 */
/*<       common /tabinf/ ielmnt,isbckt,nsbckt,iunsat,nunsat,itemps,numtem, >*/
/*<      1   isens,nsens,ifour,nfour,ifield,icode,idelim,icolum,insize, >*/
/*<      2   junode,lsbkpt,numbkp,iorder,jmnode,iur,iuc,ilc,ilr,numoff,isr, >*/
/*<      3   nmoffc,iseq,iseq1,neqn,nodevs,ndiag,iswap,iequa,macins,lvnim1, >*/
/*<      4   lx0,lvn,lynl,lyu,lyl,lx1,lx2,lx3,lx4,lx5,lx6,lx7,ld0,ld1,ltd, >*/
/*<      5   imynl,imvn,lcvn,nsnod,nsmat,nsval,icnod,icmat,icval, >*/
/*<      6   loutpt,lpol,lzer,irswpf,irswpr,icswpf,icswpr,irpt,jcpt, >*/
/*<      7   irowno,jcolno,nttbr,nttar,lvntmp >*/
/* spice version 2g.6  sccsid=knstnt 3/15/83 */
/*<       common /knstnt/ twopi,xlog2,xlog10,root2,rad,boltz,charge,ctok, >*/
/*<      1   gmin,reltol,abstol,vntol,trtol,chgtol,eps0,epssil,epsox, >*/
/*<      2   pivtol,pivrel >*/
/* spice version 2g.6  sccsid=cirdat 3/15/83 */
/*<       common /cirdat/ locate(50),jelcnt(50),nunods,ncnods,numnod,nstop, >*/
/*<      1   nut,nlt,nxtrm,ndist,ntlin,ibr,numvs,numalt,numcyc >*/
/* spice version 2g.6  sccsid=status 3/15/83 */
/*<       common /status/ omega,time,delta,delold(7),ag(7),vt,xni,egfet, >*/
/*<      1   xmu,sfactr,mode,modedc,icalc,initf,method,iord,maxord,noncon, >*/
/*<      2   iterno,itemno,nosolv,modac,ipiv,ivmflg,ipostp,iscrch,iofile >*/
/* spice version 2g.6  sccsid=miscel 3/15/83 */
/*<       common /miscel/ atime,aprog(3),adate,atitle(10),defl,defw,defad, >*/
/*<      1  defas,rstats(50),iwidth,lwidth,nopage >*/
/* spice version 2g.6  sccsid=flags 3/15/83 */
/*<       common /flags/ iprnta,iprntl,iprntm,iprntn,iprnto,limtim,limpts, >*/
/*<      1   lvlcod,lvltim,itl1,itl2,itl3,itl4,itl5,itl6,igoof,nogo,keof >*/
/* spice version 2g.6  sccsid=blank 3/15/83 */
/*<       common /blank/ value(200000) >*/
/*<       integer nodplc(64) >*/
/*<       complex cvalue(32) >*/
/*<       equivalence (value(1),nodplc(1),cvalue(1)) >*/


/*<       igoof=0 >*/
    flags_1.igoof = 0;
/*<       iterno=0 >*/
    status_1.iterno = 0;
/*<       ndrflo=0 >*/
    ndrflo = 0;
/*<       noncon=0 >*/
    status_1.noncon = 0;
/*<       ipass=0 >*/
    ipass = 0;

/*  construct linear equations and check convergence */

/*<    10 ivmflg=0 >*/
L10:
    status_1.ivmflg = 0;
/*<       call load >*/
    load_();
/*<    15 if ((mode.eq.1).and.(modedc.eq.2).and.(nosolv.ne.0)) go to 300 >*/
/* L15: */
    if (status_1.mode == 1 && status_1.modedc == 2 && status_1.nosolv != 0) {
	goto L300;
    }
/*<       iterno=iterno+1 >*/
    ++status_1.iterno;
/*<       go to (20,30,40,60,50,60),initf >*/
    switch (status_1.initf) {
	case 1:  goto L20;
	case 2:  goto L30;
	case 3:  goto L40;
	case 4:  goto L60;
	case 5:  goto L50;
	case 6:  goto L60;
    }
/*<    20 if(mode.ne.1) go to 22 >*/
L20:
    if (status_1.mode != 1) {
	goto L22;
    }
/*<       call sizmem(nsnod,nic) >*/
    sizmem_(&tabinf_1.nsnod, &nic);
/*<       if (nic.eq.0) go to 22 >*/
    if (nic == 0) {
	goto L22;
    }
/*<       if (ipass.ne.0) noncon=ipass >*/
    if (ipass != 0) {
	status_1.noncon = ipass;
    }
/*<       ipass=0 >*/
    ipass = 0;
/*<    22 if (noncon.eq.0) go to 300 >*/
L22:
    if (status_1.noncon == 0) {
	goto L300;
    }
/*<       go to 100 >*/
    goto L100;
/*<    30 initf=3 >*/
L30:
    status_1.initf = 3;
/*<       if(lvlcod.eq.3) lvlcod=2 >*/
    if (flags_1.lvlcod == 3) {
	flags_1.lvlcod = 2;
    }
/*<       ipiv=1 >*/
    status_1.ipiv = 1;
/*<    40 if (noncon.eq.0) initf=1 >*/
L40:
    if (status_1.noncon == 0) {
	status_1.initf = 1;
    }
/*<       ipass=1 >*/
    ipass = 1;
/*<       go to 100 >*/
    goto L100;
/*<    50 if (iterno.gt.1) go to 60 >*/
L50:
    if (status_1.iterno > 1) {
	goto L60;
    }
/*<       ipiv=1 >*/
    status_1.ipiv = 1;
/*<       if (lvlcod.eq.3) lvlcod=2 >*/
    if (flags_1.lvlcod == 3) {
	flags_1.lvlcod = 2;
    }
/*<    60 initf=1 >*/
L60:
    status_1.initf = 1;

/*  solve equations for next iteration */

/*<   100 if (iterno.ge.itlim) go to 200 >*/
L100:
    if (status_1.iterno >= *itlim) {
	goto L200;
    }
/*<   102 call dcdcmp >*/
L102:
    dcdcmp_();
/*<       if (igoof.ne.0) go to 400 >*/
    if (flags_1.igoof != 0) {
	goto L400;
    }
/*<       if (lvlcod.eq.1) go to 105 >*/
    if (flags_1.lvlcod == 1) {
	goto L105;
    }
/*<   105 call dcsol >*/
L105:
    dcsol_();
/*<       go to 120 >*/
    goto L120;
/*<   120 if (igoof.eq.0) go to 130 >*/
L120:
    if (flags_1.igoof == 0) {
	goto L130;
    }
/*<       igoof=0 >*/
    flags_1.igoof = 0;
/*<       if (lvlcod.ne.1) lvlcod=2 >*/
    if (flags_1.lvlcod != 1) {
	flags_1.lvlcod = 2;
    }
/*<       ipiv=1 >*/
    status_1.ipiv = 1;
/*<       call load >*/
    load_();
/*<       go to 102 >*/
    goto L102;
/*<   130 value(lvn+1)=0.0d0 >*/
L130:
    blank_1.value[tabinf_1.lvn] = 0.;
/*<       do 135 i=1,nstop >*/
    i_1 = cirdat_1.nstop;
    for (i = 1; i <= i_1; ++i) {
/*<       j=nodplc(icswpr+i) >*/
	j = nodplc[tabinf_1.icswpr + i - 1];
/*<       k=nodplc(irswpf+j) >*/
	k = nodplc[tabinf_1.irswpf + j - 1];
/*<       value(lvntmp+k)=value(lvnim1+i) >*/
	blank_1.value[tabinf_1.lvntmp + k - 1] = blank_1.value[
		tabinf_1.lvnim1 + i - 1];
/*<   135 continue >*/
/* L135: */
    }
/*<       call copy8(value(lvntmp+1),value(lvnim1+1),nstop) >*/
    copy8_(&blank_1.value[tabinf_1.lvntmp], &blank_1.value[tabinf_1.lvnim1], &
	    cirdat_1.nstop);
/*<       ntemp=noncon >*/
    ntemp = status_1.noncon;
/*<       noncon=0 >*/
    status_1.noncon = 0;
/*<       if (ntemp.gt.0) go to 150 >*/
    if (ntemp > 0) {
	goto L150;
    }
/*<       if (iterno.eq.1) go to 150 >*/
    if (status_1.iterno == 1) {
	goto L150;
    }
/*<       do 140 i=2,numnod >*/
    i_1 = cirdat_1.numnod;
    for (i = 2; i <= i_1; ++i) {
/*<       vold=value(lvnim1+i) >*/
	vold = blank_1.value[tabinf_1.lvnim1 + i - 1];
/*<       vnew=value(lvn+i) >*/
	vnew = blank_1.value[tabinf_1.lvn + i - 1];
/*<       tol=reltol*dmax1(dabs(vold),dabs(vnew))+vntol >*/
/* Computing MAX */
	d_1 = abs(vold), d_2 = abs(vnew);
	tol = knstnt_1.reltol * max(d_2,d_1) + knstnt_1.vntol;
/*<       if (dabs(vold-vnew).le.tol) go to 140 >*/
	if ((d_1 = vold - vnew, abs(d_1)) <= tol) {
	    goto L140;
	}
/*<       noncon=noncon+1 >*/
	++status_1.noncon;
/*<   140 continue >*/
L140:
    ;}
/*<   150 do 160 i=1,nstop >*/
L150:
    i_1 = cirdat_1.nstop;
    for (i = 1; i <= i_1; ++i) {
/*<       j=nodplc(icswpr+i) >*/
	j = nodplc[tabinf_1.icswpr + i - 1];
/*<       k=nodplc(irswpf+j) >*/
	k = nodplc[tabinf_1.irswpf + j - 1];
/*<       value(lvnim1+i)=value(lvn+k) >*/
	blank_1.value[tabinf_1.lvnim1 + i - 1] = blank_1.value[tabinf_1.lvn + 
		k - 1];
/*<   160 continue >*/
/* L160: */
    }
/*     write(iofile,151) (value(lvn+k),k=1,nstop) */
/* 151 format(' solution: '/1p12d10.3) */
/*<       go to 10 >*/
    goto L10;

/*  no convergence */

/*<   200 igoof=1 >*/
L200:
    flags_1.igoof = 1;
/*<   300 if (ndrflo.eq.0) go to 400 >*/
L300:
    if (ndrflo == 0) {
	goto L400;
    }
/*<       write (iofile,301) ndrflo >*/
    io__13.ciunit = status_1.iofile;
    s_wsfe(&io__13);
    do_fio(&c__1, (char *)&ndrflo, (ftnlen)sizeof(integer));
    e_wsfe();
/*<   301 format('0warning:  underflow occurred ',i4,' time(s)') >*/

/*  finished */

/*<   400 return >*/
L400:
    return 0;
/*<       end >*/
} /* iter8_ */

#undef cvalue
#undef nodplc


