Jspice3
resparse.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1987 Thomas L. Quarles
5  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include <stdio.h>
10 #include "inpdefs.h"
11 #include "inpmacs.h"
12 
13 void
14 RESparse(type,ckt,tabp,currentp)
15 
16 int type;
17 GENERIC *ckt;
18 GENERIC *tabp;
19 GENERIC *currentp;
20 {
21  /* resistor parser */
22 
23  /* Rname <node> <node> [<model>] [<val>] [w=<val>] [l=<val>] */
24 
25  INPtables *tab = (INPtables*)tabp;
26  card *current = (card*)currentp;
27 
28  char *line; /* the part of the current line left to parse */
29  char *name; /* the device's name */
30  char *model; /* the name of the resistor's model */
31  char *nname1; /* the first node's name */
32  char *nname2; /* the second node's name */
33  GENERIC *node1; /* the first node's node pointer */
34  GENERIC *node2; /* the second node's node pointer */
35  double val; /* temp to held resistance */
36  int error; /* error code temporary */
37  int error1; /* secondary error code temporary */
38  INPmodel *thismodel; /* pointer to model structure describing our model */
39  GENERIC *mdfast; /* pointer to the actual model */
40  GENERIC *fast; /* pointer to the actual instance */
41  IFvalue ptemp; /* a value structure to package resistance into */
42  int waslead; /* flag to indicate that unlabeled number was found */
43  double leadval; /* actual value of unlabeled number */
44  IFuid uid; /* uid for default model */
45 
46  line = current->line;
47  INPgetTok(&line,&name,1);
48  INPinsert(&name,tab);
49 
50  INPgetTok(&line,&nname1,1);
51  INPtermInsert(ckt,&nname1,tab,&node1);
52 
53  INPgetTok(&line,&nname2,1);
54  INPtermInsert(ckt,&nname2,tab,&node2);
55 
56  val = INPevaluate(&line,&error1,1);
57  /* either not a number -> model, or
58  * follows a number, so must be a model name
59  * -> MUST be a model name (or null)
60  */
61  INPgetTok(&line,&model,1);
62  if (*model) { /* token isn't null */
63  INPinsert(&model,tab);
64  thismodel = (INPmodel *)NULL;
65  current->error = INPgetMod(ckt,model,&thismodel,tab);
66  if (thismodel != NULL) {
67  if (type != thismodel->INPmodType) {
69  return;
70  }
71  mdfast = thismodel->INPmodfast;
72  type = thismodel->INPmodType;
73  }
74  else {
75  if (!tab->defRmod) {
76  /* create default R model */
77  IFnewUid(ckt,&uid,(IFuid)NULL,"R",UID_MODEL,(GENERIC**)NULL);
78  IFC(newModel, (ckt,type,&(tab->defRmod),uid))
79  }
80  mdfast = tab->defRmod;
81  }
82  IFC(newInstance,(ckt,mdfast,&fast,name))
83  }
84  else {
85  txfree(model);
86  if (!tab->defRmod) {
87  /* create default R model */
88  IFnewUid(ckt,&uid,(IFuid)NULL,"R",UID_MODEL,(GENERIC**)NULL);
89  IFC(newModel, (ckt,type,&(tab->defRmod),uid))
90  }
91  IFC(newInstance,(ckt,tab->defRmod,&fast,name))
92  }
93  if (error1 == 0) { /* got a resistance above */
94  ptemp.rValue = val;
95  GCA(INPpName,("resistance",&ptemp,ckt,type,fast))
96  }
97 
98  IFC(bindNode,(ckt,fast,1,node1))
99  IFC(bindNode,(ckt,fast,2,node2))
100  PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab))
101  if (waslead) {
102  ptemp.rValue = leadval;
103  GCA(INPpName,("resistance",&ptemp,ckt,type,fast))
104  }
105 }
int INPpName()
char * line
Definition: inpdefs.h:64
int INPtermInsert()
int IFnewUid()
Definition: inpdefs.h:62
#define UID_MODEL
Definition: ifsim.h:83
double INPevaluate()
Definition: subckt.c:51
double rValue
Definition: ifsim.h:233
#define LITERR(text)
Definition: inpmacs.h:35
int INPmodType
Definition: inpdefs.h:73
int INPinsert()
Definition: fteinp.h:14
GENERIC * IFuid
Definition: ifsim.h:72
void txfree()
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
#define GCA(func, args)
Definition: inpmacs.h:27
#define IFC(func, args)
Definition: inpmacs.h:19
char * error
Definition: inpdefs.h:65
#define PARSECALL(args)
Definition: inpmacs.h:42
static char model[32]
Definition: subckt.c:76
GENERIC * INPmodfast
Definition: inpdefs.h:77
void RESparse(int type, GENERIC *ckt, GENERIC *tabp, GENERIC *currentp)
Definition: resparse.c:14
GENERIC * defRmod
Definition: inpdefs.h:52
char * INPdevErr()
char GENERIC
Definition: ifsim.h:27
char * INPgetMod()
int INPgetTok()