/* reordr.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__1 = 1;

/*<       subroutine reordr >*/
/* Subroutine */ int reordr_()
{
    /* Format strings */
    static char fmt_591[] = "(\0020*abort*:  spice internal error in reord\
r\002/)";

    /* System generated locals */
    integer i_1;

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

    /* Local variables */
    static integer node, locx, node1, node2;
    extern /* Subroutine */ int getm4_(), copy4_();
    static integer i, j, l, nflag, nodex, ltemp, nextv, ix;
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    extern /* Subroutine */ int swapij_();
    static integer loc;

    /* Fortran I/O blocks */
    static cilist io__16 = { 0, 0, 0, fmt_591, 0 };


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

/*     this routine swaps rows in the coefficient matrix to eliminate */
/* singularity problems which can be recognized by examining the circuit 
*/
/* topology. */

/* 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)) >*/

/*  allocate and initialize storage */

/*<       call getm4(irswpf,nstop) >*/
    getm4_(&tabinf_1.irswpf, &cirdat_1.nstop);
/*<       call getm4(irswpr,nstop) >*/
    getm4_(&tabinf_1.irswpr, &cirdat_1.nstop);
/*<       call getm4(icswpf,nstop) >*/
    getm4_(&tabinf_1.icswpf, &cirdat_1.nstop);
/*<       call getm4(icswpr,nstop) >*/
    getm4_(&tabinf_1.icswpr, &cirdat_1.nstop);

/*<       do 10 i=1,nstop >*/
    i_1 = cirdat_1.nstop;
    for (i = 1; i <= i_1; ++i) {
/*<       nodplc(irswpf+i)=i >*/
	nodplc[tabinf_1.irswpf + i - 1] = i;
/*<    10 continue >*/
/* L10: */
    }
/*<       call copy4(nodplc(irswpf+1),nodplc(irswpr+1),nstop) >*/
    copy4_(&nodplc[tabinf_1.irswpf], &nodplc[tabinf_1.irswpr], &
	    cirdat_1.nstop);
/*<       call copy4(nodplc(irswpf+1),nodplc(icswpf+1),nstop) >*/
    copy4_(&nodplc[tabinf_1.irswpf], &nodplc[tabinf_1.icswpf], &
	    cirdat_1.nstop);
/*<       call copy4(nodplc(irswpf+1),nodplc(icswpr+1),nstop) >*/
    copy4_(&nodplc[tabinf_1.irswpf], &nodplc[tabinf_1.icswpr], &
	    cirdat_1.nstop);

/*  swap current equations into admittance part of equation matrix */

/*<       nextv=1 >*/
    nextv = 1;

/*  find suitable voltage source */

/*<   100 if (nextv.gt.numvs) go to 600 >*/
L100:
    if (nextv > cirdat_1.numvs) {
	goto L600;
    }
/*<       ix=0 >*/
    ix = 0;
/*<       do 130 i=nextv,numvs >*/
    i_1 = cirdat_1.numvs;
    for (i = nextv; i <= i_1; ++i) {
/*<       loc=nodplc(iseq+i) >*/
	loc = nodplc[tabinf_1.iseq + i - 1];
/*<       node=nodplc(loc+2) >*/
	node = nodplc[loc + 1];
/*<       nflag=nodplc(iseq1+i) >*/
	nflag = nodplc[tabinf_1.iseq1 + i - 1];
/*<       if (nflag.eq.1) node=nodplc(loc+6) >*/
	if (nflag == 1) {
	    node = nodplc[loc + 5];
	}
/*<       if (nflag.eq.2) node=nodplc(loc+7) >*/
	if (nflag == 2) {
	    node = nodplc[loc + 6];
	}
/*<       if (node.eq.1) go to 110 >*/
	if (node == 1) {
	    goto L110;
	}
/*<       if (nodplc(nodevs+node).ge.2) go to 110 >*/
	if (nodplc[tabinf_1.nodevs + node - 1] >= 2) {
	    goto L110;
	}
/*<       if (nodplc(ndiag+node).eq.0) go to 145 >*/
	if (nodplc[tabinf_1.ndiag + node - 1] == 0) {
	    goto L145;
	}
/*<       ix=i >*/
	ix = i;
/*<       locx=loc >*/
	locx = loc;
/*<       nodex=node >*/
	nodex = node;
/*<   110 node=nodplc(loc+3) >*/
L110:
	node = nodplc[loc + 2];
/*<       if (nflag.eq.2) node=nodplc(loc+5) >*/
	if (nflag == 2) {
	    node = nodplc[loc + 4];
	}
/*<       if (node.eq.1) go to 130 >*/
	if (node == 1) {
	    goto L130;
	}
/*<       if (nodplc(nodevs+node).ge.2) go to 130 >*/
	if (nodplc[tabinf_1.nodevs + node - 1] >= 2) {
	    goto L130;
	}
/*<   120 if (nodplc(ndiag+node).eq.0) go to 145 >*/
/* L120: */
	if (nodplc[tabinf_1.ndiag + node - 1] == 0) {
	    goto L145;
	}
/*<       ix=i >*/
	ix = i;
/*<       locx=loc >*/
	locx = loc;
/*<       nodex=node >*/
	nodex = node;
/*<   130 continue >*/
L130:
    ;}
/*<       if (ix.eq.0) go to 590 >*/
    if (ix == 0) {
	goto L590;
    }
/*<       i=ix >*/
    i = ix;
/*<       loc=locx >*/
    loc = locx;
/*<       node=nodex >*/
    node = nodex;

/*  resequence voltage sources */

/*<   145 nodplc(iseq+i)=nodplc(iseq+nextv) >*/
L145:
    nodplc[tabinf_1.iseq + i - 1] = nodplc[tabinf_1.iseq + nextv - 1];
/*<       nodplc(iseq+nextv)=loc >*/
    nodplc[tabinf_1.iseq + nextv - 1] = loc;
/*<       ltemp=nodplc(iseq1+i) >*/
    ltemp = nodplc[tabinf_1.iseq1 + i - 1];
/*<       nodplc(iseq1+i)=nodplc(iseq1+nextv) >*/
    nodplc[tabinf_1.iseq1 + i - 1] = nodplc[tabinf_1.iseq1 + nextv - 1];
/*<       nodplc(iseq1+nextv)=ltemp >*/
    nodplc[tabinf_1.iseq1 + nextv - 1] = ltemp;
/*<       ibr=nodplc(neqn+i) >*/
    cirdat_1.ibr = nodplc[tabinf_1.neqn + i - 1];
/*<       nodplc(neqn+i)=nodplc(neqn+nextv) >*/
    nodplc[tabinf_1.neqn + i - 1] = nodplc[tabinf_1.neqn + nextv - 1];
/*<       nodplc(neqn+nextv)=ibr >*/
    nodplc[tabinf_1.neqn + nextv - 1] = cirdat_1.ibr;
/*<       node1=nodplc(loc+2) >*/
    node1 = nodplc[loc + 1];
/*<       if (ltemp.eq.1) node1=nodplc(loc+6) >*/
    if (ltemp == 1) {
	node1 = nodplc[loc + 5];
    }
/*<       if (ltemp.eq.2) node1=nodplc(loc+7) >*/
    if (ltemp == 2) {
	node1 = nodplc[loc + 6];
    }
/*<       node2=nodplc(loc+3) >*/
    node2 = nodplc[loc + 2];
/*<       if (ltemp.eq.1) node2=nodplc(loc+3) >*/
    if (ltemp == 1) {
	node2 = nodplc[loc + 2];
    }
/*<       if (ltemp.eq.2) node2=nodplc(loc+5) >*/
    if (ltemp == 2) {
	node2 = nodplc[loc + 4];
    }
/*<       nodplc(nodevs+node1)=nodplc(nodevs+node1)-1 >*/
    --nodplc[tabinf_1.nodevs + node1 - 1];
/*<       nodplc(nodevs+node2)=nodplc(nodevs+node2)-1 >*/
    --nodplc[tabinf_1.nodevs + node2 - 1];

/*  set row swap indicators */

/*<       l=nodplc(irswpf+ibr) >*/
    l = nodplc[tabinf_1.irswpf + cirdat_1.ibr - 1];
/*<       j=nodplc(irswpr+node) >*/
    j = nodplc[tabinf_1.irswpr + node - 1];
/*<       nodplc(irswpf+j)=l >*/
    nodplc[tabinf_1.irswpf + j - 1] = l;
/*<       nodplc(irswpr+l)=j >*/
    nodplc[tabinf_1.irswpr + l - 1] = j;
/*<       nodplc(irswpf+ibr)=node >*/
    nodplc[tabinf_1.irswpf + cirdat_1.ibr - 1] = node;
/*<       nodplc(irswpr+node)=ibr >*/
    nodplc[tabinf_1.irswpr + node - 1] = cirdat_1.ibr;
/*<       call swapij(ibr,j,1,1) >*/
    swapij_(&cirdat_1.ibr, &j, &c__1, &c__1);
/*<       nextv=nextv+1 >*/
    ++nextv;
/*<       go to 100 >*/
    goto L100;


/*  error - voltage-source/inductor/transmission-line loop detected ... */


/*<   590 nogo=1 >*/
L590:
    flags_1.nogo = 1;
/*<       write (iofile,591) >*/
    io__16.ciunit = status_1.iofile;
    s_wsfe(&io__16);
    e_wsfe();
/* ...  loop should have been detected in topchk */
/*<   591 format('0*abort*:  spice internal error in reordr'/) >*/

/*  finished */

/*<   600 return >*/
L600:
    return 0;
/*<       end >*/
} /* reordr_ */

#undef cvalue
#undef nodplc


