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

📄 ex_utils.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement * retains certain rights in this software. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: *  *     * Redistributions of source code must retain the above copyright *       notice, this list of conditions and the following disclaimer. *  *     * Redistributions in binary form must reproduce the above *       copyright notice, this list of conditions and the following *       disclaimer in the documentation and/or other materials provided *       with the distribution.   *  *     * Neither the name of Sandia Corporation nor the names of its *       contributors may be used to endorse or promote products derived *       from this software without specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  *//******************************************************************************* exutils - utility routines**  $Id: ex_utils.c 2928 2008-07-11 17:45:07Z friedmud $*****************************************************************************/#if defined(DEBUG_QSORT)#include <assert.h>#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "exodusII.h"#include "exodusII_int.h"struct obj_stats*  exoII_eb = 0;struct obj_stats*  exoII_ed = 0;struct obj_stats*  exoII_fa = 0;struct obj_stats*  exoII_ns = 0;struct obj_stats*  exoII_es = 0;struct obj_stats*  exoII_fs = 0;struct obj_stats*  exoII_ss = 0;struct obj_stats* exoII_els = 0;struct obj_stats*  exoII_em = 0;struct obj_stats* exoII_edm = 0;struct obj_stats* exoII_fam = 0;struct obj_stats*  exoII_nm = 0;/******************************************************************************* utility routines for string conversions* ex_catstr  - concatenate  string/number (where number is converted to ASCII)* ex_catstr2 - concatenate  string1/number1/string2/number2   "** NOTE: these routines reuse the same storage over and over to build*        concatenated strings, because the strings are just passed to netCDF*        routines as names used to look up variables.  if the strings returned*        by these routines are needed for any other purpose, they should*        immediately be copied into other storage.*****************************************************************************/static char ret_string[10*(MAX_VAR_NAME_LENGTH+1)];static char* cur_string = &ret_string[0];/** ex_catstr  - concatenate  string/number (where number is converted to ASCII) */char *ex_catstr (const char *string,                 int   num){  char* tmp_string = cur_string;  cur_string += sprintf (cur_string, "%s%d", string, num) + 1;  if ( cur_string - ret_string > 9*(MAX_VAR_NAME_LENGTH+1) )    cur_string = ret_string;  return (tmp_string);}/** ex_catstr2 - concatenate  string1num1string2num2   */char *ex_catstr2 (const char *string1,                  int   num1,                  const char *string2,                  int   num2){  char* tmp_string = cur_string;  cur_string += sprintf (cur_string, "%s%d%s%d", string1, num1, string2, num2) + 1;  if ( cur_string - ret_string > 9*(MAX_VAR_NAME_LENGTH+1) )    cur_string = ret_string;  return (tmp_string);}char* ex_name_of_object(ex_entity_type obj_type){  switch (obj_type) {  case EX_NODAL:    return "nodal";  case EX_EDGE_BLOCK:    return "edge block";  case EX_FACE_BLOCK:    return "face block";  case EX_ELEM_BLOCK:    return "element block";  case EX_NODE_SET:    return "node set";  case EX_EDGE_SET:    return "edge set";  case EX_FACE_SET:    return "face set";  case EX_SIDE_SET:    return "side set";  case EX_ELEM_SET:    return "element set";  case EX_ELEM_MAP:    return "element map";  case EX_NODE_MAP:    return "node map";  case EX_EDGE_MAP:    return "edge map";  case EX_FACE_MAP:    return "face map";  case EX_GLOBAL:    return "global";  default:    return "invalid type";  }}ex_entity_type ex_var_type_to_ex_entity_type(char var_type){  char var_lower = tolower(var_type);  if (var_lower == 'n')    return EX_NODAL;  else if (var_lower == 'l')    return EX_EDGE_BLOCK;  else if (var_lower == 'f')    return EX_FACE_BLOCK;  else if (var_lower == 'e')    return EX_ELEM_BLOCK;  else if (var_lower == 'm')    return EX_NODE_SET;  else if (var_lower == 'd')    return EX_EDGE_SET;  else if (var_lower == 'a')    return EX_FACE_SET;  else if (var_lower == 's')    return EX_SIDE_SET;  else if (var_lower == 't')    return EX_ELEM_SET;  else if (var_lower == 'g')    return EX_GLOBAL;  else    return EX_INVALID;}char* ex_dim_num_objects(ex_entity_type obj_type){   exerrval = 0; /* clear error code */   switch (obj_type)   {     case EX_NODAL:       return DIM_NUM_NODES;     case EX_ELEM_BLOCK:       return DIM_NUM_EL_BLK;     case EX_EDGE_BLOCK:       return DIM_NUM_ED_BLK;     case EX_FACE_BLOCK:       return DIM_NUM_FA_BLK;     case EX_NODE_SET:       return DIM_NUM_NS;     case EX_EDGE_SET:       return DIM_NUM_ES;     case EX_FACE_SET:       return DIM_NUM_FS;     case EX_ELEM_SET:       return DIM_NUM_ELS;     case EX_SIDE_SET:       return DIM_NUM_SS;     case EX_ELEM_MAP:       return DIM_NUM_EM;     case EX_FACE_MAP:       return DIM_NUM_FAM;     case EX_EDGE_MAP:       return DIM_NUM_EDM;     case EX_NODE_MAP:       return DIM_NUM_NM;     default:       {	 char errmsg[MAX_ERR_LENGTH];	 exerrval = EX_BADPARAM;	 sprintf(errmsg, "Error: object type %d not supported in call to ex_dim_num_objects",		 obj_type);	 ex_err("ex_dim_num_objects",errmsg,exerrval);	 return (NULL);       }   }}char* ex_dim_num_entries_in_object( ex_entity_type obj_type,                                    int idx ){  switch (obj_type) {  case EX_NODAL:    return DIM_NUM_NODES;  case EX_EDGE_BLOCK:    return DIM_NUM_ED_IN_EBLK(idx);  case EX_FACE_BLOCK:    return DIM_NUM_FA_IN_FBLK(idx);  case EX_ELEM_BLOCK:    return DIM_NUM_EL_IN_BLK(idx);  case EX_NODE_SET:    return DIM_NUM_NOD_NS(idx);  case EX_EDGE_SET:    return DIM_NUM_EDGE_ES(idx);  case EX_FACE_SET:    return DIM_NUM_FACE_FS(idx);  case EX_SIDE_SET:    return DIM_NUM_SIDE_SS(idx);  case EX_ELEM_SET:    return DIM_NUM_ELE_ELS(idx);  default:    return 0;  }}char* ex_name_var_of_object(ex_entity_type obj_type,			    int i, int j){  switch (obj_type) {  case EX_EDGE_BLOCK:    return VAR_EDGE_VAR(i,j);  case EX_FACE_BLOCK:    return VAR_FACE_VAR(i,j);  case EX_ELEM_BLOCK:    return VAR_ELEM_VAR(i,j);  case EX_NODE_SET:    return VAR_NS_VAR(i,j);  case EX_EDGE_SET:    return VAR_ES_VAR(i,j);  case EX_FACE_SET:    return VAR_FS_VAR(i,j);  case EX_SIDE_SET:    return VAR_SS_VAR(i,j);  case EX_ELEM_SET:    return VAR_ELS_VAR(i,j);  default:    return 0;  }}char* ex_name_of_map(ex_entity_type map_type, int map_index){  switch (map_type) {  case EX_NODE_MAP:    return VAR_NODE_MAP(map_index);  case EX_EDGE_MAP:    return VAR_EDGE_MAP(map_index);  case EX_FACE_MAP:    return VAR_FACE_MAP(map_index);  case EX_ELEM_MAP:    return VAR_ELEM_MAP(map_index);  default:    return 0;  }}/******************************************************************************* ex_id_lkup - look up id** entry conditions - *   input parameters:*       int            exoid             exodus file id*       ex_entity_type id_type           id type name:*                                         elem_ss*                                         node_ns*                                         side_ss*       int     num                     id value** exit conditions - *       int     return                  index into table (1-based)** revision history - *******************************************************************************/int ex_id_lkup( int exoid,                ex_entity_type id_type,                int num){  char id_table[MAX_VAR_NAME_LENGTH+1];  char id_dim[MAX_VAR_NAME_LENGTH+1];  char stat_table[MAX_VAR_NAME_LENGTH+1];  int varid, dimid, i;  size_t dim_len;  int *id_vals=NULL, *stat_vals=NULL;  static int filled=FALSE;  struct obj_stats *tmp_stats;  int status;  char errmsg[MAX_ERR_LENGTH];  exerrval  = 0; /* clear error code */  switch(id_type) {  case EX_NODAL:    return 0;  case EX_GLOBAL:    return 0;  case EX_ELEM_BLOCK:    strcpy(id_table, VAR_ID_EL_BLK);            /* id array name */    strcpy(id_dim, DIM_NUM_EL_BLK);             /* id array dimension name*/    strcpy(stat_table, VAR_STAT_EL_BLK);        /* id status array name */    tmp_stats = ex_get_stat_ptr (exoid, &exoII_eb);    break;  case EX_NODE_SET:    strcpy(id_table, VAR_NS_IDS);    strcpy(id_dim, DIM_NUM_NS);    strcpy(stat_table, VAR_NS_STAT);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ns);    break;  case EX_SIDE_SET:    strcpy(id_table, VAR_SS_IDS);    strcpy(id_dim, DIM_NUM_SS);    strcpy(stat_table, VAR_SS_STAT);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ss);    break;  case EX_ELEM_MAP:    strcpy(id_table, VAR_EM_PROP(1));    strcpy(id_dim, DIM_NUM_EM);    strcpy(stat_table, "");    tmp_stats = ex_get_stat_ptr (exoid, &exoII_em);    break;  case EX_NODE_MAP:    strcpy(id_table, VAR_NM_PROP(1));    strcpy(id_dim, DIM_NUM_NM);    strcpy(stat_table, "");    tmp_stats = ex_get_stat_ptr (exoid, &exoII_nm);    break;  case EX_EDGE_BLOCK:    strcpy(id_table, VAR_ID_ED_BLK);    strcpy(id_dim, DIM_NUM_ED_BLK);    strcpy(stat_table, VAR_STAT_ED_BLK);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ed);    break;  case EX_FACE_BLOCK:    strcpy(id_table, VAR_ID_FA_BLK);    strcpy(id_dim, DIM_NUM_FA_BLK);    strcpy(stat_table, VAR_STAT_FA_BLK);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fa);    break;  case EX_EDGE_SET:    strcpy(id_table, VAR_ES_IDS);    strcpy(id_dim, DIM_NUM_ES);    strcpy(stat_table, VAR_ES_STAT);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_es);    break;  case EX_FACE_SET:    strcpy(id_table, VAR_FS_IDS);    strcpy(id_dim, DIM_NUM_FS);    strcpy(stat_table, VAR_FS_STAT);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fs);    break;  case EX_ELEM_SET:    strcpy(id_table, VAR_ELS_IDS);    strcpy(id_dim, DIM_NUM_ELS);    strcpy(stat_table, VAR_ELS_STAT);    tmp_stats = ex_get_stat_ptr (exoid, &exoII_els);    break;  case EX_EDGE_MAP:    strcpy(id_table, VAR_EDM_PROP(1));    strcpy(id_dim, DIM_NUM_EDM);    strcpy(stat_table, "");    tmp_stats = ex_get_stat_ptr (exoid, &exoII_edm);    break;  case EX_FACE_MAP:    strcpy(id_table, VAR_FAM_PROP(1));    strcpy(id_dim, DIM_NUM_FAM);    strcpy(stat_table, "");    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fam);    break;  default:    exerrval = EX_BADPARAM;    sprintf(errmsg,           "Error: unsupported id array type %d for file id %d",            id_type, exoid);    ex_err("ex_id_lkup",errmsg,exerrval);    return (EX_FATAL);  }  if ( (tmp_stats->id_vals == NULL) || (!(tmp_stats->valid_ids)) ) {    /* first time thru or id arrays haven't been completely filled yet */     /* get size of id array */    /* First get dimension id of id array */    if ((status = nc_inq_dimid(exoid,id_dim,&dimid)) != NC_NOERR) {      exerrval = status;      sprintf(errmsg,           "Error: failed to locate id array dimension in file id %d",            exoid);      ex_err("ex_id_lkup",errmsg,exerrval);      return (EX_FATAL);

⌨️ 快捷键说明

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