/* sstf.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 {
    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 {
    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 tcstar[2], tcstop[2], tcincr[2];
    integer icvflg, itcelm[2], kssop, kinel, kidin, kovar, kidout;
} dc_;

#define dc_1 dc_

struct {
    doublereal value[200000];
} blank_;

#define blank_1 blank_

/* Table of constant values */

static integer c__1 = 1;
static integer c__3 = 3;
static integer c__8 = 8;
static integer c__5 = 5;

/*<       subroutine sstf >*/
/* Subroutine */ int sstf_()
{
    /* Initialized data */

    static struct {
	char e_1[8];
	doublereal e_2;
	} equiv_24 = { {'/', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0. };

#define aslash (*(doublereal *)&equiv_24)

    static struct {
	char e_1[8];
	doublereal e_2;
	} equiv_25 = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0. };

#define ablnk (*(doublereal *)&equiv_25)


    /* Format strings */
    static char fmt_231[] = "(////,\0020****     small-signal characteristic\
s\002//,\0020\002,5x,5a8,\002 = \002,1pd10.3,/,\0020\002,5x,\002input resist\
ance at \002,a8,12x,\002 = \002,d10.3,/,\0020\002,5x,\002output resistance a\
t \002,2a8,a3,\002 = \002,d10.3)";

    /* System generated locals */
    integer i_1;

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

    /* Local variables */
    static doublereal anam, save[3];
    static integer locv;
    extern /* Subroutine */ int move_();
    static doublereal trfn;
    static integer ipos;
    static doublereal zout;
    extern /* Subroutine */ int copy8_(), zero8_();
    static integer i, j, k;
    static doublereal creal;
    extern /* Subroutine */ int dcsol_();
    static integer iptri, iptro;
    extern /* Subroutine */ int dcdcmp_();
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    static doublereal string[5];
    static integer noposi, nonegi, noposo, nonego;
    extern /* Subroutine */ int outnam_();
    static doublereal zin;

    /* Fortran I/O blocks */
    static cilist io__23 = { 0, 0, 0, fmt_231, 0 };


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

/*     this routine computes the value of the small-signal transfer */
/* function specified by the user. */

/* 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=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=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=dc 3/15/83 */
/*<       common /dc/ tcstar(2),tcstop(2),tcincr(2),icvflg,itcelm(2),kssop, >*/
/*<      1   kinel,kidin,kovar,kidout >*/
/* 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)) >*/


/*<       dimension string(5),save(3) >*/
/*<       data aslash, ablnk / 1h/, 1h  / >*/

/*  setup current vector for input resistance and transfer function */

/*<       call zero8(value(lvn+1),nstop) >*/
    zero8_(&blank_1.value[tabinf_1.lvn], &cirdat_1.nstop);
/*<       if (kidin.eq.10) go to 5 >*/
    if (dc_1.kidin == 10) {
	goto L5;
    }
/* ...  voltage source input */
/*<       iptri=nodplc(kinel+6) >*/
    iptri = nodplc[dc_1.kinel + 5];
/*<       value(lvn+iptri)=+1.0d0 >*/
    blank_1.value[tabinf_1.lvn + iptri - 1] = 1.;
/*<       go to 20 >*/
    goto L20;
/* ...  current source input */
/*<     5 noposi=nodplc(kinel+2) >*/
L5:
    noposi = nodplc[dc_1.kinel + 1];
/*<       nonegi=nodplc(kinel+3) >*/
    nonegi = nodplc[dc_1.kinel + 2];
/*<       value(lvn+noposi)=-1.0d0 >*/
    blank_1.value[tabinf_1.lvn + noposi - 1] = -1.;
/*<       value(lvn+nonegi)=+1.0d0 >*/
    blank_1.value[tabinf_1.lvn + nonegi - 1] = 1.;

/*  lu decompose and solve the system of circuit equations */

/* ...  reorder the right-hand side */
/*<    20 call dcdcmp >*/
L20:
    dcdcmp_();
/*<       call dcsol >*/
    dcsol_();
/*<       value(lvn+1)=0.0d0 >*/
    blank_1.value[tabinf_1.lvn] = 0.;
/*<       do 25 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+i)=value(lvn+k) >*/
	blank_1.value[tabinf_1.lvntmp + i - 1] = blank_1.value[tabinf_1.lvn + 
		k - 1];
/*<    25 continue >*/
/* L25: */
    }
