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

📄 cfunc.mod

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 MOD
📖 第 1 页 / 共 3 页
字号:
        }    }    /* Convert the numeric portion to a float and multiply by the */    /* scale factor.                                              */    n_matched = sscanf(val_str,"%e",&value);    if(n_matched < 1) {        *p_value = 0.0;        return(FAIL);    }    *p_value = value * scale_factor;    return(OK);}                                    /*==============================================================================FUNCTION cm_source_mask_and_retrieve()AUTHORS                          15 Jul 1991     Jeffrey P. MurrayMODIFICATIONS       16 Jul 1991     Jeffrey P. Murray    30 Sep 1991     Jeffrey P. MurraySUMMARY    Masks off and retrieves a two-bit value from a short    integer word passed to the function, using an offset value.     This effectively handles retrieval of eight two-bit values     from a single short integer space in order to conserve memory.INTERFACES           FILE                 ROUTINE CALLED          N/A                  N/ARETURNED VALUE        Returns a Digital_t value.GLOBAL VARIABLES        NONENON-STANDARD FEATURES    NONE==============================================================================*//*=== Static CM_SOURCE_MASK_AND_RETRIEVE ROUTINE ===*//***************************************************      The following routine masks and retrieves  **   the value passed to it by the out value       **   by masking the appropriate bits in the        **   base integer. The particular bit affected     **   is determined by the bit_offset value.        **                                                 **   Created 7/15/91               J.P.Murray      ***************************************************/static void cm_source_mask_and_retrieve(short base,int bit_offset,Digital_t *out){                                                                  short value;  /* the hexadecimal value of the masked bit  */    switch (bit_offset) {                                case 0:            break;    case 1:        base = base >> 4;        break;    case 2:        base = base >> 8;        break;    case 3:        base = base >> 12;        break;    }    value = 0x000f & base;    switch (value) {    case 0: out->state = ZERO;            out->strength = STRONG;            break;    case 1: out->state = ONE;            out->strength = STRONG;            break;    case 2: out->state = UNKNOWN;            out->strength = STRONG;            break;    case 3: out->state = ZERO;            out->strength = RESISTIVE;            break;    case 4: out->state = ONE;            out->strength = RESISTIVE;            break;    case 5: out->state = UNKNOWN;            out->strength = RESISTIVE;            break;    case 6: out->state = ZERO;            out->strength = HI_IMPEDANCE;            break;    case 7: out->state = ONE;            out->strength = HI_IMPEDANCE;            break;    case 8: out->state = UNKNOWN;            out->strength = HI_IMPEDANCE;            break;    case 9: out->state = ZERO;            out->strength = UNDETERMINED;            break;    case 10: out->state = ONE;            out->strength = UNDETERMINED;            break;    case 11: out->state = UNKNOWN;            out->strength = UNDETERMINED;            break;    }}/*==============================================================================FUNCTION cm_source_mask_and_store()AUTHORS                          15 Jul 1991     Jeffrey P. MurrayMODIFICATIONS       16 Jul 1991     Jeffrey P. Murray    30 Sep 1991     Jeffrey P. MurraySUMMARY    Masks off and stores a two-bit value to a short    integer word passed to the function, using an offset value.     This effectively handles storage of eight two-bit values     to a single short integer space in order to conserve memory.INTERFACES           FILE                 ROUTINE CALLED          N/A                  N/ARETURNED VALUE        Returns updated *base value.GLOBAL VARIABLES        NONENON-STANDARD FEATURES    NONE==============================================================================*//*=== Static CM_SOURCE_MASK_AND_STORE ROUTINE ===*//*************************************************      The following routine masks and stores   **   the value passed to it by the out value     **   by masking the appropriate bits in the      **   base integer. The particular bit affected   **   is determined by the ram_offset value.      **                                               **   Created 7/15/91               J.P.Murray    *************************************************/static int cm_source_mask_and_store(short *base,int bit_offset,int bit_value){    switch (bit_offset) {                                case 0:            *base = *base & 0xfff0;        break;    case 1:        *base = *base & 0xff0f;        bit_value = bit_value << 4;        break;    case 2:        *base = *base & 0xf0ff;        bit_value = bit_value << 8;        break;    case 3:        *base = *base & 0x0fff;        bit_value = bit_value << 12;        break;    }         *base = *base | bit_value;return 0;}/*==============================================================================FUNCTION cm_get_source_value()AUTHORS                          15 Jul 1991     Jeffrey P. MurrayMODIFICATIONS       16 Jul 1991     Jeffrey P. Murray    30 Sep 1991     Jeffrey P. MurraySUMMARY    Retrieves four-bit data from short integer array "source".INTERFACES           FILE                 ROUTINE CALLED          N/A                  N/ARETURNED VALUE        Returns data via *out pointer.GLOBAL VARIABLES        NONENON-STANDARD FEATURES    NONE==============================================================================*/             /*=== Static CM_GET_SOURCE_VALUE ROUTINE ===*//*************************************************      The following routine retrieves four-bit **   data from short integer array "source". The **   integers are assumed to be at least two     **   bytes each, so each will hold four four-    **   bit values.                                 **                                               **   Created 7/15/91               J.P.Murray    *************************************************/static void cm_get_source_value(int word_width,int bit_number,int index,                         short *bits, Digital_t *out){    int       /*err,*/      /* error index value    */             int1,      /* temp storage variable    */        bit_index,      /* bits base address at which word bits will                           be found */       bit_offset;      /* offset from ram base address at which bit[0]                           of the required word can be found    */            short    base;      /* variable to hold current base integer for                           comparison purposes. */                                            double   double1,             double2;      /* holding variables for modf routine */    /* obtain offset value from index, word_width & bit_number */    int1 = index * word_width + bit_number;    double1 = int1 / 4.0;    modf(double1, &double2);    bit_index = double2;    bit_offset = int1 - (double2 * 4.0);    /* retrieve entire base_address bits integer... */    base = bits[bit_index];                             /* for each offset, mask off the bits and determine values */    cm_source_mask_and_retrieve(base,bit_offset,out);}/*==============================================================================FUNCTION cm_read_source()AUTHORS                          15 Jul 1991     Jeffrey P. MurrayMODIFICATIONS       19 Jul 1991     Jeffrey P. Murray    30 Sep 1991     Jeffrey P. MurraySUMMARY    This function reads the source file and stores the results    for later output by the model.INTERFACES           FILE                 ROUTINE CALLED          N/A                  N/ARETURNED VALUE        Returns output bits stored in "bits" array.GLOBAL VARIABLES        NONENON-STANDARD FEATURES    NONE==============================================================================*//*=== Static CM_READ_SOURCE ROUTINE ===*/                                     /***************************************************      The following routine reads the file       **   *source, parses the file, and stores          **   the values found there into the *bits &       **   *timepoints arrays.                           **                                                 **   Created 7/15/91               J.P.Murray      ***************************************************/static int cm_read_source(FILE *source,short *bits,double *timepoints,                   Source_Table_Info_t *info){    int         i,  /* indexing variable    */                j,  /* indexing variable    */       num_tokens,  /* number of tokens in a given string    */        bit_index,  /* index to which bits[] integer we are accessing   */       bit_offset,  /* index to which bit within the current bits[]                        integer we are accessing   */             int1;  /* temporary holding variable   */    Cnv_Token_Type_t type;  /* variable for testing token type returned.    */    char   temp[MAX_STRING_SIZE],   /* holding string variable for testing                                       input from source.in */                              *s,   /* main string variable */                   *base_address,   /* storage location for base address                                       of string.   */                              *token;   /* a particular token from the string   */       float                 number;   /* holding variable for timepoint values */                                                                                                  double               double1,   /* temporary holding variable   */                         double2;   /* temporary holding variable   */    short              bit_value,   /* holding variable for value read from                                       source file which needs to be stored */                            base;   /* holding variable for existing                                        non-masked bits[] integer  */    i = 0;                                     s = temp;    while ( fgets(s,MAX_STRING_SIZE,source) != NULL) {        /* Test this string to see if it is whitespace... */        base_address = s;        while(isspace(*s) || (*s == '*'))               (s)++;        if ( *s != '\0' ) {     /* This is not a blank line, so process... */            s = base_address;            if ( '*' != s[0] ) {                        /* Count up total number of tokens including \0... */                j = 0;                type = CNV_STRING_TOK;                while ( type != CNV_NO_TOK ) {                    token = CNVget_token(&s, &type);                    j++;                }                num_tokens = j;                        /* If this number is incorrect, return with an error    */                if ( (info->width + 2) != num_tokens) {                    return 1;                }                        /* reset s to beginning... */                     

⌨️ 快捷键说明

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