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

#define dc_1 dc_

struct {
    doublereal atime, aprog[3], adate, atitle[10], defl, defw, defad, defas, 
	    rstats[50];
    integer iwidth, lwidth, nopage;
} miscel_;

#define miscel_1 miscel_

struct {
    doublereal value[200000];
} blank_;

#define blank_1 blank_

/* Table of constant values */

static integer c__12 = 12;
static integer c__10 = 10;
static integer c__48 = 48;
static integer c__1 = 1;

/*<       subroutine pheadr(aheadr) >*/
/* Subroutine */ int pheadr_(aheadr)
doublereal *aheadr;
{
    /* Initialized data */

    static struct {
	char e_1[16];
	doublereal e_2;
	} equiv_26 = { {'t', 'i', 'm', 'e', ' ', ' ', ' ', ' ', 'f', 'r', 'e',
		 'q', ' ', ' ', ' ', ' '}, 0. };

#define xtype ((doublereal *)&equiv_26)

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

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

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

#define aletv (*(doublereal *)&equiv_28)

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

#define aleti (*(doublereal *)&equiv_29)


    /* System generated locals */
    integer i_1;

    /* Local variables */
    static doublereal anam;
    static integer info, locv, iknt;
    extern /* Subroutine */ int move_();
    static integer ipos, nwds, ityp;
    extern /* Subroutine */ int getm4_();
    static integer iseq2;
    extern /* Subroutine */ int getm8_(), copy8_();
    static integer i, ibuff, iseqs;
#define nodpl2 ((integer *)&blank_1)
    static integer itype2;
#define nodplc ((integer *)&blank_1)
#define cvalue ((complex *)&blank_1)
    extern /* Subroutine */ int fwrite_();
    static integer numout, inames, itypes;
    extern /* Subroutine */ int alfnum_(), clrmem_();
    static integer loc, int2, int3;

    /* Parameter adjustments */
    --aheadr;

    /* Function Body */
/*<       implicit double precision (a-h,o-z) >*/
/* 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=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=miscel 3/15/83 */
/*<       common /miscel/ atime,aprog(3),adate,atitle(10),defl,defw,defad, >*/
/*<      1  defas,rstats(50),iwidth,lwidth,nopage >*/
/* spice version 2g.6  sccsid=blank 3/15/83 */
/*<       common /blank/ value(200000) >*/
/*<       integer nodplc(64) >*/
/*<       complex cvalue(32) >*/
/* int3 (not used) is strictly for alignment.  f77 on unix craps out. */
/*<       integer int2,int3,nodpl2(128) >*/
/*<       equivalence (value(1),nodpl2(1)) >*/
/*<       equivalence (value(1),nodplc(1),cvalue(1)) >*/
/*<       dimension aheadr(10) >*/

/*  put out the header records onto the post-processing file */
/*  routine is used for all analysis modes (mode=1,2,3) */

/*<       dimension xtype(2) >*/
/*<       data xtype /4htime,4hfreq/ >*/
/*<       data ablnk,aletv,aleti /1h ,1hv,1hi/ >*/

/* file structure for post-processor */

/*record 1  title card (80 bytes), date (8 bytes), time (8 bytes) 
total-96 bytes*/
/* record 2  number of output variables (including "sweep" variable) */
/* record 3  integer '4' (2 bytes) */
/* record 4  names of each output variable (8 bytes ea.) */
/* record 5  type of each output       0-no type */
/*                                     1-time */
/*                                     2-frequency */
/*                                     3-voltage */
/*                                     4-current */
/*                                     5-output noise */
/*                                     6-input noise */
/*                                     7-hd2    | */
/*                                     8-hd3    | */
/*                                     9-dim2   }   distortion outputs */
/*                                    10-sim2   | */
/*                                    11-dim3   | */
/* record 6  the location of each variable within each sweep point. */
/*          (normally just 1,2,3,4,... but needed if outputs are mixed up)
*/
/* record 6a 24 characters that are the plot title if record 3 is a '4'. 
*/
/* record 7  output at first sweep point */
/* record 8  output at second sweep point */
/* record 9  . */
/*           . */
/*           . */
/* last record */


/*<       call getm8(ibuff,12) >*/
    getm8_(&ibuff, &c__12);
/*<       call copy8(aheadr(1),value(ibuff+1),10) >*/
    copy8_(&aheadr[1], &blank_1.value[ibuff], &c__10);
/*<       value(ibuff+11)=adate >*/
    blank_1.value[ibuff + 10] = miscel_1.adate;
/*<       value(ibuff+12)=atime >*/
    blank_1.value[ibuff + 11] = miscel_1.atime;
/*<       call fwrite(value(ibuff+1),48) >*/
    fwrite_(&blank_1.value[ibuff], &c__48);
/*<       numout=nunods+jelcnt(9) >*/
    numout = cirdat_1.nunods + cirdat_1.jelcnt[8];
/* force nused to be allocated by useless usage. */
/*<       int2 = numout >*/
    int2 = numout;
/*<       int3 = numout >*/
    int3 = numout;
/*<       info=4 >*/
    info = 4;
/*<       call getm8(inames,numout) >*/
    getm8_(&inames, &numout);
/*<       call getm4(itypes,numout) >*/
    getm4_(&itypes, &numout);
/*<       call getm4(iseqs,numout) >*/
    getm4_(&iseqs, &numout);
/*<       itype2=itypes*2 >*/
    itype2 = itypes << 1;
/*<       iseq2=iseqs*2 >*/
    iseq2 = iseqs << 1;
/*<       iknt=1 >*/
    iknt = 1;
/*<       nodpl2(iseq2+1)=1 >*/
    nodpl2[iseq2] = 1;

/* dc transfer curve (mode = 1): */

/*<       if(mode.ne.1) go to 10 >*/
    if (status_1.mode != 1) {
	goto L10;
    }
/*<       loc=itcelm(1) >*/
    loc = dc_1.itcelm[0];
/*<       locv=nodplc(loc+1) >*/
    locv = nodplc[loc];
/*<       value(inames+1)=value(locv) >*/
    blank_1.value[inames] = blank_1.value[locv - 1];
/*<       anam=ablnk >*/
    anam = ablnk;
/*<       call move(anam,1,value(locv),1,1) >*/
    move_(&anam, &c__1, &blank_1.value[locv - 1], &c__1, &c__1);
/*<       ityp=0 >*/
    ityp = 0;
/* voltage transfer becomes type 3 and current transfer becomes 4. */
/*<       if(anam.eq.aletv) ityp=3 >*/
    if (anam == aletv) {
	ityp = 3;
    }
/*<       if(anam.eq.aleti) ityp=4 >*/
    if (anam == aleti) {
	ityp = 4;
    }
/*<       nodpl2(itype2+1)=ityp >*/
    nodpl2[itype2] = ityp;
/*<       go to 20 >*/
    goto L20;
/*<    10 value(inames+1)=xtype(mode-1) >*/
L10:
    blank_1.value[inames] = xtype[status_1.mode - 2];
/*<       nodpl2(itype2+1)=mode-1 >*/
    nodpl2[itype2] = status_1.mode - 1;
/*<    20 do 30 i=2,nunods >*/
L20:
    i_1 = cirdat_1.nunods;
    for (i = 2; i <= i_1; ++i) {
/*<       nodpl2(itype2+i)=3 >*/
	nodpl2[itype2 + i - 1] = 3;
/*<       nodpl2(iseq2+i)=i >*/
	nodpl2[iseq2 + i - 1] = i;
/*<       value(inames+i)=ablnk >*/
	blank_1.value[inames + i - 1] = ablnk;
/*<       ipos=1 >*/
	ipos = 1;
/*<       call alfnum(nodplc(junode+i),value(inames+i),ipos) >*/
	alfnum_(&nodplc[tabinf_1.junode + i - 1], &blank_1.value[inames + i - 
		1], &ipos);
/*<    30 continue >*/
/* L30: */
    }
/*<       loc=locate(9) >*/
    loc = cirdat_1.locate[8];
/*<       iknt=nunods >*/
    iknt = cirdat_1.nunods;
/*<    40 if(loc.eq.0) go to 50 >*/
L40:
    if (loc == 0) {
	goto L50;
    }
/*<       iknt=iknt+1 >*/
    ++iknt;
/*<       nodpl2(itype2+iknt)=4 >*/
    nodpl2[itype2 + iknt - 1] = 4;
/*<       nodpl2(iseq2+iknt)=iknt >*/
    nodpl2[iseq2 + iknt - 1] = iknt;
/*<       locv=nodplc(loc+1) >*/
    locv = nodplc[loc];
/*<       value(inames+iknt)=value(locv) >*/
    blank_1.value[inames + iknt - 1] = blank_1.value[locv - 1];
/*<       loc=nodplc(loc) >*/
    loc = nodplc[loc - 1];
/*<       go to 40 >*/
    goto L40;
/*<    50 int2=numout >*/
L50:
    int2 = numout;
/*<       call fwrite(int2,1) >*/
    fwrite_(&int2, &c__1);
/*<       int2=info >*/
    int2 = info;
/*<       call fwrite(int2,1) >*/
    fwrite_(&int2, &c__1);
/*<       nwds=numout*4 >*/
    nwds = numout << 2;
/*<       call fwrite(value(inames+1),nwds) >*/
    fwrite_(&blank_1.value[inames], &nwds);
/*<       call fwrite(nodpl2(itype2+1),numout) >*/
    fwrite_(&nodpl2[itype2], &numout);
/*<       call fwrite(nodpl2(iseq2+1),numout) >*/
    fwrite_(&nodpl2[iseq2], &numout);
/*<       call fwrite(aprog(1),12) >*/
    fwrite_(miscel_1.aprog, &c__12);
/*<       call clrmem(ibuff) >*/
    clrmem_(&ibuff);
/*<       call clrmem(inames) >*/
    clrmem_(&inames);
/*<       call clrmem(itypes) >*/
    clrmem_(&itypes);
/*<       call clrmem(iseqs) >*/
    clrmem_(&iseqs);
/*<       return >*/
    return 0;
/*<       end >*/
} /* pheadr_ */

#undef cvalue
#undef nodplc
#undef nodpl2
#undef aleti
#undef aletv
#undef ablnk
#undef xtype