/*<       call copy8(value(lvntmp+1),value(lvn+1),nstop) >*/
    copy8_(&blank_1.value[tabinf_1.lvntmp], &blank_1.value[tabinf_1.lvn], &
	    cirdat_1.nstop);

/*  evaluate transfer function */

/*<       if (nodplc(kovar+5).ne.0) go to 30 >*/
    if (nodplc[dc_1.kovar + 4] != 0) {
	goto L30;
    }
/* ...  voltage output */
/*<       noposo=nodplc(kovar+2) >*/
    noposo = nodplc[dc_1.kovar + 1];
/*<       nonego=nodplc(kovar+3) >*/
    nonego = nodplc[dc_1.kovar + 2];
/*<       trfn=value(lvn+noposo)-value(lvn+nonego) >*/
    trfn = blank_1.value[tabinf_1.lvn + noposo - 1] - blank_1.value[
	    tabinf_1.lvn + nonego - 1];
/*<       go to 40 >*/
    goto L40;
/* ...  current output (through voltage source) */
/*<    30 iptro=nodplc(kovar+2) >*/
L30:
    iptro = nodplc[dc_1.kovar + 1];
/*<       iptro=nodplc(iptro+6) >*/
    iptro = nodplc[iptro + 5];
/*<       trfn=value(lvn+iptro) >*/
    trfn = blank_1.value[tabinf_1.lvn + iptro - 1];

/*  evaluate input resistance */

/*<    40 if (kidin.eq.9) go to 50 >*/
L40:
    if (dc_1.kidin == 9) {
	goto L50;
    }
/* ...  current source input */
/*<       zin=value(lvn+nonegi)-value(lvn+noposi) >*/
    zin = blank_1.value[tabinf_1.lvn + nonegi - 1] - blank_1.value[
	    tabinf_1.lvn + noposi - 1];
/*<       go to 70 >*/
    goto L70;
/* ...  voltage source input */
/*<    50 creal=value(lvn+iptri) >*/
L50:
    creal = blank_1.value[tabinf_1.lvn + iptri - 1];
/*<       if (dabs(creal).ge.1.0d-20) go to 60 >*/
    if (abs(creal) >= 1e-20) {
	goto L60;
    }
/*<       zin=1.0d20 >*/
    zin = 1e20;
/*<       go to 70 >*/
    goto L70;
/*<    60 zin=-1.0d0/creal >*/
L60:
    zin = -1. / creal;

/*  setup current vector for output resistance */

/*<    70 call zero8(value(lvn+1),nstop) >*/
L70:
    zero8_(&blank_1.value[tabinf_1.lvn], &cirdat_1.nstop);
/*<       if (nodplc(kovar+5).ne.0) go to 80 >*/
    if (nodplc[dc_1.kovar + 4] != 0) {
	goto L80;
    }
/* ...  voltage output */
/*<       value(lvn+noposo)=-1.0d0 >*/
    blank_1.value[tabinf_1.lvn + noposo - 1] = -1.;
/*<       value(lvn+nonego)=+1.0d0 >*/
    blank_1.value[tabinf_1.lvn + nonego - 1] = 1.;
/*<       go to 90 >*/
    goto L90;
/*<    80 if (nodplc(kovar+2).ne.kinel) go to 85 >*/
L80:
    if (nodplc[dc_1.kovar + 1] != dc_1.kinel) {
	goto L85;
    }
/*<       zout=zin >*/
    zout = zin;
/*<       go to 200 >*/
    goto L200;
/* ...  current output (through voltage source) */
/*<    85 value(lvn+iptro)=+1.0d0 >*/
L85:
    blank_1.value[tabinf_1.lvn + iptro - 1] = 1.;

/*  perform new forward and backward substitution */

/* ...  reorder the right-hand side */
/*<    90 call dcsol >*/
L90:
    dcsol_();
