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

📄 ex_utils.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 3 页
字号:
    }    /* Next get value of dimension */     if ((status = nc_inq_dimlen(exoid,dimid,&dim_len)) != NC_NOERR) {      exerrval = status;      sprintf(errmsg,           "Error: failed to locate %s array length in file id %d",            id_table,exoid);      ex_err("ex_id_lkup",errmsg,exerrval);      return (EX_FATAL);    }    /* get variable id of id array */    if ((status = nc_inq_varid (exoid, id_table, &varid)) != NC_NOERR) {      exerrval = status;      sprintf(errmsg,             "Error: failed to locate %s array in file id %d",              id_table, exoid);      ex_err("ex_id_lkup",errmsg,exerrval);      return (EX_FATAL);    }    /* allocate space for id array */    if (!(id_vals = malloc((int)dim_len*sizeof(int)))) {      exerrval = EX_MEMFAIL;      sprintf(errmsg,             "Error: failed to allocate memory for %s array for file id %d",              id_table,exoid);      ex_err("ex_id_lkup",errmsg,exerrval);      return (EX_FATAL);    }    if ((status = nc_get_var_int (exoid, varid, id_vals)) != NC_NOERR) {      exerrval = status;      sprintf(errmsg,             "Error: failed to get %s array from file id %d",              id_table,exoid);      ex_err("ex_id_lkup",errmsg,exerrval);      free(id_vals);      return (EX_FATAL);    }    /* check if values in stored arrays are filled with non-zeroes */    filled = TRUE;    for (i=0;i<dim_len;i++) {      if (id_vals[i] == 0 || id_vals[i] == NC_FILL_INT) {        filled = FALSE;        break; /* id array hasn't been completely filled with valid ids yet */      }    }    if (filled) {      tmp_stats->valid_ids = TRUE;      tmp_stats->num = dim_len;      tmp_stats->id_vals = id_vals;    }  } else {    id_vals = tmp_stats->id_vals;    dim_len = tmp_stats->num;  }  /* Do a linear search through the id array to find the array value     corresponding to the passed index number */  for (i=0;i<dim_len;i++) {    if (id_vals[i] == num)      break; /* found the id requested */  }  if (i >= dim_len) /* failed to find id number */  {    if ( !(tmp_stats->valid_ids) ) {       free (id_vals);    }    exerrval = EX_LOOKUPFAIL;    return(EX_LOOKUPFAIL); /*if we got here, the id array value doesn't exist */  }    /* Now check status array to see if object is null */  /* get variable id of status array */  if (nc_inq_varid (exoid, stat_table, &varid) == NC_NOERR) {    /* if status array exists, use it, otherwise assume object exists        to be backward compatible */    if ( (tmp_stats->stat_vals == NULL) || (!(tmp_stats->valid_stat)) ) {      /* first time thru or status arrays haven't been filled yet */       /* allocate space for new status array */      if (!(stat_vals = malloc((int)dim_len*sizeof(int)))) {        exerrval = EX_MEMFAIL;        sprintf(errmsg,                 "Error: failed to allocate memory for %s array for file id %d",                  id_table,exoid);        ex_err("ex_id_lkup",errmsg,exerrval);        return (EX_FATAL);      }      if ((status = nc_get_var_int (exoid, varid, stat_vals)) != NC_NOERR) {        exerrval = status;        free(stat_vals);        sprintf(errmsg,               "Error: failed to get %s array from file id %d",                stat_table,exoid);        ex_err("ex_id_lkup",errmsg,exerrval);        return (EX_FATAL);      }      if (tmp_stats->valid_ids) {          /* status array is valid only if ids are valid */        tmp_stats->valid_stat = TRUE;        tmp_stats->stat_vals = stat_vals;      }    } else {      stat_vals = tmp_stats->stat_vals;    }    if (stat_vals[i] == 0) /* is this object null? */ {      exerrval =  EX_NULLENTITY;      if ( !(tmp_stats->valid_stat) ) {        free (stat_vals);      }      if ( !(tmp_stats->valid_ids) ) {        if (id_vals) free (id_vals);       }      return(-(i+1)); /* return index into id array (1-based) */    }  }  if ( !(tmp_stats->valid_ids) ) {    if (id_vals) free (id_vals);    if (stat_vals) free (stat_vals);  }  return(i+1); /* return index into id array (1-based) */}/******************************************************************************** ex_get_stat_ptr - returns a pointer to a structure of object ids** revision history - *******************************************************************************//*! this routine returns a pointer to a structure containing the ids of  * element blocks, node sets, or side sets according to exoid;  if there * is not a structure that matches the exoid, one is created */struct obj_stats *ex_get_stat_ptr (int exoid, struct obj_stats **obj_ptr){  struct obj_stats *tmp_ptr;  tmp_ptr = *obj_ptr;  while (tmp_ptr) {    if ( (tmp_ptr)->exoid == exoid) {      break;    }    tmp_ptr = (tmp_ptr)->next;  }  if (!tmp_ptr) {    /* exoid not found */    tmp_ptr = (struct obj_stats *) calloc (1, sizeof(struct obj_stats));    tmp_ptr->exoid = exoid;    tmp_ptr->next = *obj_ptr;    tmp_ptr->id_vals = 0;    tmp_ptr->stat_vals = 0;    tmp_ptr->num = 0;    tmp_ptr->valid_ids = 0;    tmp_ptr->valid_stat = 0;    *obj_ptr = tmp_ptr;  }  return (tmp_ptr);}/******************************************************************************** ex_rm_stat_ptr - removes a pointer to a structure of object ids** revision history - *******************************************************************************//*! this routine removes a pointer to a structure containing the ids of  * element blocks, node sets, or side sets according to exoid;  this * is necessary to clean up because netCDF reuses file ids;  should be * called from ex_close */void ex_rm_stat_ptr (int exoid, struct obj_stats **obj_ptr){  struct obj_stats *last_head_list_ptr, *tmp_ptr;  tmp_ptr = *obj_ptr;  last_head_list_ptr = *obj_ptr;        /* save last head pointer */  while (tmp_ptr )                      /* Walk linked list of file ids/vals */  {    if (exoid == tmp_ptr->exoid )       /* linear search for exodus file id */    {      if (tmp_ptr == *obj_ptr)          /* Are we at the head of the list? */        *obj_ptr = (*obj_ptr)->next;    /*   yes, reset ptr to head of list */      else                              /*   no, remove this record from chain*/        last_head_list_ptr->next=tmp_ptr->next;      if (tmp_ptr->id_vals != NULL)        free(tmp_ptr->id_vals);           /* free up memory */      if (tmp_ptr->stat_vals != NULL)        free(tmp_ptr->stat_vals);      free(tmp_ptr);      break;                            /* Quit if found */    }    last_head_list_ptr = tmp_ptr;       /* save last head pointer */    tmp_ptr = tmp_ptr->next;            /* Loop back if not */  }}/* structures to hold number of blocks of that type for each file id */ static struct list_item*  ed_ctr_list = 0; /* edge blocks */static struct list_item*  fa_ctr_list = 0; /* face blocks */static struct list_item*  eb_ctr_list = 0; /* element blocks *//* structures to hold number of sets of that type for each file id */ static struct list_item*  ns_ctr_list = 0; /* node sets */static struct list_item*  es_ctr_list = 0; /* edge sets */static struct list_item*  fs_ctr_list = 0; /* face sets */static struct list_item*  ss_ctr_list = 0; /* side sets */static struct list_item* els_ctr_list = 0; /* element sets *//* structures to hold number of maps of that type for each file id */ static struct list_item*  nm_ctr_list = 0; /* node maps */static struct list_item* edm_ctr_list = 0; /* edge maps */static struct list_item* fam_ctr_list = 0; /* face maps */static struct list_item*  em_ctr_list = 0; /* element maps */struct list_item** ex_get_counter_list(ex_entity_type obj_type){  switch(obj_type) {  case EX_ELEM_BLOCK:    return &eb_ctr_list;  case EX_NODE_SET:    return &ns_ctr_list;  case EX_SIDE_SET:    return &ss_ctr_list;  case EX_ELEM_MAP:    return &em_ctr_list;  case EX_NODE_MAP:    return &nm_ctr_list;  case EX_EDGE_BLOCK:    return &ed_ctr_list;  case EX_FACE_BLOCK:    return &fa_ctr_list;  case EX_EDGE_SET:    return &es_ctr_list;  case EX_FACE_SET:    return &fs_ctr_list;  case EX_ELEM_SET:    return &els_ctr_list;  case EX_EDGE_MAP:    return &edm_ctr_list;  case EX_FACE_MAP:    return &fam_ctr_list;  default:    return (NULL);  }}/******************************************************************************** ex_inc_file_item - increment file item******************************************************************************//*! this routine sets up a structure to track and increment a counter for * each open exodus file.  it is designed to be used by the routines * ex_put_elem_block() and ex_put_set_param(), * to keep track of the number of element blocks, and each type of set, * respectively, for each open exodus II file. * * The list structure is used as follows: * *   ptr -----------> list item structure *                    ------------------- *                    exodus file id *                    item value (int) *                    ptr to next (NULL if last) * * * NOTE: since netCDF reuses its file ids, and a user may open and close any *       number of files in one application, items must be taken out of the *       linked lists in each of the above routines.  these should be called *       after ncclose(). */int ex_inc_file_item( int exoid,                /* file id */                      struct list_item **list_ptr)/* ptr to ptr to list_item */{  struct list_item* tlist_ptr;  /* printf("[f] list: %ld, *list: %ld \n", list_ptr, *list_ptr); */  tlist_ptr = *list_ptr;        /* use temp list ptr to walk linked list */  while (tlist_ptr )                    /* Walk linked list of file ids/vals */  {    if (exoid == tlist_ptr->exo_id )    /* linear search for exodus file id */      break;                            /* Quit if found */    tlist_ptr = tlist_ptr->next;        /* Loop back if not */  }  if (!tlist_ptr )                      /* ptr NULL? */  {                                     /*  yes, new file id */    /* allocate space for new structure record */    tlist_ptr = (struct list_item*) calloc(1,sizeof(struct list_item));    tlist_ptr->exo_id = exoid;          /* insert file id */    tlist_ptr->next = *list_ptr;        /* insert into head of list */    *list_ptr = tlist_ptr;              /* fix up new head of list  */  }/*  printf("[f] tlist: %ld *tlist: %ld **tlist: %ld\n",          tlist_ptr,*tlist_ptr,(*tlist_ptr)->value, (*tlist_ptr)->next); */    return(tlist_ptr->value++);}/******************************************************************************* ex_get_file_item - increment file item******************************************************************************//*! this routine accesses a structure to track and increment a counter for * each open exodus file.  it is designed to be used by the routines * ex_put_elem_block(), and ex_put_set_param(), * to get the number of element blocks, or a type of set, * respectively, for an open exodus II file. * * The list structure is used as follows: * *   ptr -----------> list item structure *                    ------------------- *                    exodus file id *                    item value (int) *                    ptr to next (NULL if last) * * * NOTE: since netCDF reuses its file ids, and a user may open and close any *       number of files in one application, items must be taken out of the *       linked lists in each of the above routines.  these should be called *       after ncclose(). */int ex_get_file_item( int exoid,                /* file id */                      struct list_item **list_ptr)/* ptr to ptr to list_item */{  struct list_item* tlist_ptr;  /* printf("[f] list: %ld, *list: %ld \n", list_ptr, *list_ptr); */  tlist_ptr = *list_ptr;        /* use temp list ptr to walk linked list */  while (tlist_ptr )                    /* Walk linked list of file ids/vals */  {    if (exoid == tlist_ptr->exo_id )    /* linear search for exodus file id */      break;                            /* Quit if found */    tlist_ptr = tlist_ptr->next;        /* Loop back if not */  }  if (!tlist_ptr )                      /* ptr NULL? */  {                                     /*  yes, Error: file id not found*/    return(-1);  }/*  printf("[f] list: %ld *list: %ld **list: %ld\n",          list_ptr,*list_ptr,(*list_ptr)->value, (*list_ptr)->next); */  return(tlist_ptr->value);}/******************************************************************************* ex_rm_file_item - remove file item******************************************************************************//*! this routine removes a structure to track and increment a counter for * each open exodus file. * * The list structure is used as follows: * *   ptr -----------> list item structure *                    ------------------- *                    exodus file id *                    item value (int) *                    ptr to next (NULL if last) * * * NOTE: since netCDF reuses its file ids, and a user may open and close any *       number of files in one application, items must be taken out of the *       linked lists in each of the above routines.  these should be called *       after ncclose(). */void ex_rm_file_item( int exoid,                /* file id */                      struct list_item **list_ptr)/* ptr to ptr to list_item */{  struct list_item *last_head_list_ptr, *tlist_ptr;

⌨️ 快捷键说明

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