Jspice3
inpgmod.c File Reference
#include "spice.h"
#include "inpdefs.h"
#include "misc.h"
Include dependency graph for inpgmod.c:

Go to the source code of this file.

Functions

char * INPgetMod (GENERIC *ckt, char *name, INPmodel **model, INPtables *tab)
 

Variables

INPmodelmodtab
 

Function Documentation

char* INPgetMod ( GENERIC ckt,
char *  name,
INPmodel **  model,
INPtables tab 
)

Definition at line 15 of file inpgmod.c.

21 {
22  INPmodel *modtmp;
23  IFvalue *val;
24  int j;
25  char *line;
26  char *parm;
27  char *err = NULL;
28  char *temp;
29  int error;
30 
31  for (modtmp = modtab; modtmp != (INPmodel *)NULL;
32  modtmp = ((modtmp)->INPnextModel)) {
33  if (strcmp((modtmp)->INPmodName,name))
34  continue;
35 
36  /* found the model in question - now instantiate if necessary
37  * and return an appropriate pointer to it
38  */
39  if (modtmp->INPmodType < 0) {
40  /* illegal device type, so can't handle */
41  *model = (INPmodel *)NULL;
42  err = (char *)tmalloc((35+strlen(name)) * sizeof(char));
43  (void) sprintf(err,
44  "Unknown device type for model %s.",name);
45  return (err);
46  }
47  if (! ((modtmp)->INPmodUsed )) {
48  /* not already defined, so create & give parameters */
49  error = (*(ft_sim->newModel))( ckt,(modtmp)->INPmodType,
50  &((modtmp)->INPmodfast), (modtmp)->INPmodName);
51  if (error)
52  return (INPerror(error));
53 
54  /* parameter isolation, identification, binding */
55  line = ((modtmp)->INPmodLine)->line;
56  INPgetTok(&line,&parm,1); /* throw away '.model' */
57  txfree(parm);
58  INPgetTok(&line,&parm,1); /* throw away 'modname' */
59  txfree(parm);
60  INPgetTok(&line,&parm,1);
61  while (*parm != '\0') {
62  for (j = 0;
63  j < (*(*(ft_sim->devices)[(modtmp)->INPmodType]).
64  numModelParms); j++) {
65  if (strcmp(parm,((*(ft_sim->devices) [ (modtmp)->
66  INPmodType ]).modelParms[j].keyword)) == 0) {
67  val = INPgetValue(ckt,&line,
68  ((*(ft_sim->devices)[(modtmp)->
69  INPmodType ]).modelParms[j].
70  dataType),tab);
71  error = (*(ft_sim->setModelParm))(ckt,
72  ((modtmp)->INPmodfast),
73  (*(ft_sim->devices)[(modtmp)->INPmodType]).
74  modelParms[j].id,val,(IFvalue*)NULL);
75  if (error) {
76  txfree(parm);
77  return (INPerror(error));
78  }
79  break;
80  }
81  }
82  if (strcmp(parm,"level") == 0) {
83  /* just grab the level number and throw away */
84  /* since we already have that info from pass1 */
85  val = INPgetValue(ckt,&line,IF_REAL,tab);
86  }
87  else if (j >=
88  (*(*(ft_sim->devices)[(modtmp)->INPmodType]).
89  numModelParms)) {
90  temp = (char *)tmalloc((40+strlen(parm)) * sizeof(char));
91  (void)sprintf(temp,
92  "Unrecognized parameter (%s) - ignored.", parm);
93  err = INPerrCat(err,temp);
94  }
95  txfree(parm);
96  INPgetTok(&line,&parm,1);
97  }
98  txfree(parm);
99  (modtmp)->INPmodUsed = 1;
100  (modtmp)->INPmodLine->error = err;
101  }
102  *model = modtmp;
103  return ((char *)NULL);
104  }
105 
106  /* didn't find model - ERROR - return model */
107  *model = (INPmodel *)NULL;
108  err = (char *)tmalloc((60+strlen(name)) * sizeof(char));
109  (void) sprintf(err,
110  "Unable to find definition of model %s - default assumed.",name);
111  return (err);
112 }
char * INPerror()
IFsimulator * ft_sim
Definition: main.c:111
IFvalue * INPgetValue()
int INPmodType
Definition: inpdefs.h:73
char * tmalloc()
Definition: fteinp.h:14
IFdevice ** devices
Definition: ifsim.h:461
void txfree()
#define NULL
Definition: spdefs.h:121
#define IF_REAL
Definition: ifsim.h:108
INPmodel * modtab
Definition: inpmkmod.c:13
Definition: mfb.h:383
char * INPerrCat()
int INPgetTok()

Variable Documentation

INPmodel* modtab

Definition at line 13 of file inpmkmod.c.