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

#define blank_1 blank_

/* Subroutine */ int acasol_()
{
    /* System generated locals */
    integer i_1, i_2;
    doublereal d_1, d_2;
    complex q_1;

    /* Local variables */
    extern /* Subroutine */ int cdiv_();
    static integer iord, jord;
    extern /* Subroutine */ int copy8_();
    static integer i, j, k;
    static doublereal ximag;
    static integer locnn;
    static doublereal xreal;
    extern /* Subroutine */ int cmult_();
    extern integer indxx_();
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    static integer loc;


/*     this routine evaluates the response of the adjoint circuit by */
/* doing a forward/backward substitution step using the transpose of the 
*/
/* circuit equation coefficient matrix. */

/* spice version 2g.6  sccsid=tabinf 3/15/83 */
/* spice version 2g.6  sccsid=cirdat 3/15/83 */
/* spice version 2g.6  sccsid=blank 3/15/83 */

/*  evaluates adjoint response by doing forward/backward substitution on 
*/
/*  the transpose of the y matrix */

/*  forward substitution */

    i_1 = cirdat_1.nstop;
    for (i = 2; i <= i_1; ++i) {
	loc = i;
	iord = nodplc[tabinf_1.icswpf + i - 1];
L10:
	loc = nodplc[tabinf_1.irpt + loc - 1];
	if (nodplc[tabinf_1.irowno + loc - 1] >= i) {
	    goto L15;
	}
	j = nodplc[tabinf_1.irowno + loc - 1];
	jord = nodplc[tabinf_1.icswpf + j - 1];
	cmult_(&blank_1.value[tabinf_1.lynl + loc - 1], &blank_1.value[
		tabinf_1.imynl + loc - 1], &blank_1.value[tabinf_1.lvn + jord 
		- 1], &blank_1.value[tabinf_1.imvn + jord - 1], &xreal, &
		ximag);
	blank_1.value[tabinf_1.lvn + iord - 1] -= xreal;
	blank_1.value[tabinf_1.imvn + iord - 1] -= ximag;
	goto L10;
L15:
	jord = nodplc[tabinf_1.irswpf + i - 1];
	locnn = indxx_(&jord, &iord);
	cdiv_(&blank_1.value[tabinf_1.lvn + iord - 1], &blank_1.value[
		tabinf_1.imvn + iord - 1], &blank_1.value[tabinf_1.lynl + 
		locnn - 1], &blank_1.value[tabinf_1.imynl + locnn - 1], &
		blank_1.value[tabinf_1.lvn + iord - 1], &blank_1.value[
		tabinf_1.imvn + iord - 1]);
/* L20: */
    }

/*  backward substitution */

    i = cirdat_1.nstop;
L30:
    --i;
    if (i <= 1) {
	goto L60;
    }
    iord = nodplc[tabinf_1.icswpf + i - 1];
    loc = i;
L35:
    loc = nodplc[tabinf_1.irpt + loc - 1];
/* L40: */
    if (nodplc[tabinf_1.irowno + loc - 1] != i) {
	goto L35;
    }
L50:
    loc = nodplc[tabinf_1.irpt + loc - 1];
    if (loc == 0) {
	goto L30;
    }
    j = nodplc[tabinf_1.irowno + loc - 1];
    jord = nodplc[tabinf_1.icswpf + j - 1];
    cmult_(&blank_1.value[tabinf_1.lynl + loc - 1], &blank_1.value[
	    tabinf_1.imynl + loc - 1], &blank_1.value[tabinf_1.lvn + jord - 1]
	    , &blank_1.value[tabinf_1.imvn + jord - 1], &xreal, &ximag);
    blank_1.value[tabinf_1.lvn + iord - 1] -= xreal;
    blank_1.value[tabinf_1.imvn + iord - 1] -= ximag;
    goto L50;

/*  reorder solution vector */

L60:
    i_1 = cirdat_1.nstop;
    for (i = 1; i <= i_1; ++i) {
	j = nodplc[tabinf_1.irswpr + i - 1];
	k = nodplc[tabinf_1.icswpf + j - 1];
	blank_1.value[tabinf_1.ndiag + i - 1] = blank_1.value[tabinf_1.lvn + 
		k - 1];
	blank_1.value[tabinf_1.ndiag + i + cirdat_1.nstop - 1] = 
		blank_1.value[tabinf_1.imvn + k - 1];
/* L70: */
    }
    copy8_(&blank_1.value[tabinf_1.ndiag], &blank_1.value[tabinf_1.lvn], &
	    cirdat_1.nstop);
    copy8_(&blank_1.value[tabinf_1.ndiag + 1 + cirdat_1.nstop - 1], &
	    blank_1.value[tabinf_1.imvn], &cirdat_1.nstop);
    i_1 = cirdat_1.nstop;
    for (i = 2; i <= i_1; ++i) {
	i_2 = tabinf_1.lcvn + i - 1;
	d_1 = blank_1.value[tabinf_1.lvn + i - 1];
	d_2 = blank_1.value[tabinf_1.imvn + i - 1];
	q_1.r = d_1, q_1.i = d_2;
	cvalue[i_2].r = q_1.r, cvalue[i_2].i = q_1.i;
/* L120: */
    }
    i_1 = tabinf_1.lcvn;
    cvalue[i_1].r = (float)0., cvalue[i_1].i = (float)0.;

/*  finished */

    return 0;
} /* acasol_ */

#undef cvalue
#undef nodplc


