⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mifgetmod.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
字号:
/*============================================================================FILEMEMBER OF process XSPICECopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights Reserved * * Copyright (c) 1985 Thomas L. Quarles * * NOTE:  Portions of this code are Copyright Thomas L. Quarles and University of *        California at Berkeley.  Other portions are modified and added by *        the Georgia Tech Research Institute. *PROJECT A-8503AUTHORS    9/12/91  Bill KuhnMODIFICATIONS    <date> <person name> <nature of modifications>SUMMARY    This file contains the routine that allocates a new model structure and    parses the .model card parameters.INTERFACES    MIFgetMod()REFERENCED FILES    None.NON-STANDARD FEATURES    None.============================================================================*//* #include "prefix.h" */#include "ngspice.h"#include <stdio.h>#include "inpdefs.h"  /* maschmann : kleinbuchstaben */#include "devdefs.h" /* maschmann : kleinbuchstaben *///#include "util.h"#include "ifsim.h"  /* maschmann : kleinbuchstaben */#include "cpstd.h" /* maschmann : kleinbuchstaben */#include "fteext.h" /* maschmann : kleinbuchstaben */#include "mifproto.h"#include "mifdefs.h"#include "mifcmdat.h"#include "suffix.h"/*  This is the table of all models known to the program.  *//*  It is now defined in inpdefs.h  6.19.2003 -- SDB.      */extern INPmodel *modtab;extern SPICEdev **DEVices;        /* info about all device types *//*MIFgetModThis function is a modified version of SPICE 3C1 INPgetMod().MIFgetMod looks in the table of model information created on thefirst pass of the parser to find the text of the .model card.  Itthen checks to see if the .model card has already been processedby a previous element card reference.  If so, it returns apointer to the previously created model structure.  If not, itallocates a new model structure and processes the parameters onthe .model card.  Parameter values for parameters not found onthe .model card are not filled in by this function.  They aredefaulted later by MIFsetup().  The function returns NULL whensuccessful, and an error string on failure.*//*  char *MIFgetMod(ckt,name,model,tab) */   /*  former buggy calling method  */char *MIFgetMod(     void   *ckt,           /* The circuit structure */    char      *name,          /* The name of the model to look for */    INPmodel  **model,        /* The model found/created */    INPtables *tab           /* Table of model info from first pass */    ){    INPmodel *modtmp;    IFvalue * val;    register int j;    char * line;    char *parm;    char *err = NULL;    char *temp;    int error;    int               i;    char              *err1;    char              *err2;    MIFmodel          *mdfast;    /* Mif_Param_Info_t  *param_info;*/    /* ===========  First locate the named model in the modtab list ================= */#ifdef TRACE    /* SDB debug statement */    printf("In MIFgetMod, looking for model name = %s . . .\n", name);#endif    /* maschmann : remove : from name     *    char *pos;     * if((pos=strstr(name,":"))!=NULL) *pos=0;        */    /*------------------------------------   for (i = &modtab; *i != (INPmodel *) NULL; i = &((*i)->INPnextModel)) {        if (strcmp((*i)->INPmodName, token) == 0) {            return (OK);        }    }    --------------------------*/    /* loop through modtable looking for this model (*name) */    for (modtmp = modtab; modtmp != NULL; modtmp = ((modtmp)->INPnextModel) ) {#ifdef TRACE      /* SDB debug statement */      printf("In MIFgetMod, checking model against stored model = %s . . .\n", (modtmp)->INPmodName );#endif        if (strcmp((modtmp)->INPmodName,name) == 0) {#ifdef TRACE	/* SDB debug statement */	printf("In MIFgetMod, found model!!!\n");#endif	/* ========= found the model in question - now instantiate if necessary ========== */	/* ==============    and return an appropriate pointer to it ===================== */            /* make sure the type is valid before proceeding */	if( (modtmp)->INPmodType < 0) {                /* illegal device type, so can't handle */                *model = NULL;		/* fixed by SDB -- magic number is 39, not 35.  		 * Also needed parens to correctly compute # of bytes to malloc		 */                err = (char *)tmalloc( (39+strlen(name)) * sizeof(char) );                 sprintf(err, "MIF: Unknown device type for model %s \n",name);                return(err);            }            /* check to see if this model's parameters have been processed */            if(! ((modtmp)->INPmodUsed )) {                /* not already processed, so create data struct */                error = (*(ft_sim->newModel))( ckt,(modtmp)->INPmodType,                        &((modtmp)->INPmodfast), (modtmp)->INPmodName);                if(error)                    return(INPerror(error));                /* gtri modification: allocate and initialize MIF specific model struct items */                mdfast = modtmp->INPmodfast;                mdfast->num_param = DEVices[modtmp->INPmodType]->DEVpublic.num_param;                mdfast->param = (void *) tmalloc(mdfast->num_param * sizeof(void *));                for(i = 0; i < mdfast->num_param; i++) {                    mdfast->param[i] = (void *) tmalloc(sizeof(Mif_Param_Data_t));                    mdfast->param[i]->is_null = MIF_TRUE;                    mdfast->param[i]->size = 0;                    mdfast->param[i]->element = NULL;                }                /* remaining initializations will be done by MIFmParam() and MIFsetup() */                /* parameter isolation, identification, binding */                line = ((modtmp)->INPmodLine)->line;                INPgetTok(&line,&parm,1);     /* throw away '.model' */                INPgetTok(&line,&parm,1);     /* throw away 'modname' */                /* throw away the modtype - we don't treat it as a parameter */                /* like SPICE does                                           */                INPgetTok(&line,&parm,1);     /* throw away 'modtype' */                while(*line != 0) {                    INPgetTok(&line,&parm,1);                    for(j=0;j<*((*(ft_sim->devices)[(modtmp)->INPmodType]).numModelParms); j++) {                        if (strcmp(parm,((*(ft_sim->devices) [ (modtmp)->                                         INPmodType ]).modelParms[j].keyword)) == 0) {                           /* gtri modification: call MIFgetValue instead of INPgetValue */                            err1 = NULL;                            val = MIFgetValue(ckt,&line,                                    ((*(ft_sim->devices)[(modtmp)->                                    INPmodType ]).modelParms[j].                                    dataType),tab,&err1);                            if(err1) {                                err2 = (void *) tmalloc(25 + strlen(name) + strlen(err1));                                sprintf(err2, "MIF-ERROR - model: %s - %s\n", name, err1);                                return(err2);                            }                            error = (*(ft_sim->setModelParm))(ckt,                                    ((modtmp)->INPmodfast),                                    (*(ft_sim->devices)[(modtmp)->INPmodType ]).                                    modelParms[j].id,val,(IFvalue*)NULL);                            if(error)                                return(INPerror(error));                            break;                        }                    }                    /* gtri modification: processing of special parameter "level" removed */                    if(j >= *((*(ft_sim->devices)[(modtmp)->INPmodType]).numModelParms))					{						//err has not been allocated, but free() in INPerrCat()						// This did not allocate enough memory you wanker, K.A. replaced 5 March 2000		// temp = (char *)tmalloc((40+strlen(parm)) * sizeof(char));						temp = (char *)tmalloc((42+strlen(parm)) * sizeof(char));// K.A. replaced 5 March 2000						sprintf(temp, "MIF: unrecognized parameter (%s) - ignored\n", parm);						fprintf(stdout,temp);						err = (char *)tmalloc( (2*strlen(temp) +2)*sizeof(char));// K.A. added 5 March 2000                  						*err = '\0';// K.A. added 5 March 2000                        err = INPerrCat(err,temp);                    }                    FREE(parm);                }  /* end while end of line not reached */                (modtmp)->INPmodUsed=1;                (modtmp)->INPmodLine->error = err;            }  /* end if model parameters not processed yet */            *model = modtmp;            return((char *)NULL);        } /* end if name matches */    } /* end for all models in modtab linked list */    /* didn't find model - ERROR  - return NULL model */    *model = (INPmodel *)NULL;    err = (char *)tmalloc((60+strlen(name)) * sizeof(char));    sprintf(err, " MIF-ERROR - unable to find definition of model %s\n",name);    return(err);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -