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

📄 units.c

📁 有限元分析源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
           free((char *)dp1);           free((char *)dp2->units_name);           free((char *)dp2);           free((char *)dp3->units_name);           free((char *)dp3);           free((char *)dp4->units_name);           free((char *)dp4);           free((char *)dd1->units_name);           free((char *)dd1);           free((char *)dd2->units_name);           free((char *)dd2);#ifdef DEBUG     printf(" Leaving UnitsSimplify() \n");#endif           return(d);        }}/* *  ============================================================ *  RadUnitsSimplify() : Simplify Radian Units *   *  Input : DIMENSIONS *d : Pointer to dimensions data structure   *  Ouput : DIMENSIONS *d : Pointer to "simplified" dimensions *  ============================================================ */#ifdef __STDC__DIMENSIONS *RadUnitsSimplify( DIMENSIONS *d )#elseDIMENSIONS *RadUnitsSimplify( d )DIMENSIONS *d;#endif{SYMBOL     *hp;#ifdef DEBUG     printf(" Enter RadUnitsSimplify() \n");#endif  /* [a] Check waether unit names are in the symbol table */                if( d==(DIMENSIONS *)NULL ) {             printf("Warning: d is NULL,   in RadUnitsSimplify()\n");             return (DIMENSIONS *)NULL;         }	 hp = (SYMBOL *)NULL;         if(d->units_name != NULL)            hp = lookup(d->units_name);         if(hp != NULL)            return(d);            /* [b] Check weather the units are rad units            */                 if(d->length_expnt == 0 && d->time_expnt == 0 &&            d->mass_expnt   == 0 && d->temp_expnt == 0 ) {           free((char *)d->units_name);           d->units_name   = SaveString( (char *) "rad" );           d->scale_factor = 1.0;           d->units_type   = SI_US;           return(d);        }#ifdef DEBUG     printf(" Leaving RadUnitsSimplify() \n");#endif        return(d);}/* *  ===================== *  Print Units *  ===================== */#ifdef __STDC__void UnitsPrint(DIMENSIONS *d)#elsevoid UnitsPrint(d)DIMENSIONS *d;#endif{#ifdef DEBUG  printf("\n Enter UnitsPrint()\n");#endif           if( d==(DIMENSIONS *)NULL ) {               printf("Unit d is NULL,   in UnitsPrint()\n");               return;           }             if( d->units_name != (char *)NULL )               printf("\n units_name = %s\n", d->units_name);           else               printf("\n units_name = %s\n", (char *)"NULL");           printf(" d->units_type   = %d \n",d->units_type);           printf(" d->scale_factor = %lg\n",d->scale_factor);           printf(" d->length_expnt = %g \n",d->length_expnt);           printf(" d->time_expnt   = %g \n",d->time_expnt  );           printf(" d->mass_expnt   = %g \n",d->mass_expnt );           printf(" d->temp_expnt   = %g \n",d->temp_expnt );#ifdef DEBUG      printf("\n Leaving UnitsPrint()\n");#endif}/*  *  ================================================================== *  Usage : *  int   : L ; char * name1, * name2, ...                    *        L = UnitsLength(name1, "STOP");   *  or    L = UnitsLength(name1, name2, ..., "STOP");    *  ================================================================== */ #ifdef __STDC__int UnitsLength( char *first_name, ... )#elseint UnitsLength(va_alist)va_dcl#endif{char       *name;int       length;#ifdef __STDC__va_list  arg_ptr;#elseva_list  arg_ptr;char *first_name;#endif#ifdef DEBUG     printf(" Enter UnitsLength() \n");#endif#ifdef __STDC__    va_start(arg_ptr, first_name);#else    va_start(arg_ptr);    first_name = va_arg(arg_ptr, char *);#endif    for (name = first_name, length = (int) 0;    ; name = va_arg(arg_ptr, char * ) ) {       if(name != (char *)NULL && !strcmp(name, "STOP") )          break;        if (name != (char *)NULL) {              length += strlen(name);        }        else            length += 0;   }   va_end(arg_ptr);#ifdef DEBUG     printf(" Leaving UnitsLength() length = %d\n", length);#endif   return(length);}/*  *  ================================================== *  BufferPrint() : Print contents of matrix buffer *  ================================================== */ #ifdef __STDC__void BufferPrint(char *name, DIMENSIONS *array, int no_col)#elsevoid BufferPrint(name, array, no_col)char        *name;DIMENSIONS *array;int        no_col;#endif{int i;#ifdef DEBUG  printf("\n Enter BufferPrint()\n");#endif   printf("\n in BufferPrint() no_of col = %d \n", no_col);       printf(" \n buffer_name = %s\n", name);       if(array != (DIMENSIONS *)NULL) {          for (i = 1; i <= no_col; i++) {           printf("\n col/row[%d] \n", i);           UnitsPrint(&array[i-1]);         }      }      else         printf("\n Buffer = NULL \n");#ifdef DEBUG      printf("\n Leaving BufferPrint()\n");#endif }/*  *  ================================================== *  BufferInit() : Allocate and zero Matrix Buffer *   *  Input  : int no_col : number of elements in buffer   *  Output : pointer to array of DIMENSIONS. *  ================================================== */ #ifdef __STDC__DIMENSIONS *BufferInit(int no_col)#elseDIMENSIONS *BufferInit(no_col)int         no_col;#endif{DIMENSIONS *array;int          i;#ifdef DEBUG       printf("\n Enter BufferInit()\n");#endif     array = (DIMENSIONS *) MyCalloc(no_col, sizeof(DIMENSIONS));    for( i = 1; i <= no_col; i++)       ZeroUnits(&array[i-1]);#ifdef DEBUG       BufferPrint(" no name ", array, no_col);       printf("\n Leaving BufferInit()\n");#endif   return (array);}/* *  ======================================================================== *  ConvertTempUnits() : Convert temperature units * *  Input : *  Output : *  ======================================================================== */#ifdef __STDC__double ConvertTempUnits(char *name, double value,int units_type)#elsedouble ConvertTempUnits(name, value, units_type)char      *name;double    value;int  units_type;#endif{#ifdef DEBUG  printf("**** Enter ConvertTempUnits \n");  printf("  : name = %s \n", name);  printf("  : value= %g \n", value);  printf("  : type = %d \n", units_type);#endif  switch(units_type) {     case SI: /* convert to SI */       if(name != (char *)NULL) {          if( !strcmp(name, "deg_C") || !strcmp(name, "deg_F") )              value = 5.0*(value - 32.0)/9.0;          else {             printf("*** In ConvertTempUnits(): units_name = %s", name);             FatalError("Try to convert a non temperature units",             (char *) NULL);         }       }     break;     case US: /* convert to US */       if(name != (char *)NULL) {          if( !strcmp(name, "deg_C") || !strcmp(name, "deg_F") )             value = 9.0*value/5.0 + 32.0;          else {             printf("*** In ConvertTempUnits(): units_name = %s", name);             FatalError("Try to convert a non temperature units",             (char *) NULL);         }       }     break;  }    return(value);}/* *  ======================================================================== *  UnitsScaleConvert() : * *  Input : *  Output : *  ======================================================================== */#ifdef __STDC__DIMENSIONS UnitsScaleConvert(DIMENSIONS eng_units, int units_type) #elseDIMENSIONS UnitsScaleConvert(eng_units, units_type) DIMENSIONS eng_units;int         units_type;#endif{ switch(units_type) {   case SI:    /* convert from US to SI */       /* [a] length units */    if(eng_units.units_name != (char *)NULL && !strcmp("in", eng_units.units_name))       eng_units.scale_factor = 0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("ft", eng_units.units_name))       eng_units.scale_factor = 12.0*0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("mil", eng_units.units_name))       eng_units.scale_factor = 1E-3*0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("micro_in", eng_units.units_name))       eng_units.scale_factor = 1E-3*0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("yard", eng_units.units_name))       eng_units.scale_factor = 36.0*0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("mile", eng_units.units_name))       eng_units.scale_factor = 63360*0.0254;    /* [b] volumn units */    if(eng_units.units_name != (char *)NULL && !strcmp("gallon", eng_units.units_name))       eng_units.scale_factor = 3.785412E-3;    else if(eng_units.units_name != (char *)NULL && !strcmp("barrel", eng_units.units_name))       eng_units.scale_factor = 0.1589873;    /* [c] mass units */    if(eng_units.units_name != (char *)NULL && !strcmp("lb", eng_units.units_name))       eng_units.scale_factor = 0.4535924;    else if(eng_units.units_name != (char *)NULL && !strcmp("grain", eng_units.units_name))       eng_units.scale_factor = 0.4535924/7E+3;    else if(eng_units.units_name != (char *)NULL && !strcmp("ton", eng_units.units_name))       eng_units.scale_factor = 2E+3*0.4535924;    else if(eng_units.units_name != (char *)NULL && !strcmp("klb", eng_units.units_name))       eng_units.scale_factor = 1E+3*0.4535924;    /* [d] force units */    if(eng_units.units_name != (char *)NULL && !strcmp("lbf", eng_units.units_name))       eng_units.scale_factor = 0.4535924*9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("kips", eng_units.units_name))       eng_units.scale_factor = 1E+3*0.4535924*9.80665;    /* [e] pressure units */    if(eng_units.units_name != (char *)NULL && !strcmp("psi", eng_units.units_name))       eng_units.scale_factor = 0.4535924*9.80665/0.0254/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("ksi", eng_units.units_name))       eng_units.scale_factor = 1E+3*0.4535924*9.80665/0.0254/0.0254;    /* [f] incremental temperature units */    if(eng_units.units_name != (char *)NULL && !strcmp("DEG_F", eng_units.units_name))       eng_units.scale_factor = 5.0/9.0;    break;    case US:    /* convert from SI to US */    /* [a] length units */    if(eng_units.units_name != (char *)NULL && !strcmp("micron", eng_units.units_name))       eng_units.scale_factor = 1E-6/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("mm", eng_units.units_name))       eng_units.scale_factor = 1E-3/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("cm", eng_units.units_name))       eng_units.scale_factor = 1E-2/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("dm", eng_units.units_name))       eng_units.scale_factor = 1E-1/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("m", eng_units.units_name))       eng_units.scale_factor = 1.0/0.0254;    else if(eng_units.units_name != (char *)NULL && !strcmp("km", eng_units.units_name))       eng_units.scale_factor = 1E+3/0.0254;    /* [b] mass units */    if(eng_units.units_name != (char *)NULL && !strcmp("g", eng_units.units_name))       eng_units.scale_factor = 1E-3/0.4535924;    else if(eng_units.units_name != (char *)NULL && !strcmp("kg", eng_units.units_name))       eng_units.scale_factor = 1.0/0.4535924;    else if(eng_units.units_name != (char *)NULL && !strcmp("Mg", eng_units.units_name))       eng_units.scale_factor = 1E+3/0.4535924;    /* [c] force units */    if(eng_units.units_name != (char *)NULL && !strcmp("N", eng_units.units_name))       eng_units.scale_factor = 1.0/0.4535924/9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("kN", eng_units.units_name))       eng_units.scale_factor = 1E+3/0.4535924/9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("kgf", eng_units.units_name))       eng_units.scale_factor = 1.0/0.4535924;    /* [d] pressure units */    if(eng_units.units_name != (char *)NULL && !strcmp("Pa", eng_units.units_name))       eng_units.scale_factor = 0.0254*0.0254/0.4535924/9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("kPa", eng_units.units_name))       eng_units.scale_factor = 1E+3*0.0254*0.0254/0.4535924/9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("MPa", eng_units.units_name))       eng_units.scale_factor = 1E+6*0.0254*0.0254/0.4535924/9.80665;    else if(eng_units.units_name != (char *)NULL && !strcmp("GPa", eng_units.units_name))       eng_units.scale_factor = 1E+9*0.0254*0.0254/0.4535924/9.80665;    /* [e] energy units */    if(eng_units.units_name != (char *)NULL && !st

⌨️ 快捷键说明

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