1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1985 Thomas L. Quarles
4 **********/
5 /*
6  */
7 
8     /* CKTmodCrt(type,name,ckt,fast)
9      *  Create a device model of the specified type, with the given name
10      *  in the named circuit.
11      */
12 
13 #include "ngspice/ngspice.h"
14 #include "ngspice/devdefs.h"
15 #include "ngspice/cktdefs.h"
16 #include "ngspice/sperror.h"
17 #include "ngspice/wordlist.h"
18 
19 
20 
21 int
CKTmodCrt(CKTcircuit * ckt,int type,GENmodel ** modfast,IFuid name)22 CKTmodCrt(CKTcircuit *ckt, int type, GENmodel **modfast, IFuid name)
23 {
24     GENmodel *model = CKTfndMod(ckt, name);
25 
26     if (model) {
27         *modfast = model;
28         return E_EXISTS;
29     }
30 
31     model = (GENmodel *) tmalloc((size_t) *(DEVices[type]->DEVmodSize));
32     if (!model)
33         return E_NOMEM;
34 
35     model->defaults = NULL;
36     model->GENmodType = type;
37     model->GENmodName = name;
38     model->GENnextModel = ckt->CKThead[type];
39     ckt->CKThead[type] = model;
40 
41     nghash_insert(ckt->MODnameHash, name, model);
42 
43     *modfast = model;
44 
45     return OK;
46 }
47 
48 
49 void
GENinstanceFree(GENinstance * inst)50 GENinstanceFree(GENinstance *inst)
51 {
52     txfree(inst);
53 }
54 
55 
56 void
GENmodelFree(GENmodel * model)57 GENmodelFree(GENmodel *model)
58 {
59     wl_free(model->defaults);
60     txfree(model);
61 }
62