/* subckt.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 value[200000];
} blank_;

#define blank_1 blank_

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_

/* Table of constant values */

static integer c__20 = 20;
static integer c__1 = 1;

/*<       subroutine subckt >*/
/* Subroutine */ int subckt_()
{
    /* Format strings */
    static char fmt_251[] = "(\0020*error*:  \002,a8,\002 has different numb\
er of nodes than \002,a8/)";
    static char fmt_261[] = "(\0020*error*:  subcircuit \002,a8,\002 is defi\
ned recursively\002/)";

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

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

    /* Local variables */
    extern /* Subroutine */ int find_();
    static integer loce, locx, locs, locv;
    extern /* Subroutine */ int getm4_(), copy4_();
    static doublereal asnam;
    static integer inodi;
    static doublereal axnam;
    static integer itemp, nxnod, inodx, locsv, id;
    extern /* Subroutine */ int addelt_(), fndnam_();
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    static integer isbptr;
    extern /* Subroutine */ int sizmem_();
    static integer nssnod;
    extern /* Subroutine */ int clrmem_();
    static integer loc;

    /* Fortran I/O blocks */
    static cilist io__17 = { 0, 0, 0, fmt_251, 0 };
    static cilist io__19 = { 0, 0, 0, fmt_261, 0 };


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

/*     this routine drives the expansion of subcircuit calls. */

/* 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=blank 3/15/83 */
/*<       common /blank/ value(200000) >*/
/* 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 >*/
/*<       integer nodplc(64) >*/
/*<       complex cvalue(32) >*/
/*<       equivalence (value(1),nodplc(1),cvalue(1)) >*/


/* ... avoid 'call by value' problems, make inodi, inodx arrays */
/* ... in routines which receive them as parameters ]]] */
/*<       locx=locate(19) >*/
    locx = cirdat_1.locate[18];
/*<    10 if (locx.eq.0) go to 300 >*/
L10:
    if (locx == 0) {
	goto L300;
    }
/*<       locs=nodplc(locx+3) >*/
    locs = nodplc[locx + 2];
/*<       asnam=value(iunsat+locs) >*/
    asnam = blank_1.value[tabinf_1.iunsat + locs - 1];
/*<       call fndnam(asnam,locx-1,locx+3,20) >*/
    i_1 = locx - 1;
    i_2 = locx + 3;
    fndnam_(&asnam, &i_1, &i_2, &c__20);
/*<       if (nogo.ne.0) go to 300 >*/
    if (flags_1.nogo != 0) {
	goto L300;
    }
/*<       locs=nodplc(locx+3) >*/
    locs = nodplc[locx + 2];

/*  check for recursion */

/*<       isbptr=nodplc(locx-1) >*/
    isbptr = nodplc[locx - 2];
/*<    20 if (isbptr.eq.0) go to 30 >*/
L20:
    if (isbptr == 0) {
	goto L30;
    }
/*<       if (locs.eq.nodplc(isbptr+3)) go to 260 >*/
    if (locs == nodplc[isbptr + 2]) {
	goto L260;
    }
/*<       isbptr=nodplc(isbptr-1) >*/
    isbptr = nodplc[isbptr - 2];
/*<       go to 20 >*/
    goto L20;


/*<    30 call sizmem(nodplc(locx+2),nxnod) >*/
L30:
    sizmem_(&nodplc[locx + 1], &nxnod);
/*<       call sizmem(nodplc(locs+2),nssnod) >*/
    sizmem_(&nodplc[locs + 1], &nssnod);
/*<       if (nxnod.ne.nssnod) go to 250 >*/
    if (nxnod != nssnod) {
	goto L250;
    }
/*<       call getm4(inodx,nssnod) >*/
    getm4_(&inodx, &nssnod);
/*<       call getm4(inodi,nssnod) >*/
    getm4_(&inodi, &nssnod);
/*<       itemp=nodplc(locs+2) >*/
    itemp = nodplc[locs + 1];
/*<       call copy4(nodplc(itemp+1),nodplc(inodx+1),nssnod) >*/
    copy4_(&nodplc[itemp], &nodplc[inodx], &nssnod);
/*<       itemp=nodplc(locx+2) >*/
    itemp = nodplc[locx + 1];
/*<       call copy4(nodplc(itemp+1),nodplc(inodi+1),nxnod) >*/
    copy4_(&nodplc[itemp], &nodplc[inodi], &nxnod);

/*  add elements of subcircuit to nominal circuit */

/*<       loc=nodplc(locs+3) >*/
    loc = nodplc[locs + 2];
/*<   100 if (loc.eq.0) go to 200 >*/
L100:
    if (loc == 0) {
	goto L200;
    }
/*<       id=nodplc(loc-1) >*/
    id = nodplc[loc - 2];
/*<       if (id.eq.20) go to 110 >*/
    if (id == 20) {
	goto L110;
    }
/*<       call find(dble(jelcnt(id)),id,loce,1) >*/
    d_1 = (doublereal) cirdat_1.jelcnt[id - 1];
    find_(&d_1, &id, &loce, &c__1);
/*<       nodplc(loce-1)=locx >*/
    nodplc[loce - 2] = locx;
/*<       call addelt(loce,loc,id,inodx,inodi,nxnod) >*/
    addelt_(&loce, &loc, &id, &inodx, &inodi, &nxnod);
/*<   110 loc=nodplc(loc) >*/
L110:
    loc = nodplc[loc - 1];
/*<       go to 100 >*/
    goto L100;


/*<   200 call clrmem(inodx) >*/
L200:
    clrmem_(&inodx);
/*<       call clrmem(inodi) >*/
    clrmem_(&inodi);
/*<       locx=nodplc(locx) >*/
    locx = nodplc[locx - 1];
/*<       go to 10 >*/
    goto L10;

/*  errors */

/*<   250 locv=nodplc(locx+1) >*/
L250:
    locv = nodplc[locx];
/*<       axnam=value(locv) >*/
    axnam = blank_1.value[locv - 1];
/*<       locv=nodplc(locs+1) >*/
    locv = nodplc[locs];
/*<       asnam=value(locv) >*/
    asnam = blank_1.value[locv - 1];
/*<       write (iofile,251) axnam,asnam >*/
    io__17.ciunit = status_1.iofile;
    s_wsfe(&io__17);
    do_fio(&c__1, (char *)&axnam, (ftnlen)sizeof(doublereal));
    do_fio(&c__1, (char *)&asnam, (ftnlen)sizeof(doublereal));
    e_wsfe();
/*<   251 format('0*error*:  ',a8,' has different number of nodes than ',a8/ >*/
/*<      1) >*/
/*<       nogo=1 >*/
    flags_1.nogo = 1;
/*<       go to 300 >*/
    goto L300;
/*<   260 locsv=nodplc(locs+1) >*/
L260:
    locsv = nodplc[locs];
/*<       asnam=value(locsv) >*/
    asnam = blank_1.value[locsv - 1];
/*<       write (iofile,261) asnam >*/
    io__19.ciunit = status_1.iofile;
    s_wsfe(&io__19);
    do_fio(&c__1, (char *)&asnam, (ftnlen)sizeof(doublereal));
    e_wsfe();
/*<   261 format('0*error*:  subcircuit ',a8,' is defined recursively'/) >*/
/*<       nogo=1 >*/
    flags_1.nogo = 1;

/*  finished */

/*<   300 return >*/
L300:
    return 0;
/*<       end >*/
} /* subckt_ */

#undef cvalue
#undef nodplc


