Jspice3
ckti2nod.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  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8  /* CKTinst2Node
9  * get the name and node pointer for a node given a device it is
10  * bound to and the terminal of the device.
11  */
12 
13 #include "spice.h"
14 #include <stdio.h>
15 #include "devdefs.h"
16 #include "sperror.h"
17 #include "cktext.h"
18 
19 
20 extern SPICEdev *DEVices[];
21 
22 int
23 CKTinst2Node(ckt,instPtr,term,node,nodeName)
24 
25 GENERIC *ckt;
26 GENERIC *instPtr;
27 int term;
28 GENERIC **node;
29 IFuid *nodeName;
30 {
31  int i, nodenum;
32  CKTnode *here;
33  int type = ((GENinstance *)instPtr)->GENmodPtr->GENmodType;
34  char key = *(char*)((GENinstance *)instPtr)->GENname;
35  IFkeys *keys = DEVices[type]->DEVpublic.keys;
36 
37  for (i = 0; i < *DEVices[type]->DEVpublic.numKeys; i++) {
38  if (keys[i].key == key)
39  break;
40  }
41  if (i == *DEVices[type]->DEVpublic.numKeys)
42  return (E_NOTERM);
43 
44  if (keys[i].numTerms >= term && term > 0) {
45  switch (term) {
46  default:
47  return (E_NOTERM);
48  case 1:
49  nodenum = ((GENinstance *)instPtr)->GENnode1;
50  break;
51  case 2:
52  nodenum = ((GENinstance *)instPtr)->GENnode2;
53  break;
54  case 3:
55  nodenum = ((GENinstance *)instPtr)->GENnode3;
56  break;
57  case 4:
58  nodenum = ((GENinstance *)instPtr)->GENnode4;
59  break;
60  case 5:
61  nodenum = ((GENinstance *)instPtr)->GENnode5;
62  break;
63  }
64  /* ok, now we know its number, so we just have to find it.*/
65  for (here = ((CKTcircuit*)ckt)->CKTnodes; here; here = here->next) {
66  if (here->number == nodenum) {
67  /* found it */
68  *node = (GENERIC*) here;
69  *nodeName = here->name;
70  return (OK);
71  }
72  }
73  return (E_NOTFOUND);
74  }
75  return (E_NOTERM);
76 }
SPICEdev * DEVices[]
Definition: sconfig.c:109
IFkeys * keys
Definition: ifsim.h:297
IFuid name
Definition: cktdefs.h:31
#define E_NOTFOUND
Definition: iferrmsg.h:35
IFdevice DEVpublic
Definition: devdefs.h:44
#define OK
Definition: iferrmsg.h:17
GENERIC * IFuid
Definition: ifsim.h:72
Definition: types.c:18
int CKTinst2Node(GENERIC *ckt, GENERIC *instPtr, int term, GENERIC **node, IFuid *nodeName)
Definition: ckti2nod.c:23
struct sCKTnode * next
Definition: cktdefs.h:43
int number
Definition: cktdefs.h:39
Definition: ifsim.h:267
#define E_NOTERM
Definition: iferrmsg.h:25
int type
Definition: cktdefs.h:56
int * numKeys
Definition: ifsim.h:296
static int nodenum()
char GENERIC
Definition: ifsim.h:27