📄 cfunc.mod
字号:
/* $Id: cfunc.mod,v 1.4 2005/08/23 08:21:01 pnenzi Exp $ *//*.......1.........2.........3.........4.........5.........6.........7.........8================================================================================FILE d_source/cfunc.modCopyright 1991Georgia Tech Research Corporation, Atlanta, Ga. 30332All Rights ReservedPROJECT A-8503-405 AUTHORS 6 June 1991 Jeffrey P. MurrayMODIFICATIONS 30 Sept 1991 Jeffrey P. Murray SUMMARY This file contains the model-specific routines used to functionally describe the <model_name> code model.INTERFACES FILE ROUTINE CALLED CMmacros.h cm_message_send(); CMevt.c void *cm_event_alloc() void *cm_event_get_ptr() int cm_event_queue() REFERENCED FILES Inputs from and outputs to ARGS structure. NON-STANDARD FEATURES NONE===============================================================================*//*=== INCLUDE FILES ====================*/#include "d_source.h" /* ...contains macros & type defns. for this model. 6/13/90 - JPM */ /*=== CONSTANTS ========================*/#define MAX_STRING_SIZE 200/*=== MACROS ===========================*/ /*=== LOCAL VARIABLES & TYPEDEFS =======*/ typedef struct { int index, /* current index into source tables */ width, /* width of table...equal to size of out port */ depth; /* depth of table...equal to size of "timepoints" array, and to the total number of vectors retrieved from the source.in file. */} Source_Table_Info_t;/* Type definition for each possible token returned. */typedef enum token_type_s {CNV_NO_TOK,CNV_STRING_TOK} Cnv_Token_Type_t; /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ /*==============================================================================FUNCTION *CNVgettok()AUTHORS 13 Jun 1991 Jeffrey P. MurrayMODIFICATIONS 8 Aug 1991 Jeffrey P. Murray 30 Sep 1991 Jeffrey P. MurraySUMMARY This function obtains the next token from an input stream.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns a string value representing the next token.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== Static CNVgettok ROUTINE ================*//*Get the next token from the input string. The input string pointeris advanced to the following token and the token from the inputstring is copied to malloced storage and a pointer to that storageis returned. The original input string is undisturbed.*/#include <stdlib.h>static char *CNVgettok(char **s){ char *buf; /* temporary storage to copy token into */ /*char *temp;*/ /* temporary storage to copy token into */ char *ret_str; /* storage for returned string */ int i; /* allocate space big enough for the whole string */ buf = (void *) malloc(strlen(*s) + 1); /* skip over any white space */ while(isspace(**s) || (**s == '=') || (**s == '(') || (**s == ')') || (**s == ',')) (*s)++; /* isolate the next token */ switch(**s) { case '\0': /* End of string found */ if(buf) free(buf); return(NULL); default: /* Otherwise, we are dealing with a */ /* string representation of a number */ /* or a mess o' characters. */ i = 0; while( (**s != '\0') && (! ( isspace(**s) || (**s == '=') || (**s == '(') || (**s == ')') || (**s == ',') ) ) ) { buf[i] = **s; i++; (*s)++; } buf[i] = '\0'; break; } /* skip over white space up to next token */ while(isspace(**s) || (**s == '=') || (**s == '(') || (**s == ')') || (**s == ',')) (*s)++; /* make a copy using only the space needed by the string length */ ret_str = (void *) malloc(strlen(buf) + 1); ret_str = strcpy(ret_str,buf); if(buf) free(buf); return(ret_str);}/*==============================================================================FUNCTION *CNVget_token()AUTHORS 13 Jun 1991 Jeffrey P. MurrayMODIFICATIONS 8 Aug 1991 Jeffrey P. Murray 30 Sep 1991 Jeffrey P. MurraySUMMARY This function obtains the next token from an input stream.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns a string value representing the next token. Uses *CNVget_tok.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== Static CNVget_token ROUTINE =============*//*Get the next token from the input string together with its type.The input string pointeris advanced to the following token and the token from the inputstring is copied to malloced storage and a pointer to that storageis returned. The original input string is undisturbed.*/static char *CNVget_token(char **s, Cnv_Token_Type_t *type){ char *ret_str; /* storage for returned string */ /* get the token from the input line */ ret_str = CNVgettok(s); /* if no next token, return */ if(ret_str == NULL) { *type = CNV_NO_TOK; return(NULL); } /* else, determine and return token type */ switch(*ret_str) { default: *type = CNV_STRING_TOK; break; } return(ret_str);}/*==============================================================================FUNCTION cnv_get_spice_value()AUTHORS ??? Bill KuhnMODIFICATIONS 30 Sep 1991 Jeffrey P. MurraySUMMARY This function takes as input a string token from a SPICE deck and returns a floating point equivalent value.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns the floating point value in pointer *p_value. Also returns an integer representing successful completion.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== Static CNV_get_spice_value ROUTINE =============*//* Function takes as input a string token from a SPICEdeck and returns a floating point equivalent value.*/static int cnv_get_spice_value(str,p_value)char *str; /* IN - The value text e.g. 1.2K */float *p_value; /* OUT - The numerical value */{ /* the following were "int4" devices - jpm */ int len; int i; int n_matched; line_t val_str; /*char *suffix;*/ char c = ' '; char c1; float scale_factor; float value; /* Scan the input string looking for an alpha character that is not */ /* 'e' or 'E'. Such a character is assumed to be an engineering */ /* suffix as defined in the Spice 2G.6 user's manual. */ len = strlen(str); if( len > (sizeof(val_str) - 1)) len = sizeof(val_str) - 1; for(i = 0; i < len; i++) { c = str[i]; if( isalpha(c) && (c != 'E') && (c != 'e') ) break; else if( isspace(c) ) break; else val_str[i] = c; } val_str[i] = '\0'; /* Determine the scale factor */ if( (i >= len) || (! isalpha(c)) ) scale_factor = 1.0; else { if(isupper(c)) c = tolower(c); switch(c) { case 't': scale_factor = 1.0e12; break; case 'g': scale_factor = 1.0e9; break; case 'k': scale_factor = 1.0e3; break; case 'u': scale_factor = 1.0e-6; break; case 'n': scale_factor = 1.0e-9; break; case 'p': scale_factor = 1.0e-12; break; case 'f': scale_factor = 1.0e-15; break; case 'm': i++; if(i >= len) { scale_factor = 1.0e-3; break; } c1 = str[i]; if(! isalpha(c1)) { scale_factor = 1.0e-3; break; } if(islower(c1)) c1 = toupper(c1); if(c1 == 'E') scale_factor = 1.0e6; else if(c1 == 'I') scale_factor = 25.4e-6; else scale_factor = 1.0e-3; break; default: scale_factor = 1.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -