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

📄 mifmpara.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
字号:
/*============================================================================FILE    MIFmParam.cMEMBER OF process XSPICECopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS    9/12/91  Bill KuhnMODIFICATIONS    <date> <person name> <nature of modifications>SUMMARY    This file contains the function used to assign the value of a parameter    read from the .model card into the appropriate structure in the model.INTERFACES    MIFmParam()REFERENCED FILES    None.NON-STANDARD FEATURES    None.============================================================================*//*  #include "prefix.h"  */#include "ngspice.h"#include <stdio.h>//#include "CONST.h"//#include "util.h"#include "ifsim.h"//#include "resdefs.h"#include "devdefs.h"#include "sperror.h"#include <string.h>#include "mifproto.h"#include "mifparse.h"#include "mifdefs.h"#include "mifcmdat.h"/* #include "suffix.h"  */extern  SPICEdev    **DEVices;extern  int         DEVmaxnum;/*MIFmParamThis function is called by SPICE/Nutmeg to set the value of aparameter on a model according to information parsed from a.model card or information supplied interactively by a user.  Ittakes the value of the parameter input in an IFvalue structureand sets the parameter on the specified model structure.  Unlikethe procedure for SPICE 3C1 devices, MIFmParam does not useenumerations for identifying the parameter to set.  Instead, theparameter is identified directly by the index value of theparameter in the SPICEdev.DEVpublic.modelParms array.*/int MIFmParam(    int param_index,        /* The parameter to set */    IFvalue *value,         /* The value of the parameter */    GENmodel *inModel)      /* The model structure on which to set the value */{    MIFmodel    *model;    int         mod_type;    int         value_type;    int         i;    Mif_Boolean_t  is_array;    /* Arrange for access to MIF specific data in the model */    model = (MIFmodel *) inModel;    /* Get model type */    mod_type = model->MIFmodType;    if((mod_type < 0) || (mod_type >= DEVmaxnum))        return(E_BADPARM);    /* Check parameter index for validity */    if((param_index < 0) || (param_index >= model->num_param))        return(E_BADPARM);    /* get value type to know which members of unions to access */    value_type = DEVices[mod_type]->DEVpublic.modelParms[param_index].dataType;    value_type &= IF_VARTYPES;    /* determine if the parameter is an array or not */    is_array = value_type & IF_VECTOR;    /* initialize the parameter is_null and size elements and allocate elements */    model->param[param_index]->is_null = MIF_FALSE;    if(is_array) {        model->param[param_index]->size = value->v.numValue;        model->param[param_index]->element = (void *) MALLOC(value->v.numValue *                                                   sizeof(Mif_Value_t));    }    else {        model->param[param_index]->size = 1;        model->param[param_index]->element = (void *) MALLOC(sizeof(Mif_Value_t));    }    /* Transfer the values from the SPICE3C1 value union to the param elements */    /* This is analagous to what SPICE3 does with other device types */    if(! is_array) {        switch(value_type) {        case  IF_FLAG:            model->param[param_index]->element[0].bvalue = value->iValue;            break;        case  IF_INTEGER:            model->param[param_index]->element[0].ivalue = value->iValue;            break;        case  IF_REAL:            model->param[param_index]->element[0].rvalue = value->rValue;            break;        case  IF_STRING:            /* we don't trust the caller to keep the string alive, so copy it */            model->param[param_index]->element[0].svalue =                                       (void *) MALLOC(1 + strlen(value->sValue));            strcpy(model->param[param_index]->element[0].svalue, value->sValue);            break;        case  IF_COMPLEX:            /* we don't trust the caller to have a parallel complex structure */            /* so copy the real and imaginary parts explicitly                */            model->param[param_index]->element[0].cvalue.real = value->cValue.real;            model->param[param_index]->element[0].cvalue.imag = value->cValue.imag;            break;        default:            return(E_BADPARM);        }    }    else {   /* it is an array */        for(i = 0; i < value->v.numValue; i++) {            switch(value_type) {            case  IF_FLAGVEC:                model->param[param_index]->element[i].bvalue = value->v.vec.iVec[i];                break;            case  IF_INTVEC:                model->param[param_index]->element[i].ivalue = value->v.vec.iVec[i];                break;            case  IF_REALVEC:                model->param[param_index]->element[i].rvalue = value->v.vec.rVec[i];                break;            case  IF_STRINGVEC:                /* we don't trust the caller to keep the string alive, so copy it */                model->param[param_index]->element[i].svalue =                                           (void *) MALLOC(1 + strlen(value->v.vec.sVec[i]));                strcpy(model->param[param_index]->element[i].svalue, value->v.vec.sVec[i]);                break;            case  IF_CPLXVEC:                /* we don't trust the caller to have a parallel complex structure */                /* so copy the real and imaginary parts explicitly                */                model->param[param_index]->element[i].cvalue.real = value->v.vec.cVec[i].real;                model->param[param_index]->element[i].cvalue.imag = value->v.vec.cVec[i].imag;                break;            default:                return(E_BADPARM);            } /* end switch */        } /* end for number of elements of vector */    } /* end else */    return(OK);}

⌨️ 快捷键说明

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