/*
   Copyright © 1998 Norlinvest Ltd. All rights reserved.
   Visual Code Model Generator, EDSpice, EDWin, EE Designer, CompCAD,
   CAD 1000, CAD ABC and Visionics are trade marks of Norlinvest Ltd.
   Copyright © 1983 - 1998.

   Copyright 1990 Regents of the University of California.
*/

#ifndef CKT

   #define CKT "CKTdefs.h $Revision: 1.13 $  on $Date: 89/04/05 13:09:39 $ "

   #include "EVT.h"
   #include "ENH.h"

   #define MAXNUMDEVS 32
   #define MAXNUMDEVNODES 4

   extern int DEVmaxnum;

   #include "smpdefs.h"
   #include "ifsim.h"
   #include "acdefs.h"
   #include "gendefs.h"
   #include "trcvdefs.h"
   #include "optdefs.h"
   #include "sen2defs.h"
   #include "pzdefs.h"
   #include "tempanal.h"

   typedef struct sCKTnode
   {
      #define SP_VOLTAGE 3
      #define SP_CURRENT 4
      #define NODE_VOLTAGE SP_VOLTAGE
      #define NODE_CURRENT SP_CURRENT

      IFuid            name;
      int              type,
                       number;
      double           ic,
                       nodeset,
                      *ptr;
      struct sCKTnode *next;
      unsigned int     icGiven : 1;
      unsigned int     nsGiven : 1;
   } CKTnode;

   #define PARM_NS 1
   #define PARM_IC 2
   #define PARM_NODETYPE 3

   typedef struct
   {
      #define NODENAME(ckt, nodenum) CKTnodName(ckt, nodenum)

      #define CKTstate0 CKTstates[0]
      #define CKTstate1 CKTstates[1]
      #define CKTstate2 CKTstates[2]
      #define CKTstate3 CKTstates[3]
      #define CKTstate4 CKTstates[4]
      #define CKTstate5 CKTstates[5]
      #define CKTstate6 CKTstates[6]
      #define CKTstate7 CKTstates[7]

      #define INITF 0x3F00

      #define MODE            0x000003
      #define MODETRAN        0x000001
      #define MODEAC          0x000002
      #define MODEDC          0x000070
      #define MODEDCOP        0x000010
      #define MODETRANOP      0x000020
      #define MODEDCTRANCURVE 0x000040
      #define MODEINITFLOAT   0x000100
      #define MODEINITJCT     0x000200
      #define MODEINITFIX     0x000400
      #define MODEINITSMSIG   0x000800
      #define MODEINITTRAN    0x001000
      #define MODEINITPRED    0x002000
      #define MODEUIC         0x10000l

      #define NISHOULDREORDER   0x001
      #define NIREORDERED       0x002
      #define NIUNINITIALIZED   0x004
      #define NIACSHOULDREORDER 0x010
      #define NIACREORDERED     0x020
      #define NIACUNINITIALIZED 0x040
      #define NIDIDPREORDER     0x100
      #define NIPZSHOULDREORDER 0x200

      #define GEAR        2
      #define TRAPEZOIDAL 1
      
      GENmodel   **CKThead;
      STATistics  *CKTstat;
      double      *(CKTstates[8]),
                   CKTtime,
                   CKTdelta,
                   CKTdeltaOld[7],
                   CKTtemp,
                   CKTnomTemp,
                   CKTvt,
                   CKTag[7];

      #ifdef PREDICTOR
         double CKTagp[7];
      #endif

      int        CKTorder,
                 CKTmaxOrder,
                 CKTintegrateMethod;
      SMPmatrix *CKTmatrix;
      int        CKTniState;
      double    *CKTrhs,
                *CKTrhsOld,
                *CKTrhsSpare,
                *CKTirhs,
                *CKTirhsOld,
                *CKTirhsSpare;

      #ifdef PREDICTOR
         double *CKTpred,
                *CKTsols[8];
      #endif

      double  *CKTrhsOp,
              *CKTsenRhs,
              *CKTseniRhs;
      int      CKTmaxEqNum,
               CKTcurrentAnalysis;
      CKTnode *CKTnodes,
              *CKTlastNode;
      int      CKTnumStates;
      long     CKTmode;
      int      CKTbypass,
               CKTdcMaxIter,
               CKTdcTrcvMaxIter,
               CKTtranMaxIter,
               CKTbreakSize,
               CKTbreak;
      double   CKTsaveDelta,
               CKTminBreak,
              *CKTbreaks,
               CKTabstol,
               CKTpivotAbsTol,
               CKTpivotRelTol,
               CKTreltol,
               CKTchgtol,
               CKTvoltTol;

      #ifdef NEWTRUNC
         double CKTlteReltol,
                CKTlteAbstol;
      #endif

      double          CKTgmin,
                      CKTdelmin,
                      CKTtrtol,
                      CKTfinalTime,
                      CKTstep,
                      CKTmaxStep,
                      CKTinitTime,
                      CKTomega,
                      CKTsrcFact,
                      CKTdiagGmin;
      int             CKTnumSrcSteps,
                      CKTnumGminSteps,
                      CKTnoncon;
      double          CKTdefaultMosL,
                      CKTdefaultMosW,
                      CKTdefaultMosAD,
                      CKTdefaultMosAS;
      unsigned int    CKThadNodeset : 1,
                      CKTfixLimit   : 1,
                      CKTnoOpIter   : 1,
                      CKTisSetup    : 1;
      JOB            *CKTcurJob;
      SENstruct      *CKTsenInfo;
      double         *CKTtimePoints,
                     *CKTdeltaList;
      int             CKTtimeListSize,
                      CKTtimeIndex,
                      CKTsizeIncr;
      unsigned int    CKTtryToCompact : 1,
                      CKTbadMos3      : 1,
                      CKTkeepOpInfo   : 1;
      int             CKTtroubleNode;
      GENinstance    *CKTtroubleElt;
      TEMP           *CKTTempAnal;
      Evt_Ckt_Data_t *evt,
                     *enh;
   } CKTcircuit;

   #ifdef __STDC__

      int      ACan(CKTcircuit*, int);
      int      ACaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      ACsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      CKTacDump(CKTcircuit*, double, GENERIC*);
      int      CKTacLoad(CKTcircuit*);
      int      CKTaccept(CKTcircuit*);
      int      CKTacct(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      CKTask(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTaskAnalQ(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTaskNodQst(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTbindNode(GENERIC*, GENERIC*, int, GENERIC*);
      void     CKTbreakDump(CKTcircuit*);
      int      CKTclrBreak(CKTcircuit*);
      int      CKTconvTest(CKTcircuit*);
      int      CKTcrtElt(GENERIC*, GENERIC*, GENERIC**, IFuid);
      int      CKTdelTask(GENERIC*, GENERIC*);
      int      CKTdestroy(GENERIC*);
      int      CKTdltAnal(GENERIC*, GENERIC*, GENERIC*);
      int      CKTdltInst(GENERIC*, GENERIC*);
      int      CKTdltMod(GENERIC*, GENERIC*);
      int      CKTdltNod(GENERIC*, GENERIC*);
      int      CKTdoJob(GENERIC*, int, GENERIC*);
      void     CKTdump(CKTcircuit*, double, GENERIC*);
      int      CKTfndAnal(GENERIC*, int*, GENERIC**, IFuid, GENERIC*, IFuid);
      int      CKTfndBranch(CKTcircuit*, IFuid);
      int      CKTfndDev(GENERIC*, int*, GENERIC**, IFuid, GENERIC*, IFuid);
      int      CKTfndMod(GENERIC*, int*, GENERIC**, IFuid);
      int      CKTfndNode(GENERIC*, GENERIC**, IFuid);
      int      CKTfndTask(GENERIC*, GENERIC**, IFuid);
      int      CKTground(GENERIC*, GENERIC**, IFuid);
      int      CKTic(CKTcircuit*);
      int      CKTinit(GENERIC**);
      int      CKTinst2Node(GENERIC*, GENERIC*, int, GENERIC**, IFuid*);
      int      CKTlinkEq(CKTcircuit*, CKTnode*);
      int      CKTload(CKTcircuit*);
      int      CKTmapNode(GENERIC*, GENERIC**, IFuid);
      int      CKTmkCur(CKTcircuit*, CKTnode**, IFuid, char*);
      int      CKTmkNode(CKTcircuit*, CKTnode**);
      int      CKTmkVolt(CKTcircuit*, CKTnode**, IFuid, char*);
      int      CKTmodAsk(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTmodCrt(GENERIC*, int, GENERIC**, IFuid);
      int      CKTmodParam(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTnames(CKTcircuit*, int*, IFuid**);
      int      CKTnewAnal(GENERIC*, int, IFuid, GENERIC**, GENERIC*);
      int      CKTnewEq(GENERIC*, GENERIC**, IFuid);
      int      CKTnewNode(GENERIC*, GENERIC**, IFuid);
      int      CKTnewTask(GENERIC*, GENERIC**, IFuid);
      IFuid    CKTnodName(CKTcircuit*, int);
      void     CKTnodOut(CKTcircuit*);
      CKTnode *CKTnum2nod( CKTcircuit*, int);
      int      CKTop(CKTcircuit*, long, long, int);
      int      CKTpModName(char*, IFvalue*, CKTcircuit*, int, IFuid, GENmodel**);
      int      CKTpName(char*, IFvalue*, CKTcircuit*, int, char*, GENinstance**);
      int      CKTparam(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTpzFindZeros(CKTcircuit*, PZtrial**, int*);
      int      CKTpzLoad(CKTcircuit*, SPcomplex*);
      int      CKTpzSetup(CKTcircuit*, int);
      int      CKTsenAC(CKTcircuit*);
      int      CKTsenComp(CKTcircuit*);
      int      CKTsenDCtran(CKTcircuit*);
      int      CKTsenLoad(CKTcircuit*);
      void     CKTsenPrint(CKTcircuit*);
      int      CKTsenSetup(CKTcircuit*);
      int      CKTsenUpdate(CKTcircuit*);
      int      CKTsetAnalPm(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTsetBreak(CKTcircuit*, double);
      int      CKTsetNodPm(GENERIC*, GENERIC*, int, IFvalue*, IFvalue*);
      int      CKTsetOpt(GENERIC*, GENERIC*, int, IFvalue*);
      int      CKTsetup(CKTcircuit*);
      int      CKTtemp(CKTcircuit*);
      char    *CKTtrouble(GENERIC*, char*);
      void     CKTterr(int, CKTcircuit*, double*);
      int      CKTtrunc(CKTcircuit*, double*);
      int      CKTtypelook(char*);
      int      DCOaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      DCOsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      DCTaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      DCTsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      DCop(CKTcircuit*);
      int      DCtrCurv(CKTcircuit*, int);
      int      DCtran(CKTcircuit*, int);
      int      DISTOan(CKTcircuit*, int);
      int      NIacIter(CKTcircuit*);
      int      NIcomCof(CKTcircuit*); 
      int      NIconvTest(CKTcircuit*);
      void     NIdestroy(CKTcircuit*);
      int      NIinit( CKTcircuit*);
      int      NIintegrate(CKTcircuit*, double*, double*, double, int);
      int      NIiter(CKTcircuit*, int);
      int      NIpzMuller(PZtrial**, PZtrial*);
      int      NIpzComplex(PZtrial**, PZtrial*);
      int      NIpzSym(PZtrial**, PZtrial*);
      int      NIpzSym2(PZtrial**, PZtrial*);
      int      NIreinit(CKTcircuit*);
      int      NIsenReinit(CKTcircuit*);
      int      NOISEan(CKTcircuit*, int);
      int      PZan(CKTcircuit*, int);
      int      PZinit(CKTcircuit*);
      int      PZpost(CKTcircuit*);
      int      PZaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      PZsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      SENaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      void     SENdestroy(SENstruct*);
      int      SENsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      SENstartup(CKTcircuit*);
      int      SPIinit(IFfrontEnd*, IFsimulator**);
      char    *SPerror(int);
      int      TFanal(CKTcircuit*, int);
      int      TFaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      TFsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      TRANaskQuest(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      TRANsetParm(CKTcircuit*, GENERIC*, int, IFvalue*);
      int      TRANinit(CKTcircuit*, JOB*);
   #else
      int      ACan();
      int      ACaskQuest();
      int      ACsetParm();
      int      CKTacDump();
      int      CKTacLoad();
      int      CKTaccept();
      int      CKTacct();
      int      CKTask();
      int      CKTaskAnalQ();
      int      CKTaskNodQst();
      int      CKTbindNode();
      void     CKTbreakDump();
      int      CKTclrBreak();
      int      CKTcrtElt();
      int      CKTdelTask();
      int      CKTdestroy();
      int      CKTdltAnal();
      int      CKTdltInst();
      int      CKTdltMod();
      int      CKTdltNod();
      int      CKTdoJob();
      void     CKTdump();
      int      CKTfndAnal();
      int      CKTfndBranch();
      int      CKTfndDev();
      int      CKTfndMod();
      int      CKTfndNode();
      int      CKTfndTask();
      int      CKTground();
      int      CKTic();
      int      CKTinit();
      int      CKTinst2Node();
      int      CKTlinkEq();
      int      CKTload();
      int      CKTmapNode();
      int      CKTmkCur();
      int      CKTmkNode();
      int      CKTmkVolt();
      int      CKTmodAsk();
      int      CKTmodCrt();
      int      CKTmodParam();
      int      CKTnames();
      int      CKTnewAnal();
      int      CKTnewEq();
      int      CKTnewNode();
      int      CKTnewTask();
      IFuid    CKTnodName();
      void     CKTnodOut();
      CKTnode *CKTnum2nod();
      int      CKTop();
      int      CKTpModName();
      int      CKTpName();
      int      CKTparam();
      int      CKTpzLoad();
      int      CKTpzSetup();
      int      CKTsenAC();
      int      CKTsenComp();
      int      CKTsenDCtran();
      int      CKTsenLoad();
      void     CKTsenPrint();
      int      CKTsenSetup();
      int      CKTsenUpdate();
      int      CKTsetAnalPm();
      int      CKTsetBreak();
      int      CKTsetNodPm();
      int      CKTsetOpt();
      int      CKTsetup();
      int      CKTpzSetup();
      int      CKTtemp();
      char    *CKTtrouble( );
      void     CKTterr();
      int      CKTtrunc();
      int      CKTtypelook();
      int      DCOaskQuest();
      int      DCOsetParm();
      int      DCTaskQuest();
      int      DCTsetParm();
      int      DCop();
      int      DCtrCurv();
      int      DCtran();
      int      DISTOan();
      int      NIacIter();
      int      NIcomCof(); 
      int      NIconvTest();
      void     NIdestroy();
      int      NIinit();
      int      NIintegrate();
      int      NIiter();
      int      NIpzMuller();
      int      NIpzSolve();
      int      NIreinit();
      int      NIsenReinit();
      int      NOISEan();
      int      PZan();
      int      PZaskQuest();
      int      PZsetParm();
      int      SENaskQuest();
      void     SENdestroy();
      int      SENsetParm();
      int      SENstartup();
      int      SPIinit();
      char    *SPerror();
      int      TFanal();
      int      TFaskQuest();
      int      TFsetParm();
      int      TRANaskQuest();
      int      TRANsetParm();
      int      TRANinit( );

   #endif

   extern IFfrontEnd *SPfrontEnd;

#endif
