/* find.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 {
    integer locate[50], jelcnt[50], nunods, ncnods, numnod, nstop, nut, nlt, 
	    nxtrm, ndist, ntlin, ibr, numvs, numalt, numcyc;
} cirdat_;

#define cirdat_1 cirdat_

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 cpyknt;
    integer istack[1], lorg, icore, maxcor, maxuse, memavl, ldval, numblk, 
	    loctab, ltab, ifwa, nwoff, ntab, maxmem, memerr, nwd4, nwd8, 
	    nwd16;
} memmgr_;

#define memmgr_1 memmgr_

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 value[200000];
} blank_;

#define blank_1 blank_

/* Table of constant values */

static integer c__1 = 1;

/*<       subroutine find(aname,id,loc,iforce) >*/
/* Subroutine */ int find_(aname, id, loc, iforce)
doublereal *aname;
integer *id, *loc, *iforce;
{
    /* Initialized data */

    static integer lnod[50] = { 10,14,16,8,15,16,15,16,13,8,18,38,27,35,8,8,
	    35,5,5,5,5,5,5,5,0,0,0,0,0,0,21,21,21,21,21,21,21,21,21,21,8,8,8,
	    8,8,0,0,0,0,0 };
    static integer lval[50] = { 5,4,4,2,1,1,1,1,4,4,3,4,4,16,1,1,9,2,1,1,19,
	    55,17,46,0,0,0,0,0,0,1,1,1,1,1,17,17,17,17,17,1,1,1,1,1,0,0,0,0,0 
	    };
    static struct {
	char e_1[4];
	integer e_2;
	} equiv_16 = { {'.', 'u', ' ', ' '}, 0 };

#define ndefin (*(integer *)&equiv_16)


    /* Format strings */
    static char fmt_26[] = "(\0020*error*:  above line attempts to redefine\
 \002,a8/)";

    /* System generated locals */
    integer i_1;

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

    /* Local variables */
    static doublereal anam;
    static integer locn, loct, locv, ktmp, iptr;
    extern integer xxor_();
    extern /* Subroutine */ int zero4_(), zero8_();
    static integer itemp, isize, nword;
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    extern /* Subroutine */ int sizmem_();
    extern integer nxtevn_();
    extern /* Subroutine */ int extmem_(), undefi_();

    /* Fortran I/O blocks */
    static cilist io__11 = { 0, 0, 0, fmt_26, 0 };


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

/*     this routine searches the list with number 'id' for an element */
/* with name 'aname'.  loc is set to point to the element.  if iforce is 
*/
/* nonzero, then find expects to have to add the element to the list, and 
*/
/* reports a fatal error if the element is found.  if subcircuit defini- 
*/
/* tion is in progress (nonzero value for nsbckt), then find searches the 
*/
/* current subcircuit definition list rather than the nominal element */
/* list. */

/* 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=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=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=memmgr 3/15/83 */
/*<       common /memmgr/ cpyknt,istack(1),lorg,icore,maxcor,maxuse,memavl, >*/
/*<      1   ldval,numblk,loctab,ltab,ifwa,nwoff,ntab,maxmem,memerr,nwd4, >*/
/*<      2   nwd8,nwd16 >*/
/* 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=blank 3/15/83 */
/*<       common /blank/ value(200000) >*/
/*<       integer nodplc(64) >*/
/*<       complex cvalue(32) >*/
/*<       equivalence (value(1),nodplc(1),cvalue(1)) >*/

/*  index to the contents of the various lists: */

/*        list      contents */
/*        ----      -------- */

/*          1       resistors */
/*          2       nonlinear capacitors */
/*          3       nonlinear inductors */
/*          4       mutual inductors */
/*          5       nonlinear voltage controlled current sources */
/*          6       nonlinear voltage controlled voltage sources */
/*          7       nonlinear current controlled current sources */
/*          8       nonlinear current controlled voltage sources */
/*          9       independent voltage sources */
/*         10       independent current sources */
/*         11       diodes */
/*         12       bipolar junction transistors */
/*         13       junction field-effect transistors (jfets) */
/*         14       metal-oxide-semiconductor junction fets (mosfets) */
/*         15       s-parameter 2-port network */
/*         16       y-parameter 2-port network */
/*         17       transmission lines */
/*         18       used for temperature sweeping */
/*         19       subcircuit calls */
/*         20       subcircuit definitions */
/*         21       diode model */
/*         22       bjt model */
/*         23       jfet model */
/*         24       mosfet model */
/*      25-30       <unused> */
/*         31       .print dc */
/*         32       .print tran */
/*         33       .print ac */
/*         34       .print noise */
/*         35       .print distortion */
/*         36       .plot dc */
/*         37       .plot tr */
/*         38       .plot ac */
/*         39       .plot noise */
/*         40       .plot distortion */
/*         41       outputs for dc */
/*         42       outputs for transient */
/*         43       outputs for ac */
/*         44       outputs for noise */
/*         45       outputs for distortion */
/*      46-50       <unused> */

/*<       integer xxor >*/
/*<       dimension lnod(50),lval(50) >*/
/*<       data lnod /10,14,16, 8,15,16,15,16,13, 8, >*/
/*<      1           18,38,27,35, 8, 8,35, 5, 5, 5, >*/
/*<      2            5, 5, 5, 5, 0, 0, 0, 0, 0, 0, >*/
/*<      3           21,21,21,21,21,21,21,21,21,21, >*/
/*<      4            8, 8, 8, 8, 8, 0, 0, 0, 0, 0 / >*/
/*<       data lval / 5, 4, 4, 2, 1, 1, 1, 1, 4, 4, >*/
/*<      1            3, 4, 4,16, 1, 1, 9, 2, 1, 1, >*/
/*<      2           19,55,17,46, 0, 0, 0, 0, 0, 0, >*/
/*<      3            1, 1, 1, 1, 1,17,17,17,17,17, >*/
/*<      4            1, 1, 1, 1, 1, 0, 0, 0, 0, 0 / >*/
/*<       data ndefin /2h.u/ >*/


/*<       anam=aname >*/
    anam = *aname;
/*<       call sizmem(ielmnt,isize) >*/
    sizmem_(&tabinf_1.ielmnt, &isize);
/*<       locn=ielmnt+isize+2 >*/
    locn = tabinf_1.ielmnt + isize + 2;
/*<       if (nsbckt.eq.0) go to 10 >*/
    if (tabinf_1.nsbckt == 0) {
	goto L10;
    }
/*<       loct=nodplc(isbckt+nsbckt) >*/
    loct = nodplc[tabinf_1.isbckt + tabinf_1.nsbckt - 1];
/*<       loc=nodplc(loct+3) >*/
    *loc = nodplc[loct + 2];
/*<       if (loc.ne.0) go to 20 >*/
    if (*loc != 0) {
	goto L20;
    }
/*<       nodplc(loct+3)=locn >*/
    nodplc[loct + 2] = locn;
/*<       go to 60 >*/
    goto L60;
/*<    10 loc=locate(id) >*/
L10:
    *loc = cirdat_1.locate[*id - 1];
/*<       if (loc.ne.0) go to 20 >*/
    if (*loc != 0) {
	goto L20;
    }
/*<       locate(id)=locn >*/
    cirdat_1.locate[*id - 1] = locn;
/*<       go to 50 >*/
    goto L50;

/*  search list for a name match */

/*<    20 locv=nodplc(loc+1) >*/
L20:
    locv = nodplc[*loc];
/*<       if (xxor(anam,value(locv)).ne.0) go to 30 >*/
    if (xxor_(&anam, &blank_1.value[locv - 1]) != 0) {
	goto L30;
    }
/*<       if (numalt.ne.0) go to 30 >*/
    if (cirdat_1.numalt != 0) {
	goto L30;
    }
/*<       if (nsbckt.eq.0) go to 25 >*/
    if (tabinf_1.nsbckt == 0) {
	goto L25;
    }
/*<       if (nodplc(loc-1).ne.id) go to 30 >*/
    if (nodplc[*loc - 2] != *id) {
	goto L30;
    }
/*<    25 if (nodplc(loc+2).eq.ndefin) go to 200 >*/
L25:
    if (nodplc[*loc + 1] == ndefin) {
	goto L200;
    }
/*<       if (iforce.eq.0) go to 200 >*/
    if (*iforce == 0) {
	goto L200;
    }
/*<       write (iofile,26) anam >*/
    io__11.ciunit = status_1.iofile;
    s_wsfe(&io__11);
    do_fio(&c__1, (char *)&anam, (ftnlen)sizeof(doublereal));
    e_wsfe();
/*<    26 format('0*error*:  above line attempts to redefine ',a8/) >*/
/*<       nogo=1 >*/
    flags_1.nogo = 1;
/*<    30 if (nodplc(loc).eq.0) go to 40 >*/
L30:
    if (nodplc[*loc - 1] == 0) {
	goto L40;
    }
/*<       loc=nodplc(loc) >*/
    *loc = nodplc[*loc - 1];
/*<       go to 20 >*/
    goto L20;

/*  reserve space for this element */

/*<    40 nodplc(loc)=locn >*/
L40:
    nodplc[*loc - 1] = locn;
/*<       if (nsbckt.ne.0) go to 60 >*/
    if (tabinf_1.nsbckt != 0) {
	goto L60;
    }
/*<    50 if (numalt.eq.0) jelcnt(id)=jelcnt(id)+1 >*/
L50:
    if (cirdat_1.numalt == 0) {
	++cirdat_1.jelcnt[*id - 1];
    }
/*<    60 loc=locn >*/
L60:
    *loc = locn;
/*<       itemp=loc+lnod(id)*nwd4-1 >*/
    itemp = *loc + lnod[*id - 1] * memmgr_1.nwd4 - 1;
/*<       locv=nxtevn(itemp-1)+1 >*/
    i_1 = itemp - 1;
    locv = nxtevn_(&i_1) + 1;
/*<       itemp=locv-itemp >*/
    itemp = locv - itemp;
/*<       ktmp=lnod(id)*nwd4+lval(id)*nwd8+itemp >*/
    ktmp = lnod[*id - 1] * memmgr_1.nwd4 + lval[*id - 1] * memmgr_1.nwd8 + 
	    itemp;
/*<       call extmem(ielmnt,ktmp) >*/
    extmem_(&tabinf_1.ielmnt, &ktmp);
/*<       locv=(locv-1)/nwd8+1 >*/
    locv = (locv - 1) / memmgr_1.nwd8 + 1;
/*<       iptr=0 >*/
    iptr = 0;
/*<       if (nsbckt.eq.0) go to 80 >*/
    if (tabinf_1.nsbckt == 0) {
	goto L80;
    }
/*<       iptr=id >*/
    iptr = *id;
/*<    80 if (id.le.24) nodplc(loc+lnod(id)-2)=numalt >*/
L80:
    if (*id <= 24) {
	nodplc[*loc + lnod[*id - 1] - 3] = cirdat_1.numalt;
    }
/*<       nodplc(loc-1)=iptr >*/
    nodplc[*loc - 2] = iptr;
/*<       nodplc(loc)=0 >*/
    nodplc[*loc - 1] = 0;
/*<       nodplc(loc+1)=locv >*/
    nodplc[*loc] = locv;
/*<       value(locv)=anam >*/
    blank_1.value[locv - 1] = anam;

/*  background storage */

/*<   100 nodplc(loc+2)=ndefin >*/
/* L100: */
    nodplc[*loc + 1] = ndefin;
/*<       nword=lnod(id)-4 >*/
    nword = lnod[*id - 1] - 4;
/*<       if (id.le.24) nword=nword-1 >*/
    if (*id <= 24) {
	--nword;
    }
/*<       if (nword.lt.1) go to 120 >*/
    if (nword < 1) {
	goto L120;
    }
/*<       call zero4(nodplc(loc+3),nword) >*/
    zero4_(&nodplc[*loc + 2], &nword);
/*<   120 nword=lval(id)-1 >*/
L120:
    nword = lval[*id - 1] - 1;
/*<       if (nword.lt.1) go to 200 >*/
    if (nword < 1) {
	goto L200;
    }
/*<       call zero8(value(locv+1),nword) >*/
    zero8_(&blank_1.value[locv], &nword);
/*<       if ((id.ge.21).and.(id.le.24)) call undefi(value(locv+1),nword) >*/
    if (*id >= 21 && *id <= 24) {
	undefi_(&blank_1.value[locv], &nword);
    }

/*  exit */

/*<   200 return >*/
L200:
    return 0;
/*<       end >*/
} /* find_ */

#undef cvalue
#undef nodplc
#undef ndefin


