Jspice3
cktsetup.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Thomas L. Quarles
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8  /* CKTsetup(ckt)
9  * this is a driver program to iterate through all the various
10  * setup functions provided for the circuit elements in the
11  * given circuit
12  */
13 
14 #include "spice.h"
15 #include <stdio.h>
16 #include "devdefs.h"
17 #include "sperror.h"
18 #include "util.h"
19 #include "cktext.h"
20 #include "niext.h"
21 
22 
23 #define CKALLOC(var,size,type) \
24  if(size && (!(var =(type *)MALLOC((size)*sizeof(type))))){\
25  return(E_NOMEM);\
26 }
27 
28 
29 int
31 
32 CKTcircuit *ckt;
33 {
34  extern SPICEdev *DEVices[];
35  int i;
36  int error;
37  struct sCKTmodHead *mh;
38  int (*func)();
39  SMPmatrix *matrix;
40 
41 
42  ckt->CKTnumStates = 0;
43  matrix = ckt->CKTmatrix;
44 
45  /* we use the imag part for caching constants */
46  spSetComplex(matrix);
47  spClear(matrix);
48  spSetReal(matrix);
49 
50  for (mh = ckt->CKTheadList; mh != NULL; mh = mh->next) {
51  if ((func = DEVices[mh->type]->DEVsetup) != NULL) {
52  error = (*func)(matrix,mh->head,ckt,&ckt->CKTnumStates);
53  if (error) return (error);
54  }
55  }
56 
57  for (i = 0; i <= ckt->CKTmaxOrder+1; i++) {
58  FREE(ckt->CKTstates[i]);
59  CKALLOC(ckt->CKTstates[i],ckt->CKTnumStates,double);
60  }
61  if (ckt->CKTniState & NIUNINITIALIZED) {
62  error = NIreinit(ckt);
63  if (error) return (error);
64  }
65 
66  return (OK);
67 }
int(* DEVsetup)()
Definition: devdefs.h:93
#define NIUNINITIALIZED
Definition: cktdefs.h:122
struct sCKTmodHead * next
Definition: cktdefs.h:58
SPICEdev * DEVices[]
Definition: sconfig.c:109
#define CKALLOC(var, size, type)
Definition: cktsetup.c:23
#define FREE(ptr)
Definition: spdefs.h:436
int NIreinit()
void spSetReal()
#define OK
Definition: iferrmsg.h:17
#define NULL
Definition: spdefs.h:121
int CKTsetup(CKTcircuit *ckt)
Definition: cktsetup.c:30
void spClear()
Definition: fteparse.h:37
void spSetComplex()
int type
Definition: cktdefs.h:56
GENmodel * head
Definition: cktdefs.h:57
#define SMPmatrix
Definition: smpdefs.h:11