/*<       value(lvn+1)=0.0d0 >*/
    blank_1.value[tabinf_1.lvn] = 0.;
/*<       do 95 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+i)=value(lvn+k) >*/
	blank_1.value[tabinf_1.lvntmp + i - 1] = blank_1.value[tabinf_1.lvn + 
		k - 1];
/*<    95 continue >*/
/* L95: */
    }
/*<       call copy8(value(lvntmp+1),value(lvn+1),nstop) >*/
    copy8_(&blank_1.value[tabinf_1.lvntmp], &blank_1.value[tabinf_1.lvn], &
	    cirdat_1.nstop);

/*  evaluate output resistance */

/*<   100 if (nodplc(kovar+5).ne.0) go to 110 >*/
/* L100: */
    if (nodplc[dc_1.kovar + 4] != 0) {
	goto L110;
    }
/* ...  voltage output */
/*<       zout=value(lvn+nonego)-value(lvn+noposo) >*/
    zout = blank_1.value[tabinf_1.lvn + nonego - 1] - blank_1.value[
	    tabinf_1.lvn + noposo - 1];
/*<       go to 200 >*/
    goto L200;
/* ...  current output (through voltage source) */
/*<   110 creal=value(lvn+iptro) >*/
L110:
    creal = blank_1.value[tabinf_1.lvn + iptro - 1];
/*<       if (dabs(creal).ge.1.0d-20) go to 120 >*/
    if (abs(creal) >= 1e-20) {
	goto L120;
    }
/*<       zout=1.0d20 >*/
    zout = 1e20;
/*<       go to 200 >*/
    goto L200;
/*<   120 zout=-1.0d0/creal >*/
L120:
    zout = -1. / creal;

/*  print results */

/*<   200 do 210 i=1,5 >*/
L200:
    for (i = 1; i <= 5; ++i) {
/*<       string(i)=ablnk >*/
	string[i - 1] = ablnk;
/*<   210 continue >*/
/* L210: */
    }
/*<       ipos=1 >*/
    ipos = 1;
/*<       call outnam(kovar,1,string,ipos) >*/
    outnam_(&dc_1.kovar, &c__1, string, &ipos);
/*<       call copy8(string,save,3) >*/
    copy8_(string, save, &c__3);
/*<       call move(string,ipos,aslash,1,1) >*/
    move_(string, &ipos, &aslash, &c__1, &c__1);
/*<       ipos=ipos+1 >*/
    ++ipos;
/*<       locv=nodplc(kinel+1) >*/
    locv = nodplc[dc_1.kinel];
/*<       anam=value(locv) >*/
    anam = blank_1.value[locv - 1];
/*<       call move(string,ipos,anam,1,8) >*/
    move_(string, &ipos, &anam, &c__1, &c__8);
/*<       write (iofile,231) string,trfn,anam,zin,save,zout >*/
    io__23.ciunit = status_1.iofile;
    s_wsfe(&io__23);
    do_fio(&c__5, (char *)&string[0], (ftnlen)sizeof(doublereal));
    do_fio(&c__1, (char *)&trfn, (ftnlen)sizeof(doublereal));
    do_fio(&c__1, (char *)&anam, (ftnlen)sizeof(doublereal));
    do_fio(&c__1, (char *)&zin, (ftnlen)sizeof(doublereal));
    do_fio(&c__3, (char *)&save[0], (ftnlen)sizeof(doublereal));
    do_fio(&c__1, (char *)&zout, (ftnlen)sizeof(doublereal));
    e_wsfe();
/*<   231 format(////,'0****     small-signal characteristics'//, >*/
/*<      1   1h0,5x,5a8,3h = ,1pd10.3,/, >*/
/*<      2   1h0,5x,'input resistance at ',a8,12x,3h = ,d10.3,/, >*/
/*<      3   1h0,5x,'output resistance at ',2a8,a3,3h = ,d10.3) >*/
/*<       return >*/
    return 0;
/*<       end >*/
} /* sstf_ */

#undef cvalue
#undef nodplc
#undef ablnk
#undef aslash


