Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1988 Thomas L. Quarles
**********/
#include "ngspice/ngspice.h"
#include "ngspice/ifsim.h"
#include "ngspice/inpdefs.h"
#include "ngspice/inpmacs.h"
#include "ngspice/fteext.h"
#include "ngspice/compatmode.h"
#include "inpxx.h"
void INP2C(CKTcircuit *ckt, INPtables * tab, struct card *current)
{
static int mytype = -1;
int type = 0;
char *line;
char *saveline;
char *name;
char *model;
char *nname1;
char *nname2;
CKTnode *node1;
CKTnode *node2;
double val;
int error;
int error1;
INPmodel *thismodel;
GENmodel *mdfast = NULL;
GENinstance *fast = NULL;
IFvalue ptemp;
int waslead;
double leadval;
IFuid uid;
#ifdef TRACE
printf("In INP2C, Current line: %s\n", current->line);
#endif
if (mytype < 0) {
if ((mytype = INPtypelook("Capacitor")) < 0) {
LITERR("Device type Capacitor not supported by this binary\n");
return;
}
}
line = current->line;
INPgetNetTok(&line, &name, 1);
if (*line == '\0') {
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
return;
}
INPgetNetTok(&line, &nname1, 1);
if (*line == '\0') {
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
return;
}
INPgetNetTok(&line, &nname2, 1);
if (*line == '\0') {
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
return;
}
INPinsert(&name, tab);
INPtermInsert(ckt, &nname1, tab, &node1);
INPtermInsert(ckt, &nname2, tab, &node2);
if (newcompat.lt)
val = INPevaluateRKM_C(&line, &error1, 1);
else
val = INPevaluate(&line, &error1, 1);
saveline = line;
INPgetNetTok(&line, &model, 1);
if (*model && (strcmp(model, "c") != 0)) {
if (INPlookMod(model)) {
INPinsert(&model, tab);
current->error = INPgetMod(ckt, model, &thismodel, tab);
if (thismodel != NULL) {
if (mytype != thismodel->INPmodType) {
LITERR("incorrect model type");
return;
}
mdfast = thismodel->INPmodfast;
type = thismodel->INPmodType;
}
} else {
tfree(model);
line = saveline;
type = mytype;
if (!tab->defCmod) {
IFnewUid(ckt, &uid, NULL, "C", UID_MODEL, NULL);
IFC(newModel, (ckt, type, &(tab->defCmod), uid));
}
mdfast = tab->defCmod;
}
IFC(newInstance, (ckt, mdfast, &fast, name));
} else {
tfree(model);
type = mytype;
if (!tab->defCmod) {
IFnewUid(ckt, &uid, NULL, "C", UID_MODEL, NULL);
IFC(newModel, (ckt, type, &(tab->defCmod), uid));
}
IFC(newInstance, (ckt, tab->defCmod, &fast, name));
if (error1 == 1) {
val = INPevaluate(&line, &error1, 1);
#ifdef TRACE
printf ("In INP2C, C=val construction: val=%g\n", val);
#endif
}
}
if (!fast || !fast->GENmodPtr) {
fprintf(stderr, "\nWarning: Instance for capacitor '%s' could not be set up properly, ignored!\n\n", current->line);
return;
}
if (error1 == 0) {
ptemp.rValue = val;
GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast));
}
IFC(bindNode, (ckt, fast, 1, node1));
IFC(bindNode, (ckt, fast, 2, node2));
PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));
if (waslead) {
ptemp.rValue = leadval;
GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast));
}
return;
}