示例#1
0
int ex_get_block_param( int exoid,
			ex_block *block )
{
  int dimid, connid, blk_id_ndx;
  size_t len, i;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  const char* dnument;
  const char* dnumnod;
  const char* dnumedg;
  const char* dnumfac;
  const char* dnumatt;
  const char* ablknam;
  const char* vblkcon;

  struct ex_file_item* file = ex_find_file_item(exoid);
  if (!file ) {
    char errmsg[MAX_ERR_LENGTH];
    exerrval = EX_BADFILEID;
    sprintf(errmsg,"Error: unknown file id %d in ex_get_block_param().",exoid);
    ex_err("ex_get_block_param",errmsg,exerrval);
  }
  
  exerrval = 0;

  /* First, locate index of element block id in VAR_ID_EL_BLK array */
  blk_id_ndx = ex_id_lkup(exoid,block->type,block->id);
  if (exerrval != 0)  {
    strcpy(block->topology, "NULL");     	/* NULL element type name */
    block->num_entry = 0;  /* no elements            */
    block->num_nodes_per_entry = 0;   /* no nodes               */
    block->num_edges_per_entry = 0;
    block->num_faces_per_entry = 0;
    block->num_attribute = 0;    /* no attributes          */
    if (exerrval == EX_NULLENTITY) {    /* NULL element block?    */
      return (EX_NOERR);
    } 
      sprintf(errmsg,
	      "Error: failed to locate %s id  %"PRId64" in id array in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",errmsg,exerrval);
      return (EX_FATAL);
    
  }

  switch (block->type) {
  case EX_EDGE_BLOCK:
    dnument = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedg = 0;
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
    vblkcon = VAR_EBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_FACE_BLOCK:
    dnument = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedg = 0; /* it is possible this might be non-NULL some day */
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
    vblkcon = VAR_FBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_ELEM_BLOCK:
    dnument = DIM_NUM_EL_IN_BLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedg = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfac = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    dnumatt = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
    vblkcon = VAR_CONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Bad block type parameter (%d) specified for file id %d.",
	     block->type, exoid );
    return (EX_FATAL);
  }

  /* inquire values of some dimensions */
  if ((status = nc_inq_dimid (exoid, dnument, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate number of entities in %s  %"PRId64" in file id %d",
	    ex_name_of_object(block->type),block->id,exoid);
    ex_err("ex_get_block_param",errmsg, exerrval);
    return(EX_FATAL);
  }
  
  if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get number of %ss in block  %"PRId64" in file id %d",
	    ex_name_of_object(block->type),block->id, exoid);
    ex_err("ex_get_block_param",errmsg, exerrval);
    return(EX_FATAL);
  }
  block->num_entry = len;

  if ((status = nc_inq_dimid (exoid, dnumnod, &dimid)) != NC_NOERR) {
    /* undefined => no node entries per element */
    len = 0;
  } else {
    if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of nodes/entity in %s  %"PRId64" in file id %d",
	      ex_name_of_object(block->type),block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
  }
  block->num_nodes_per_entry = len;

  if (!file->has_edges || block->type != EX_ELEM_BLOCK) {
    block->num_edges_per_entry = 0;
  } else {
    if ((status = nc_inq_dimid (exoid, dnumedg, &dimid)) != NC_NOERR) {
      /* undefined => no edge entries per element */
      len = 0;
    } else {
      if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of edges/entry in %s  %"PRId64" in file id %d",
		ex_name_of_object(block->type),block->id, exoid);
	ex_err("ex_get_block_param",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
    block->num_edges_per_entry = len;
  }

  if (!file->has_faces || block->type != EX_ELEM_BLOCK ) {
    block->num_faces_per_entry = 0;
  } else {
    if ((status = nc_inq_dimid (exoid, dnumfac, &dimid)) != NC_NOERR) {
      /* undefined => no face entries per element */
      len = 0;
    } else {
      if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of faces/entity in %s  %"PRId64" in file id %d",
		ex_name_of_object(block->type),block->id, exoid);
	ex_err("ex_get_block_param",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
    block->num_faces_per_entry = len;
  }

  if ((status = nc_inq_dimid (exoid, dnumatt, &dimid)) != NC_NOERR) {
    /* dimension is undefined */
    block->num_attribute = 0;
  } else {
    if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of attributes in %s  %"PRId64" in file id %d",
	      ex_name_of_object(block->type),block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    block->num_attribute = len;
  }

  if (block->num_nodes_per_entry > 0) {
    ; /* Do nothing, vblkcon should be correctly set already */
  } else if (block->num_edges_per_entry > 0) {
    vblkcon = VAR_EBCONN(blk_id_ndx);
  } else if (block->num_faces_per_entry > 0) {
    vblkcon = VAR_FCONN(blk_id_ndx);
  }

  if (vblkcon) {
    /* look up connectivity array for this element block id */
    if ((status = nc_inq_varid (exoid, vblkcon, &connid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate connectivity array for %s  %"PRId64" in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    
    if ((status = nc_inq_attlen (exoid, connid, ablknam, &len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get %s  %"PRId64" type in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    
    if (len > (MAX_STR_LENGTH+1)) {
      len = MAX_STR_LENGTH;
      sprintf (errmsg,
	       "Warning: %s  %"PRId64" type will be truncated to %ld chars", 
	       ex_name_of_object(block->type), block->id, (long)len);
      ex_err("ex_get_block_param",errmsg,EX_MSG);
    }
    
    for (i=0; i < MAX_STR_LENGTH+1; i++) {
      block->topology[i] = '\0';

    /* get the element type name */
    
}if ((status = nc_get_att_text (exoid, connid, ablknam, block->topology)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,"Error: failed to get %s  %"PRId64" type in file id %d",
	      ex_name_of_object(block->type), block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    
    /* get rid of trailing blanks */
    ex_trim_internal(block->topology);
  }
  return (EX_NOERR);
}
示例#2
0
int ex_get_conn( int   exoid,
                 ex_entity_type blk_type,
                 int   blk_id,
                 int*  nodeconn,
                 int*  edgeconn,
                 int*  faceconn )
{
    int connid, econnid, fconnid, blk_id_ndx, status;
    int numnodperentdim, numedgperentdim, numfacperentdim;
    int iexit = (EX_NOERR); /* exit status */
    size_t num_nodes_per_entry, num_edges_per_entry, num_faces_per_entry;
    char errmsg[MAX_ERR_LENGTH];

    const char* dnumblkent;
    const char* dnumnodent;
    const char* dnumedgent;
    const char* dnumfacent;
    const char* vnodeconn;
    const char* vedgeconn;
    const char* vfaceconn;

    /* Should we warn if edgeconn or faceconn are non-NULL?
     * No, fail silently so the same code can be used to read any type of block info.
     * However, we will warn if edgeconn or faceconn are NULL but num_edges_per_entry
     * or num_faces_per_entry (respectively) are positive.
     */
    exerrval = 0; /* clear error code */

    /* Locate index of element block id in VAR_ID_EL_BLK array */

    blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
    if (exerrval != 0)
    {
        if (exerrval == EX_NULLENTITY)
        {
            sprintf(errmsg,
                    "Warning: no connectivity array for NULL %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg,EX_MSG);
            return (EX_WARN); /* no connectivity array for this element block */
        }
        else
        {
            sprintf(errmsg,
                    "Error: failed to locate %s id %d in id array in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    switch (blk_type) {
    case EX_EDGE_BLOCK:
        dnumblkent = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
        dnumedgent = 0;
        dnumfacent = 0;
        vnodeconn = VAR_EBCONN(blk_id_ndx);
        vedgeconn = 0;
        vfaceconn = 0;
        break;
    case EX_FACE_BLOCK:
        dnumblkent = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
        dnumedgent = 0;
        dnumfacent = 0;
        vnodeconn = VAR_FBCONN(blk_id_ndx);
        vedgeconn = 0;
        vfaceconn = 0;
        break;
    case EX_ELEM_BLOCK:
        dnumblkent = DIM_NUM_EL_IN_BLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
        dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
        dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
        vnodeconn = VAR_CONN(blk_id_ndx);
        vedgeconn = VAR_ECONN(blk_id_ndx);
        vfaceconn = VAR_FCONN(blk_id_ndx);
        break;
    default:
        sprintf(errmsg,
                "Error: Called with invalid blk_type %d", blk_type );
        ex_err("ex_get_conn",errmsg,exerrval);
        return (EX_FATAL);
        break;
    }
    /* inquire id's of previously defined dimensions  */

    if ((status = nc_inq_dimid (exoid, dnumnodent, &numnodperentdim)) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate number of nodes/entity for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg,exerrval);
        return(EX_FATAL);
    }

    if (nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get number of nodes/entity for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    if ( dnumedgent ) {
        num_edges_per_entry = 0;
        if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) {
            numedgperentdim = -1;
        } else {
            if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get number of edges/entry for %s %d in file id %d",
                        ex_name_of_object(blk_type),blk_id,exoid);
                ex_err("ex_get_conn",errmsg, exerrval);
                return(EX_FATAL);
            }
        }
    }

    if ( dnumfacent ) {
        num_faces_per_entry = 0;
        if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) {
            numfacperentdim = -1;
        } else {
            if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get number of faces/entry for %s %d in file id %d",
                        ex_name_of_object(blk_type),blk_id,exoid);
                ex_err("ex_get_conn",errmsg, exerrval);
                return(EX_FATAL);
            }
        }
    }


    if ((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    status = 0;
    if (edgeconn && (numedgperentdim > 0) &&
            ((status = nc_inq_varid (exoid, vedgeconn, &econnid)) != NC_NOERR))
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate edge connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    if (faceconn && (numfacperentdim > 0) &&
            ((status = nc_inq_varid (exoid, vfaceconn, &fconnid)) != NC_NOERR))
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate face connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }


    /* read in the connectivity array */
    if ( edgeconn && num_edges_per_entry > 0) {
        status = nc_get_var_int(exoid, econnid, edgeconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get edge connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    if ( faceconn && num_faces_per_entry > 0) {
        status = nc_get_var_int(exoid, fconnid, faceconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get face connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    if ( nodeconn && num_nodes_per_entry > 0) {
        status = nc_get_var_int(exoid, connid, nodeconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    return iexit;
}
示例#3
0
文件: expblk.c 项目: hs9906/paraview
int ex_put_block( int         exoid,
                  int         blk_type,
                  int         blk_id,
                  const char* entry_descrip,
                  int         num_entries_this_blk,
                  int         num_nodes_per_entry,
                  int         num_edges_per_entry,
                  int         num_faces_per_entry,
                  int         num_attr_per_entry )
{
   int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim;
   long start[2], num_blk;
   nclong ldum;
   int cur_num_blk, numblkdim, numattrdim;
   int nnodperentdim, nedgperentdim = -1, nfacperentdim = -1;
   int connid, econnid, fconnid;
   char *cdum;
   char errmsg[MAX_ERR_LENGTH];
   const char* tname;
   const char* dnumblk;
   const char* vblkids;
   const char* vblksta;
   const char* vnodcon = 0;
   const char* vedgcon = 0;
   const char* vfaccon = 0;
   const char* vattnam = 0;
   const char* vblkatt = 0;
   const char* dneblk = 0;
   const char* dnape = 0;
   const char* dnnpe = 0;
   const char* dnepe = 0;
   const char* dnfpe = 0;
   struct list_item** ctr_list;

   exerrval  = 0; /* clear error code */

   cdum = 0;

   switch (blk_type) {
   case EX_EDGE_BLOCK:
     tname = "edge";
     dnumblk = DIM_NUM_ED_BLK;
     vblkids = VAR_ID_ED_BLK;
     vblksta = VAR_STAT_ED_BLK;
     ctr_list = &ed_ctr_list;
     break;
   case EX_FACE_BLOCK:
     tname = "face";
     dnumblk = DIM_NUM_FA_BLK;
     vblkids = VAR_ID_FA_BLK;
     vblksta = VAR_STAT_FA_BLK;
     ctr_list = &fa_ctr_list;
     break;
   case EX_ELEM_BLOCK:
     tname = "element";
     dnumblk = DIM_NUM_EL_BLK;
     vblkids = VAR_ID_EL_BLK;
     vblksta = VAR_STAT_EL_BLK;
     ctr_list = &eb_ctr_list;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg, "Error: Bad block type (%d) specified for file id %d",
       blk_type, exoid );
     ex_err( "ex_put_block", errmsg, exerrval );
     return (EX_FATAL);
   }

/* first check if any element blocks are specified */

   if ((dimid = (ncdimid (exoid, dnumblk))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: no element blocks defined in file id %d",
             exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Get number of element blocks defined for this file */
   if ((ncdiminq (exoid,dimid,cdum,&num_blk)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of element blocks in file id %d",
             exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Next: Make sure that this is not a duplicate element block id by
         searching the vblkids array.
   WARNING: This must be done outside of define mode because id_lkup accesses
            the database to determine the position
*/

   if ((varid = ncvarid (exoid, vblkids)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate element block ids in file id %d", exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);

   }

   blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
   if (exerrval != EX_LOOKUPFAIL)   /* found the element block id */
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
            "Error: element block id %d already exists in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Keep track of the total number of element blocks defined using a counter 
   stored in a linked list keyed by exoid.
   NOTE: ex_get_file_item  is a function that finds the number of element 
         blocks for a specific file and returns that value incremented.
*/
   cur_num_blk=ex_get_file_item(exoid, ctr_list);
   if (cur_num_blk >= num_blk)
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
          "Error: exceeded number of element blocks (%ld) defined in file id %d",
             num_blk,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }


/*   NOTE: ex_get_file_item  is a function that finds the number of element
         blocks for a specific file and returns that value incremented. */

   cur_num_blk=ex_inc_file_item(exoid, ctr_list);
   start[0] = (long)cur_num_blk;

/* write out element block id to previously defined id array variable*/

   ldum = (nclong)blk_id;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element block id to file id %d",
             exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   blk_id_ndx = start[0]+1; /* element id index into vblkids array*/

   if (num_entries_this_blk == 0) /* Is this a NULL element block? */
     blk_stat = 0; /* change element block status to NULL */
   else
     blk_stat = 1; /* change element block status to TRUE */

   if ((varid = ncvarid (exoid, vblksta)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
           "Error: failed to locate element block status in file id %d", exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   ldum = (nclong)blk_stat;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element id %d status to file id %d",
             blk_id, exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (num_entries_this_blk == 0) /* Is this a NULL element block? */
   {
     return(EX_NOERR);
   }


   /*
    * Check that storage required for connectivity array is less
    * than 2GB which is maximum size permitted by netcdf
    * (in large file mode). 1<<29 == max number of integer items.
    */
   if (num_entries_this_blk * num_nodes_per_entry  > (1<<29)) {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
             "Error: Size to store connectivity for element block %d exceeds 2GB in file id %d",
             blk_id, exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* put netcdf file into define mode  */
   if (ncredef (exoid) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }


   switch (blk_type) {
   case EX_EDGE_BLOCK:
     dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx);
     dnepe = 0;
     dnfpe = 0;
     dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
     vblkatt = VAR_EATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_EATTRIB(blk_id_ndx);
     vnodcon = VAR_EBCONN(blk_id_ndx);
     vedgcon = 0;
     vfaccon = 0;
     break;
   case EX_FACE_BLOCK:
     dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx);
     dnepe = 0;
     dnfpe = 0;
     dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
     vblkatt = VAR_FATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_FATTRIB(blk_id_ndx);
     vnodcon = VAR_FBCONN(blk_id_ndx);
     vedgcon = 0;
     vfaccon = 0;
     break;
   case EX_ELEM_BLOCK:
     dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx);
     dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx);
     dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx);
     dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
     vblkatt = VAR_ATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_ATTRIB(blk_id_ndx);
     vnodcon = VAR_CONN(blk_id_ndx);
     vedgcon = VAR_ECONN(blk_id_ndx);
     vfaccon = VAR_FCONN(blk_id_ndx);
     break;
   }
/* define some dimensions and variables*/

   if ((numblkdim = ncdimdef (exoid,dneblk,(long)num_entries_this_blk)) == -1)
   {
     if (ncerr == NC_ENAMEINUSE)        /* duplicate entry */
     {
       exerrval = ncerr;
       sprintf(errmsg,
             "Error: element block %d already defined in file id %d",
              blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
    "Error: failed to define number of elements/block for block %d file id %d",
              blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
     }
     goto error_ret;         /* exit define mode and return */
   }

   if ((nnodperentdim = ncdimdef (exoid,dnnpe,(long)num_nodes_per_entry)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
   "Error: failed to define number of nodes/element for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

   if ( dnepe && num_edges_per_entry > 0 ) {
     if ((nedgperentdim = ncdimdef (exoid,dnepe,(long)num_edges_per_entry)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define number of edges/element for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

   if ( dnfpe && num_faces_per_entry > 0 ) {
     if ((nfacperentdim = ncdimdef (exoid,dnfpe,(long)num_faces_per_entry)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define number of faces/element for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

/* element attribute array */

   if (num_attr_per_entry > 0)
   {

     if ((numattrdim = ncdimdef (exoid, dnape, (long)num_attr_per_entry)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
      "Error: failed to define number of attributes in block %d in file id %d",
               blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }

     dims[0] = numblkdim;
     dims[1] = numattrdim;

     if ((ncvardef (exoid, vblkatt, nc_flt_code(exoid), 2, dims)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
       "Error:  failed to define attributes for element block %d in file id %d",
               blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }

     /* inquire previously defined dimensions  */
     if ((strdim = ncdimid (exoid, DIM_STR)) < 0) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get string length in file id %d",exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       return (EX_FATAL);
     }
     
     /* Attribute names... */
     dims[0] = numattrdim;
     dims[1] = strdim;
      
     if (ncvardef (exoid, vattnam, NC_CHAR, 2, dims) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define element attribute name array in file id %d",exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
     
   }

/* element connectivity array */

   dims[0] = numblkdim;
   dims[1] = nnodperentdim;

   if ((connid = ncvardef (exoid, vnodcon, NC_LONG, 2, dims)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to create connectivity array for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

/* store element type as attribute of connectivity variable */

   if ((ncattput (exoid, connid, ATT_NAME_ELB, NC_CHAR, strlen(entry_descrip)+1, 
             (void*) entry_descrip)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element type name %s in file id %d",
             entry_descrip,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

   if ( vedgcon && num_edges_per_entry ) {
     dims[0] = numblkdim;
     dims[1] = nedgperentdim;

     if ((econnid = ncvardef (exoid, vedgcon, NC_LONG, 2, dims)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to create edge connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

   if ( vfaccon && num_faces_per_entry ) {
     dims[0] = numblkdim;
     dims[1] = nfacperentdim;

     if ((fconnid = ncvardef (exoid, vfaccon, NC_LONG, 2, dims)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to create face connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

/* leave define mode  */

   if (ncendef (exoid) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
       "Error: failed to complete element block definition in file id %d", 
        exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
       if (ncendef (exoid) == -1)     /* exit define mode */
       {
         sprintf(errmsg,
                "Error: failed to complete definition for file id %d",
                 exoid);
         ex_err("ex_put_elem_block",errmsg,exerrval);
       }
       return (EX_FATAL);
}
示例#4
0
int ex_put_conn (int   exoid,
                 ex_entity_type blk_type,
                 ex_entity_id   blk_id,
                 const void_int  *node_conn,
                 const void_int  *elem_edge_conn,
                 const void_int  *elem_face_conn)
{
   int connid=-1, blk_id_ndx, status;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
   if (exerrval != 0) {
     if (exerrval == EX_NULLENTITY) {
       sprintf(errmsg,
         "Warning: connectivity array not allowed for NULL %s %"PRId64" in file id %d",
	       ex_name_of_object(blk_type),blk_id,exoid);
       ex_err("ex_put_conn",errmsg,EX_NULLENTITY);
       return (EX_WARN);
       }
     else {
       sprintf(errmsg,
         "Error: failed to locate %s id %"PRId64" in id array in file id %d",
         ex_name_of_object(blk_type),blk_id, exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }
     }

/* inquire id's of previously defined dimensions  */
   if (node_conn) {
     switch (blk_type) {
     case EX_ELEM_BLOCK:
       status = nc_inq_varid (exoid, VAR_CONN(blk_id_ndx), &connid);
       break;
     case EX_FACE_BLOCK:
       status = nc_inq_varid (exoid, VAR_FBCONN(blk_id_ndx), &connid);
       break;
     case EX_EDGE_BLOCK:
       status = nc_inq_varid (exoid, VAR_EBCONN(blk_id_ndx), &connid);
       break;
     default:
       exerrval = 1005;
       sprintf(errmsg,
	       "Internal Error: unrecognized block type in switch: %d in file id %d",
	       blk_type,exoid);
       ex_err("ex_putt_conn",errmsg,EX_MSG);
       return (EX_FATAL);
     }
     if (status != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
	       "Error: failed to locate connectivity array for %s %"PRId64" in file id %d",
	       ex_name_of_object(blk_type),blk_id,exoid);
       ex_err("ex_put_conn",errmsg, exerrval);
       return(EX_FATAL);
     }
     
     EX_WRITE_CONN(ex_name_of_object(blk_type),connid,node_conn);
   }

   /* If there are edge and face connectivity arrays that belong with the element
    * block, write them now. Warn if they are required but not specified or
    * specified but not required.
    */
   if ( blk_type == EX_ELEM_BLOCK ) {
     int nedpereldim, nfapereldim;
     size_t num_ed_per_elem, num_fa_per_elem;

     status = nc_inq_dimid (exoid, DIM_NUM_EDG_PER_EL(blk_id_ndx), &nedpereldim);
     if (status != NC_NOERR && elem_edge_conn != 0)
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: edge connectivity specified but failed to "
         "locate number of edges/element in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     status = nc_inq_dimid (exoid, DIM_NUM_FAC_PER_EL(blk_id_ndx), &nfapereldim);
     if (status != NC_NOERR && elem_face_conn != 0)
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: face connectivity specified but failed to "
         "locate number of faces/element in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     num_ed_per_elem = 0;
     if ((elem_edge_conn != 0) &&
	 (status = nc_inq_dimlen(exoid, nedpereldim, &num_ed_per_elem) != NC_NOERR))
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: failed to get number of edges/elem in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     num_fa_per_elem = 0;
     if ((elem_face_conn != 0) &&
	 (status = nc_inq_dimlen(exoid, nfapereldim, &num_fa_per_elem) != NC_NOERR))
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: failed to get number of faces/elem in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     if ( (num_ed_per_elem == 0 && elem_edge_conn != 0) ||
          (num_ed_per_elem != 0 && elem_edge_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of edges per element (%ld) doesn't "
         "agree with elem_edge_conn (0x%p)",
	       (long)num_ed_per_elem, (void*)elem_edge_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( (num_fa_per_elem == 0 && elem_face_conn != 0) ||
          (num_fa_per_elem != 0 && elem_face_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of faces per element (%ld) doesn't "
         "agree with elem_face_conn (0x%p)",
	       (long)num_fa_per_elem, (void*)elem_face_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( num_ed_per_elem != 0 ) {
       status = nc_inq_varid(exoid, VAR_ECONN(blk_id_ndx), &connid);
       if (status != NC_NOERR)
         {
         exerrval = status;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element edge block %"PRId64" in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element edge",connid,elem_edge_conn);
     }

     if ( num_fa_per_elem != 0 ) {
       status = nc_inq_varid (exoid, VAR_FCONN(blk_id_ndx), &connid);
       if (status != NC_NOERR)
         {
         exerrval = status;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element face block %"PRId64" in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element face",connid,elem_face_conn);
     }
   }

   return (EX_NOERR);

}
int ex_get_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, void_int *nodeconn,
                void_int *edgeconn, void_int *faceconn)
{
  int connid  = -1;
  int econnid = -1;
  int fconnid = -1;

  int blk_id_ndx, status;

  int numnodperentdim = -1;
  int numedgperentdim = -1;
  int numfacperentdim = -1;

  size_t num_nodes_per_entry = 0;
  size_t num_edges_per_entry = 0;
  size_t num_faces_per_entry = 0;

  char errmsg[MAX_ERR_LENGTH];

  const char *dnumnodent = NULL;
  const char *dnumedgent = NULL;
  const char *dnumfacent = NULL;
  const char *vnodeconn  = NULL;
  const char *vedgeconn  = NULL;
  const char *vfaceconn  = NULL;

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  /* Should we warn if edgeconn or faceconn are non-NULL?
   * No, fail silently so the same code can be used to read any type of block
   * info.
   * However, we will warn if edgeconn or faceconn are NULL but
   * num_edges_per_entry
   * or num_faces_per_entry (respectively) are positive.
   */

  /* Locate index of element block id in VAR_ID_EL_BLK array */

  blk_id_ndx = ex_id_lkup(exoid, blk_type, blk_id);
  if (blk_id_ndx <= 0) {
    ex_get_err(NULL, NULL, &status);
    if (status != 0) {
      if (status == EX_NULLENTITY) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "Warning: no connectivity array for NULL %s %" PRId64 " in file id %d",
                 ex_name_of_object(blk_type), blk_id, exoid);
        ex_err(__func__, errmsg, EX_NULLENTITY);
        EX_FUNC_LEAVE(EX_WARN); /* no connectivity array for this element block */
      }
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to locate %s id %" PRId64 " in id array in file id %d",
               ex_name_of_object(blk_type), blk_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn  = VAR_EBCONN(blk_id_ndx);
    vedgeconn  = 0;
    vfaceconn  = 0;
    break;
  case EX_FACE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn  = VAR_FBCONN(blk_id_ndx);
    vedgeconn  = 0;
    vfaceconn  = 0;
    break;
  case EX_ELEM_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    vnodeconn  = VAR_CONN(blk_id_ndx);
    vedgeconn  = VAR_ECONN(blk_id_ndx);
    vfaceconn  = VAR_FCONN(blk_id_ndx);
    break;
  default:
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Internal ERROR: unrecognized block type in switch: %d in file id %d", blk_type,
             exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
  }
  /* inquire id's of previously defined dimensions  */

  num_nodes_per_entry = 0;
  if (nodeconn && dnumnodent) {
    if ((status = nc_inq_dimid(exoid, dnumnodent, &numnodperentdim)) != NC_NOERR) {
      numnodperentdim = -1;
    }
    else {
      if ((status = nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get number of nodes/entity for %s %" PRId64 " in file id %d",
                 ex_name_of_object(blk_type), blk_id, exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
  }

  if (edgeconn && dnumedgent) {
    num_edges_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) {
      numedgperentdim = -1;
    }
    else {
      if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get number of edges/entry for %s %" PRId64 " in file id %d",
                 ex_name_of_object(blk_type), blk_id, exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
  }

  if (faceconn && dnumfacent) {
    num_faces_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) {
      numfacperentdim = -1;
    }
    else {
      if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get number of faces/entry for %s %" PRId64 " in file id %d",
                 ex_name_of_object(blk_type), blk_id, exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
  }

  status = 0;
  if (nodeconn && (numnodperentdim >= 0) &&
      ((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR)) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate node connectivity array for %s %" PRId64 " in file id %d",
             ex_name_of_object(blk_type), blk_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  status = 0;
  if (edgeconn && (numedgperentdim >= 0) &&
      ((status = nc_inq_varid(exoid, vedgeconn, &econnid)) != NC_NOERR)) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate edge connectivity array for %s %" PRId64 " in file id %d",
             ex_name_of_object(blk_type), blk_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  if (faceconn && (numfacperentdim >= 0) &&
      ((status = nc_inq_varid(exoid, vfaceconn, &fconnid)) != NC_NOERR)) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate face connectivity array for %s %" PRId64 " in file id %d",
             ex_name_of_object(blk_type), blk_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* read in the connectivity array */
  if (edgeconn && num_edges_per_entry > 0) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_var_longlong(exoid, econnid, edgeconn);
    }
    else {
      status = nc_get_var_int(exoid, econnid, edgeconn);
    }

    if (status != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get edge connectivity array for %s %" PRId64 " in file id %d",
               ex_name_of_object(blk_type), blk_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  if (faceconn && num_faces_per_entry > 0) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_var_longlong(exoid, fconnid, faceconn);
    }
    else {
      status = nc_get_var_int(exoid, fconnid, faceconn);
    }

    if (status != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get face connectivity array for %s %" PRId64 " in file id %d",
               ex_name_of_object(blk_type), blk_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  if (nodeconn && num_nodes_per_entry > 0) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_var_longlong(exoid, connid, nodeconn);
    }
    else {
      status = nc_get_var_int(exoid, connid, nodeconn);
    }

    if (status != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get node connectivity array for %s %" PRId64 " in file id %d",
               ex_name_of_object(blk_type), blk_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  EX_FUNC_LEAVE(EX_NOERR);
}
示例#6
0
/*!
 * writes the parameters used to describe all element, edge, and face blocks
 * \param     exoid          exodus file id
 * \param     param         block parameters structure
 */
int ex_put_concat_all_blocks (int    exoid,
                              const ex_block_params *param)
{
  int varid, dimid, dims[2], strdim, *eb_stat, *ed_stat, *fa_stat;
  int temp;
  size_t iblk;
  int status;
  size_t num_elem_blk, num_edge_blk, num_face_blk, i;
  int cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid=-1;
  int cur_num_edge_blk, numedbdim, nednoddim, cur_num_face_blk, numfabdim, nfanoddim;
  int neledgdim=-1, nelfacdim=-1;
  char errmsg[MAX_ERR_LENGTH];
  int elem_work = 0; /* is DIM_NUM_EL_BLK defined? If so, there's work to do */
  int edge_work = 0; /* is DIM_NUM_ED_BLK defined? If so, there's work to do */
  int face_work = 0; /* is DIM_NUM_FA_BLK defined? If so, there's work to do */
  static const char* dim_num_maps[] = {
    DIM_NUM_NM,
    DIM_NUM_EDM,
    DIM_NUM_FAM,
    DIM_NUM_EM,
  };
  static const char* dim_size_maps[] = {
    DIM_NUM_NODES,
    DIM_NUM_EDGE,
    DIM_NUM_FACE,
    DIM_NUM_ELEM,
  };
  static const ex_entity_type map_enums[] = {
    EX_NODE_MAP,
    EX_EDGE_MAP,
    EX_FACE_MAP,
    EX_ELEM_MAP
  };
  /* If param->define_maps is true, we must fill these with values from ex_put_init_ext
     before entering define mode */
  size_t num_maps[sizeof(dim_num_maps)/sizeof(dim_num_maps[0])];
  size_t num_map_dims = sizeof(dim_num_maps)/sizeof(dim_num_maps[0]);

  exerrval  = 0; /* clear error code */

  /* inquire previously defined dimensions  */
  if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get string length in file id %d",exoid);
    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ( param->define_maps ) {
    for ( i = 0; i < num_map_dims; ++i ) {
      if ((status = nc_inq_dimid(exoid, dim_num_maps[i], &dimid)) != NC_NOERR) {
        exerrval = status;
        sprintf( errmsg, "Error: failed to find node map size of file id %d", exoid );
        ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );
        return (EX_FATAL);
      }
      if ((status = nc_inq_dimlen(exoid, dimid, num_maps+i)) != NC_NOERR) {
	exerrval = status;
	sprintf( errmsg, "Error: failed to retrieve node map size of file id %d", exoid );
	ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );
	return (EX_FATAL);
      }
    }
  }

#define EX_PREPARE_BLOCK(TNAME,WNAME,DNUMNAME,VSTATNAME,VIDNAME,LNUMNAME,SNUMNAME,SIDNAME,GSTAT) \
  /* first check if any TNAME blocks are specified			\
   * OK if zero...							\
   */									\
    if ((status = (nc_inq_dimid(exoid, DNUMNAME, &dimid))) == NC_NOERR) { \
      WNAME = 1;							\
									\
      /* Get number of TNAME blocks defined for this file */		\
      if ((status = nc_inq_dimlen(exoid,dimid,&LNUMNAME)) != NC_NOERR) { \
	exerrval = status;						\
	sprintf(errmsg,							\
		"Error: failed to get number of " TNAME " blocks in file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
									\
      /* Fill out the TNAME block status array */			\
      if (!(GSTAT = malloc(LNUMNAME*sizeof(int)))) {			\
	exerrval = EX_MEMFAIL;						\
	sprintf(errmsg,							\
		"Error: failed to allocate space for " TNAME " block status array in file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
									\
      for (i=0;i<LNUMNAME;i++) {					\
	if (SNUMNAME[i] == 0) /* Is this a NULL TNAME block? */		\
	  GSTAT[i] = 0; /* change TNAME block status to NULL */		\
	else								\
	  GSTAT[i] = 1; /* change TNAME block status to TRUE */		\
      }									\
									\
      /* Next, get variable id of status array */			\
      if ((status = nc_inq_varid(exoid, VSTATNAME, &varid)) != NC_NOERR) { \
	exerrval = status;						\
	sprintf(errmsg,							\
		"Error: failed to locate " TNAME " block status in file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
									\
      status = nc_put_var_int(exoid, varid, GSTAT);			\
									\
      if (status != NC_NOERR) {						\
	exerrval = status;						\
	sprintf(errmsg,							\
		"Error: failed to store " TNAME " block status array to file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
									\
      free(GSTAT);							\
									\
      /* Next, fill out ids array */					\
      /* first get id of ids array variable */				\
      if ((status = nc_inq_varid(exoid, VIDNAME, &varid)) != NC_NOERR) { \
	exerrval = status;						\
	sprintf(errmsg,							\
		"Error: failed to locate " TNAME " block ids array in file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
									\
      /* then, write out id list */					\
      status = nc_put_var_int(exoid, varid, SIDNAME);			\
									\
      if (status != NC_NOERR) {						\
	exerrval = status;						\
	sprintf(errmsg,							\
		"Error: failed to store " TNAME " block id array in file id %d", \
		exoid);							\
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
	return (EX_FATAL);						\
      }									\
    }

  EX_PREPARE_BLOCK("element",elem_work,DIM_NUM_EL_BLK,VAR_STAT_EL_BLK,VAR_ID_EL_BLK,
		   num_elem_blk,param->num_elem_this_blk,param->elem_blk_id,eb_stat);
  EX_PREPARE_BLOCK(   "edge",edge_work,DIM_NUM_ED_BLK,VAR_STAT_ED_BLK,VAR_ID_ED_BLK,
		      num_edge_blk,param->num_edge_this_blk,param->edge_blk_id,ed_stat);
  EX_PREPARE_BLOCK(   "face",face_work,DIM_NUM_FA_BLK,VAR_STAT_FA_BLK,VAR_ID_FA_BLK,
		      num_face_blk,param->num_face_this_blk,param->face_blk_id,fa_stat);

  if ( elem_work == 0 && edge_work == 0 && face_work == 0 && param->define_maps == 0 ) {
    /* Nothing to do. This is not an error, but we can save
     * ourselves from entering define mode by returning here.
     */
    return (EX_NOERR);
  }
  /* put netcdf file into define mode  */
  if ((status = nc_redef(exoid)) != NC_NOERR)  {
    exerrval = status;
    sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
    return (EX_FATAL);
  }

#define EX_PREPARE_ATTRIB_ARRAY(TNAME,CURBLK,DNAME,DVAL,ID,VANAME,VADIM0,VADIM1,VANNAME) \
  if (DVAL[iblk] > 0) {							\
    if ((status = nc_def_dim (exoid,					\
			      DNAME(CURBLK+1),				\
			      DVAL[iblk], &VADIM1)) != NC_NOERR) { \
      exerrval = status;						\
      sprintf(errmsg,							\
	      "Error: failed to define number of attributes in " TNAME " block %d in file id %d", \
	      ID[iblk],exoid);						\
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
      goto error_ret;         /* exit define mode and return */		\
    }									\
									\
    dims[0] = VADIM0;							\
    dims[1] = VADIM1;							\
									\
    if ((status = nc_def_var (exoid, VANAME(CURBLK+1),			\
			      nc_flt_code(exoid), 2, dims, &temp)) != NC_NOERR) { \
      exerrval = status;						\
      sprintf(errmsg,							\
	      "Error:  failed to define attributes for " TNAME " block %d in file id %d", \
	      ID[iblk],exoid);						\
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
      goto error_ret;         /* exit define mode and return */		\
    }									\
									\
    /* Attribute names... */						\
    dims[0] = VADIM1;							\
    dims[1] = strdim;							\
									\
    if ((status = nc_def_var(exoid, VANNAME(CURBLK+1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) { \
      exerrval = status;						\
      sprintf(errmsg,							\
	      "Error: failed to define " TNAME " attribute name array in file id %d",exoid); \
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
      goto error_ret;         /* exit define mode and return */		\
    }									\
  }

#define EX_PREPARE_CONN(TNAME,BLK,BLKID,BLKSZ,VNAME,DNAME)		\
  if ( DNAME > 0 ) {							\
    dims[0] = BLKSZ;							\
    dims[1] = DNAME;							\
									\
    if ((status = nc_def_var(exoid, VNAME(BLK+1),			\
			     NC_INT, 2, dims, &connid)) != NC_NOERR) {	\
      exerrval = status;						\
      sprintf(errmsg,							\
	      "Error: failed to create " TNAME " connectivity array for block %d in file id %d", \
	      BLKID[iblk],exoid);					\
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\
      goto error_ret;         /* exit define mode and return */		\
    }									\
  }


  /* Iterate over edge blocks ... */
  for (iblk = 0; iblk < num_edge_blk; ++iblk) {

    cur_num_edge_blk=ex_get_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));
    if (cur_num_edge_blk >= (int)num_edge_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of edge blocks (%ld) defined in file id %d",
	      (long)num_edge_blk,exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of edge blocks
       for a specific file and returns that value incremented. */
    cur_num_edge_blk=ex_inc_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));

    if (param->num_edge_this_blk[iblk] == 0) /* Is this a NULL edge block? */
      continue;

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid,
			     DIM_NUM_ED_IN_EBLK(cur_num_edge_blk+1),
			     param->num_edge_this_blk[iblk],&numedbdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {     /* duplicate entry */
	sprintf(errmsg,
		"Error: edge block %d already defined in file id %d",
		param->edge_blk_id[iblk],exoid);
      } else {
	sprintf(errmsg,
		"Error: failed to define number of edges/block for block %d file id %d",
		param->edge_blk_id[iblk],exoid);
      }
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid,
			     DIM_NUM_NOD_PER_ED(cur_num_edge_blk+1),
			     param->num_nodes_per_edge[iblk],&nednoddim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to define number of nodes/edge for block %d in file id %d",
	      param->edge_blk_id[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* edge attribute array */
    EX_PREPARE_ATTRIB_ARRAY("edge",cur_num_edge_blk,DIM_NUM_ATT_IN_EBLK,param->num_attr_edge,param->edge_blk_id,VAR_EATTRIB,numedbdim,numattrdim,VAR_NAME_EATTRIB);

    EX_PREPARE_CONN("edge block",cur_num_edge_blk,param->edge_blk_id,numedbdim,VAR_EBCONN,nednoddim);

    /* store edge type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->edge_type[iblk])+1,
				  (void*)param->edge_type[iblk])) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store edge type name %s in file id %d",
	      param->edge_type[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  /* Iterate over face blocks ... */
  for (iblk = 0; iblk < num_face_blk; ++iblk) {

    cur_num_face_blk=ex_get_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));
    if (cur_num_face_blk >= (int)num_face_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of face blocks (%ld) defined in file id %d",
	      (long)num_face_blk,exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of edge blocks
       for a specific file and returns that value incremented. */
    cur_num_face_blk=ex_inc_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));

    if (param->num_face_this_blk[iblk] == 0) /* Is this a NULL face block? */
      continue;

    /* define some dimensions and variables*/
    if ((status = nc_def_dim (exoid,
			      DIM_NUM_FA_IN_FBLK(cur_num_face_blk+1),
			      param->num_face_this_blk[iblk],&numfabdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {     /* duplicate entry */
	sprintf(errmsg,
		"Error: face block %d already defined in file id %d",
		param->face_blk_id[iblk],exoid);
      } else {
	sprintf(errmsg,
		"Error: failed to define number of faces/block for block %d file id %d",
		param->face_blk_id[iblk],exoid);
      }
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if ((status = nc_def_dim (exoid,
			      DIM_NUM_NOD_PER_FA(cur_num_face_blk+1),
			      param->num_nodes_per_face[iblk],&nfanoddim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to define number of nodes/face for block %d in file id %d",
	      param->face_blk_id[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* edge attribute array */
    EX_PREPARE_ATTRIB_ARRAY("face",cur_num_face_blk,DIM_NUM_ATT_IN_FBLK,param->num_attr_face,param->face_blk_id,VAR_FATTRIB,numfabdim,numattrdim,VAR_NAME_FATTRIB);

    EX_PREPARE_CONN("face block",cur_num_face_blk,param->face_blk_id,numfabdim,VAR_FBCONN,nfanoddim);

    /* store face type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->face_type[iblk])+1,
				  (void*)param->face_type[iblk])) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store face type name %s in file id %d",
	      param->face_type[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  /* Iterate over element blocks ... */
  for (iblk = 0; iblk < num_elem_blk; ++iblk) {

    cur_num_elem_blk=ex_get_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
    if (cur_num_elem_blk >= (int)num_elem_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of element blocks (%ld) defined in file id %d",
	      (long)num_elem_blk,exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of element blocks
       for a specific file and returns that value incremented. */
    cur_num_elem_blk=ex_inc_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));

    if (param->num_elem_this_blk[iblk] == 0) /* Is this a NULL element block? */
      continue;

    /* define some dimensions and variables*/
    if ((status = nc_def_dim (exoid,
			      DIM_NUM_EL_IN_BLK(cur_num_elem_blk+1),
			      param->num_elem_this_blk[iblk], &numelbdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {     /* duplicate entry */
	sprintf(errmsg,
		"Error: element block %d already defined in file id %d",
		param->elem_blk_id[iblk],exoid);
      } else {
	sprintf(errmsg,
		"Error: failed to define number of elements/block for block %d file id %d",
		param->elem_blk_id[iblk],exoid);
      }
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* Always define DIM_NUM_NOD_PER_EL, even if zero.
     * Do not define DIM_NUM_EDG_PER_EL or DIM_NUM_FAC_PER_EL unless > 0.
     */
    if ((status = nc_def_dim (exoid,
			      DIM_NUM_NOD_PER_EL(cur_num_elem_blk+1),
			      param->num_nodes_per_elem[iblk], &nelnoddim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to define number of nodes/element for block %d in file id %d",
	      param->elem_blk_id[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if ( param->num_edges_per_elem[iblk] > 0 ) {
      if ((status = nc_def_dim (exoid,
				DIM_NUM_EDG_PER_EL(cur_num_elem_blk+1),
				param->num_edges_per_elem[iblk],&neledgdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of edges/element for block %d in file id %d",
		param->elem_blk_id[iblk],exoid);
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    if ( param->num_faces_per_elem[iblk] > 0 ) {
      if ((status = nc_def_dim(exoid,
			       DIM_NUM_FAC_PER_EL(cur_num_elem_blk+1),
			       param->num_faces_per_elem[iblk],&nelfacdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of faces/element for block %d in file id %d",
		param->elem_blk_id[iblk],exoid);
	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    /* element attribute array */
    EX_PREPARE_ATTRIB_ARRAY("element",cur_num_elem_blk,DIM_NUM_ATT_IN_BLK,param->num_attr_elem,param->elem_blk_id,VAR_ATTRIB,numelbdim,numattrdim,VAR_NAME_ATTRIB);
    
    /* element connectivity array */
    EX_PREPARE_CONN("nodal",cur_num_elem_blk,param->elem_blk_id,numelbdim,VAR_CONN,nelnoddim);

    /* store element type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->elem_type[iblk])+1,
				  (void*)param->elem_type[iblk])) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store element type name %s in file id %d",
	      param->elem_type[iblk],exoid);
      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    EX_PREPARE_CONN( "edge",cur_num_elem_blk,param->elem_blk_id,numelbdim,VAR_ECONN,neledgdim);
    EX_PREPARE_CONN( "face",cur_num_elem_blk,param->elem_blk_id,numelbdim,VAR_FCONN,nelfacdim);
  }

  /* Define the element map here to avoid a later redefine call */
  if ( param->define_maps != 0 ) {
    size_t map_type;
    for ( map_type = 0; map_type < num_map_dims; ++map_type ) {
      if ((status = nc_inq_dimid(exoid, dim_size_maps[map_type], &dims[0])) != NC_NOERR) {
	exerrval = status;
	sprintf( errmsg,
		 "Error: could not find map size dimension %s in file id %d",
		 dim_size_maps[map_type], exoid );
	ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );
      }
      for ( i = 1; i <= num_maps[map_type]; ++i ) {
	const char* mapname = ex_name_of_map( map_enums[map_type], i );
	if (nc_inq_varid(exoid, mapname, &temp) != NC_NOERR) {
	  if ((status = nc_def_var(exoid, mapname, NC_INT, 1, dims, &temp)) != NC_NOERR) {
	    exerrval = status;
	    if ( status == NC_ENAMEINUSE ) {
	      sprintf( errmsg, "Error: number map %s already exists in file id %d", mapname, exoid );
	    } else {
	      sprintf( errmsg, "Error: failed to create number map array %s in file id %d", mapname, exoid );
	    }
	    ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );
	    goto error_ret; /* exit define mode and return */
	  }
	}
      }
    }
  }

  /* leave define mode  */
  if ((status = nc_enddef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to complete element block definition in file id %d", 
	    exoid);
    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);
  
  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {     /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#7
0
int ex_get_partial_conn( int   exoid,
		   ex_entity_type blk_type,
		   ex_entity_id   blk_id,
		   int64_t   start_num,
		   int64_t   num_ent,
		   void_int*  nodeconn,
		   void_int*  edgeconn,
		   void_int*  faceconn )
{
  int connid = -1;
  int econnid = -1;
  int fconnid = -1;

  int blk_id_ndx;
  int status = 0;

  int numnodperentdim = -1;
  int numedgperentdim = -1;
  int numfacperentdim = -1;

  int iexit = (EX_NOERR); /* exit status */

  size_t num_nodes_per_entry = 0;
  size_t num_edges_per_entry = 0;
  size_t num_faces_per_entry = 0;
  char errmsg[MAX_ERR_LENGTH];

  const char* dnumnodent = NULL;
  const char* dnumedgent = NULL;
  const char* dnumfacent = NULL;
  const char* vnodeconn = NULL;
  const char* vedgeconn = NULL;
  const char* vfaceconn = NULL;

  /* The partial connectivity input function can currently only handle nodal
   * connectivity.  Print a warning if edgeconn or faceconn is non-NULL
   */
  if (edgeconn != NULL || faceconn != NULL) {
    exerrval = 1005;
    sprintf(errmsg,
	    "Warning: ex_get_partial_conn only supports nodal connectivity at this time. %s %"PRId64" in file id %d",
	    ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_get_partial_conn",errmsg,EX_MSG);
  }

  exerrval = 0; /* clear error code */

  /* Locate index of element block id in VAR_ID_EL_BLK array */

  blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
  if (exerrval != 0) 
    {
      if (exerrval == EX_NULLENTITY)
	{
	  sprintf(errmsg,
		  "Warning: no connectivity array for NULL %s %"PRId64" in file id %d",
		  ex_name_of_object(blk_type),blk_id,exoid);
	  ex_err("ex_get_partial_conn",errmsg,EX_NULLENTITY);
	  return (EX_WARN); /* no connectivity array for this element block */
	}
      else
	{
	  sprintf(errmsg,
		  "Error: failed to locate %s id %"PRId64" in id array in file id %d",
		  ex_name_of_object(blk_type),blk_id,exoid);
	  ex_err("ex_get_partial_conn",errmsg,exerrval);
	  return (EX_FATAL);
	}
    }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn = VAR_EBCONN(blk_id_ndx);
    vedgeconn = 0;
    vfaceconn = 0;
    break;
  case EX_FACE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn = VAR_FBCONN(blk_id_ndx);
    vedgeconn = 0;
    vfaceconn = 0;
    break;
  case EX_ELEM_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    vnodeconn = VAR_CONN(blk_id_ndx);
    vedgeconn = VAR_ECONN(blk_id_ndx);
    vfaceconn = VAR_FCONN(blk_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized block type in switch: %d in file id %d",
	    blk_type,exoid);
    ex_err("ex_get_partial_conn",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }
  /* inquire id's of previously defined dimensions  */

  if ((status = nc_inq_dimid (exoid, dnumnodent, &numnodperentdim)) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate number of nodes/entity for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg,exerrval);
      return(EX_FATAL);
    }

  if (nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of nodes/entity for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  if ( edgeconn && dnumedgent ) {
    num_edges_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) {
      numedgperentdim = -1;
    } else {
      if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of edges/entry for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
  }

  if ( faceconn && dnumfacent ) {
    num_faces_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) {
      numfacperentdim = -1;
    } else {
      if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of faces/entry for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
  }


  if ((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  status = 0;
  if (edgeconn && (numedgperentdim > 0) &&
      ((status = nc_inq_varid (exoid, vedgeconn, &econnid)) != NC_NOERR))
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate edge connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  if (faceconn && (numfacperentdim > 0) &&
      ((status = nc_inq_varid (exoid, vfaceconn, &fconnid)) != NC_NOERR))
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate face connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }


  /* read in the connectivity array */
  if ( edgeconn && num_edges_per_entry > 0) {
    size_t start[2], count[2];
    
    start[0] = (start_num-1);
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_edges_per_entry;

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, econnid, start, count, edgeconn);
    } else {
      status = nc_get_vara_int(exoid, econnid, start, count, edgeconn);
    }

    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get edge connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  if ( faceconn && num_faces_per_entry > 0) {
    size_t start[2], count[2];
    
    start[0] = start_num-1;
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_faces_per_entry;
     
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, fconnid, start, count, faceconn);
    } else {
      status = nc_get_vara_int(exoid, fconnid, start, count, faceconn);
    }
     
    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get face connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  if ( nodeconn && num_nodes_per_entry > 0) {
    size_t start[2], count[2];
     
    start[0] = start_num-1;
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_nodes_per_entry;
     
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, connid, start, count, nodeconn);
    } else {
      status = nc_get_vara_int(exoid, connid, start, count, nodeconn);
    }

    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  return iexit;
}
示例#8
0
int ex_put_block( int         exoid,
                  ex_entity_type blk_type,
                  int         blk_id,
                  const char* entry_descrip,
                  int         num_entries_this_blk,
                  int         num_nodes_per_entry,
                  int         num_edges_per_entry,
                  int         num_faces_per_entry,
                  int         num_attr_per_entry )
{
  int status;
  int arbitrary_polyhedra = 0; /* 1 if block is arbitrary 2d polyhedra type; 2 if 3d polyhedra */
  int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim;
  size_t start[2];
  int num_blk;
  size_t temp;
  int cur_num_blk, numblkdim, numattrdim;
  int nnodperentdim, nedgperentdim, nfacperentdim;
  int connid;
  int npeid;
  char errmsg[MAX_ERR_LENGTH];
  char entity_type1[5];
  char entity_type2[5];
  const char* dnumblk = NULL;
  const char* vblkids = NULL;
  const char* vblksta = NULL;
  const char* vnodcon = NULL;
  const char* vnpecnt = NULL;
  const char* vedgcon = NULL;
  const char* vfaccon = NULL;
  const char* vconn   = NULL;
  const char* vattnam = NULL;
  const char* vblkatt = NULL;
  const char* dneblk  = NULL;
  const char* dnape   = NULL;
  const char* dnnpe   = NULL;
  const char* dnepe   = NULL;
  const char* dnfpe   = NULL;

  exerrval  = 0; /* clear error code */

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnumblk = DIM_NUM_ED_BLK;
    vblkids = VAR_ID_ED_BLK;
    vblksta = VAR_STAT_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    dnumblk = DIM_NUM_FA_BLK;
    vblkids = VAR_ID_FA_BLK;
    vblksta = VAR_STAT_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    dnumblk = DIM_NUM_EL_BLK;
    vblkids = VAR_ID_EL_BLK;
    vblksta = VAR_STAT_EL_BLK;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Error: Bad block type (%d) specified for file id %d",
             blk_type, exoid );
    ex_err( "ex_put_block", errmsg, exerrval );
    return (EX_FATAL);
  }

  /* first check if any element blocks are specified */

  if ((status = ex_get_dimension(exoid, dnumblk, ex_name_of_object(blk_type),
                                 &temp, &dimid, "ex_put_block")) != NC_NOERR) {
    return EX_FATAL;
  }
  num_blk = (int)temp;
  
  /* Next: Make sure that this is not a duplicate element block id by
     searching the vblkids array.
     WARNING: This must be done outside of define mode because id_lkup accesses
     the database to determine the position
  */

  if ((status = nc_inq_varid(exoid, vblkids, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate %s ids in file id %d",
            ex_name_of_object(blk_type), exoid);
    ex_err("ex_put_block",errmsg,exerrval);
  }

  blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
  if (exerrval != EX_LOOKUPFAIL) {   /* found the element block id */
    exerrval = EX_FATAL;
    sprintf(errmsg,
            "Error: %s id %d already exists in file id %d",
            ex_name_of_object(blk_type), blk_id,exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Keep track of the total number of element blocks defined using a counter 
     stored in a linked list keyed by exoid.
     NOTE: ex_get_file_item  is a function that finds the number of element 
     blocks for a specific file and returns that value incremented.
  */
  cur_num_blk=ex_get_file_item(exoid, ex_get_counter_list(blk_type));
  if (cur_num_blk >= num_blk) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
            "Error: exceeded number of %ss (%d) defined in file id %d",
            ex_name_of_object(blk_type), num_blk,exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }


  /*   NOTE: ex_get_file_item  is a function that finds the number of element
       blocks for a specific file and returns that value incremented. */
  cur_num_blk=ex_inc_file_item(exoid, ex_get_counter_list(blk_type));
  start[0] = cur_num_blk;

  /* write out element block id to previously defined id array variable*/
  if ((status = nc_put_var1_int(exoid, varid, start, &blk_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store %s id to file id %d",
            ex_name_of_object(blk_type), exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  blk_id_ndx = ((int)start[0])+1; /* element id index into vblkids array*/

  if (num_entries_this_blk == 0) /* Is this a NULL element block? */
    blk_stat = 0; /* change element block status to NULL */
  else
    blk_stat = 1; /* change element block status to TRUE */

  if ((status = nc_inq_varid (exoid, vblksta, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate %s status in file id %d",
            ex_name_of_object(blk_type), exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_put_var1_int(exoid, varid, start, &blk_stat)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store %s id %d status to file id %d",
            ex_name_of_object(blk_type), blk_id, exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_entries_this_blk == 0) {/* Is this a NULL element block? */
    return(EX_NOERR);
  }


  /* put netcdf file into define mode  */
  if ((status=nc_redef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
    dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnepe = 0;
    dnfpe = 0;
    dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
    vblkatt = VAR_EATTRIB(blk_id_ndx);
    vattnam = VAR_NAME_EATTRIB(blk_id_ndx);
    vnodcon = VAR_EBCONN(blk_id_ndx);
    vedgcon = 0;
    vfaccon = 0;
    break;
  case EX_FACE_BLOCK:
    dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
    dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnepe = 0;
    dnfpe = 0;
    dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
    vblkatt = VAR_FATTRIB(blk_id_ndx);
    vattnam = VAR_NAME_FATTRIB(blk_id_ndx);
    vnodcon = VAR_FBCONN(blk_id_ndx);
    vnpecnt = VAR_FBEPEC(blk_id_ndx);
    vedgcon = 0;
    vfaccon = 0;
    break;
  case EX_ELEM_BLOCK:
    dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx);
    dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
    vblkatt = VAR_ATTRIB(blk_id_ndx);
    vattnam = VAR_NAME_ATTRIB(blk_id_ndx);
    vnodcon = VAR_CONN(blk_id_ndx);
    vnpecnt = VAR_EBEPEC(blk_id_ndx);
    vedgcon = VAR_ECONN(blk_id_ndx);
    vfaccon = VAR_FCONN(blk_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
            "Internal Error: unrecognized block type in switch: %d in file id %d",
            blk_type,exoid);
    ex_err("ex_put_block",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }
  /* define some dimensions and variables*/

  if ((status = nc_def_dim(exoid,dneblk,num_entries_this_blk, &numblkdim )) != NC_NOERR) {
    if (status == NC_ENAMEINUSE) {        /* duplicate entry */
      exerrval = status;
      sprintf(errmsg,
              "Error: %s %d already defined in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
    } else {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define number of entities/block for %s %d file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
    }
    goto error_ret;         /* exit define mode and return */
  }

  if ( dnnpe && num_nodes_per_entry > 0) {
    /* A nfaced block would not have any nodes defined... */
    if ((status = nc_def_dim(exoid,dnnpe,num_nodes_per_entry, &nnodperentdim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define number of nodes/entity for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  if (dnepe && num_edges_per_entry > 0 ) {
    if ((status = nc_def_dim (exoid,dnepe,num_edges_per_entry, &nedgperentdim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define number of edges/entity for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  if ( dnfpe && num_faces_per_entry > 0 ) {
    if ((status = nc_def_dim(exoid,dnfpe,num_faces_per_entry, &nfacperentdim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define number of faces/entity for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  /* element attribute array */
  if (num_attr_per_entry > 0) {

    if ((status = nc_def_dim(exoid, dnape, num_attr_per_entry, &numattrdim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define number of attributes in %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    dims[0] = numblkdim;
    dims[1] = numattrdim;

    if ((status = nc_def_var(exoid, vblkatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error:  failed to define attributes for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* inquire previously defined dimensions  */
    if ((status = nc_inq_dimid(exoid, DIM_STR, &strdim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get string length in file id %d",exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      return (EX_FATAL);
    }
     
    /* Attribute names... */
    dims[0] = numattrdim;
    dims[1] = strdim;
            
    if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to define %s attribute name array in file id %d",
              ex_name_of_object(blk_type), exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }

  /* See if storing an 'nsided' element block (arbitrary 2d polyhedra or super element) */
  if (strlen(entry_descrip) >= 3) {
    if ((entry_descrip[0] == 'n' || entry_descrip[0] == 'N') &&
        (entry_descrip[1] == 's' || entry_descrip[1] == 'S') &&
        (entry_descrip[2] == 'i' || entry_descrip[2] == 'I'))
      arbitrary_polyhedra = 1;
    else if ((entry_descrip[0] == 'n' || entry_descrip[0] == 'N') &&
             (entry_descrip[1] == 'f' || entry_descrip[1] == 'F') &&
             (entry_descrip[2] == 'a' || entry_descrip[2] == 'A'))
      /* If a FACE_BLOCK, then we are dealing with the faces of the nfaced block. */
      arbitrary_polyhedra = blk_type == EX_FACE_BLOCK ? 1 : 2;
  }

  /* element connectivity array */
  if (arbitrary_polyhedra > 0) {
    if (blk_type != EX_FACE_BLOCK && blk_type != EX_ELEM_BLOCK) {
      exerrval = EX_BADPARAM;
      sprintf( errmsg, "Error: Bad block type (%d) for nsided/nfaced block in file id %d",
               blk_type, exoid );
      ex_err( "ex_put_block", errmsg, exerrval );
      return (EX_FATAL);
    }

    if (arbitrary_polyhedra == 1) {
      dims[0] = nnodperentdim;
      vconn = vnodcon;

      /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
      strcpy(entity_type1, "NODE");
      if (blk_type == EX_ELEM_BLOCK)
        strcpy(entity_type2, "ELEM");
      else
        strcpy(entity_type2, "FACE");
    } else if (arbitrary_polyhedra == 2) {
      dims[0] = nfacperentdim;
      vconn = vfaccon;

      /* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
      strcpy(entity_type1, "FACE");
      strcpy(entity_type2, "ELEM");
    }

    if ((status = nc_def_var(exoid, vconn, NC_INT, 1, dims, &connid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to create connectivity array for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
    
    /* element face-per-element or node-per-element count array */
    dims[0] = numblkdim;
    
    if ((status = nc_def_var(exoid, vnpecnt, NC_INT, 1, dims, &npeid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to create face- or node- per-entity count array for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id, exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if ((status = nc_put_att_text(exoid, npeid, "entity_type1", strlen(entity_type1)+1,
                                  entity_type1)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to store entity type attribute text for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id, exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
    if ((status = nc_put_att_text(exoid, npeid, "entity_type2", strlen(entity_type2)+1,
                                  entity_type2)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to store entity type attribute text for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id, exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  } else {
    /* "Normal" (non-polyhedra) element block type */
    dims[0] = numblkdim;
    dims[1] = nnodperentdim;
    
    if ((status = nc_def_var(exoid, vnodcon, NC_INT, 2, dims, &connid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to create connectivity array for %s %d in file id %d",
              ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_put_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }
  }
  /* store element type as attribute of connectivity variable */
  if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(entry_descrip)+1, 
                                entry_descrip)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store %s type name %s in file id %d",
            ex_name_of_object(blk_type), entry_descrip,exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    goto error_ret;         /* exit define mode and return */
  }

  if (arbitrary_polyhedra == 0) {
    if (vedgcon && num_edges_per_entry ) {
      dims[0] = numblkdim;
      dims[1] = nedgperentdim;
      
      if ((status = nc_def_var(exoid, vedgcon, NC_INT, 2, dims, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to create edge connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type), blk_id,exoid);
        ex_err("ex_put_block",errmsg,exerrval);
        goto error_ret;         /* exit define mode and return */
      }
    }
    
    if ( vfaccon && num_faces_per_entry ) {
      dims[0] = numblkdim;
      dims[1] = nfacperentdim;
      
      if ((status = nc_def_var(exoid, vfaccon, NC_INT, 2, dims, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to create face connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type), blk_id,exoid);
        ex_err("ex_put_block",errmsg,exerrval);
        goto error_ret;         /* exit define mode and return */
      }
    }
  }
  /* leave define mode  */

  if ((exerrval=nc_enddef (exoid)) != NC_NOERR) {
    sprintf(errmsg,
            "Error: failed to complete %s definition in file id %d", 
            ex_name_of_object(blk_type), exoid);
    ex_err("ex_put_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
            "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_block",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#9
0
int ex_put_block_params( int         exoid,
			 size_t      block_count,
			 const struct ex_block *blocks)
{
  size_t i;
  int conn_int_type;
  int status;
  int arbitrary_polyhedra = 0; /* 1 if block is arbitrary 2d polyhedra type; 2 if 3d polyhedra */
  int att_name_varid = -1;
  int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim;
  size_t start[2];
  size_t num_blk;
  int cur_num_blk, numblkdim, numattrdim;
  int nnodperentdim = -1;
  int nedgperentdim = -1;
  int nfacperentdim = -1;
  int connid;
  int npeid;
  char errmsg[MAX_ERR_LENGTH];
  char entity_type1[5];
  char entity_type2[5];
  int* blocks_to_define = NULL;
  const char* dnumblk = NULL;
  const char* vblkids = NULL;
  const char* vblksta = NULL;
  const char* vnodcon = NULL;
  const char* vnpecnt = NULL;
  const char* vedgcon = NULL;
  const char* vfaccon = NULL;
  const char* vconn   = NULL;
  const char* vattnam = NULL;
  const char* vblkatt = NULL;
  const char* dneblk  = NULL;
  const char* dnape   = NULL;
  const char* dnnpe   = NULL;
  const char* dnepe   = NULL;
  const char* dnfpe   = NULL;

  exerrval  = 0; /* clear error code */

  blocks_to_define = malloc(block_count*sizeof(int));

  for (i=0; i < block_count; i++) {
    switch (blocks[i].type) {
    case EX_EDGE_BLOCK:
      dnumblk = DIM_NUM_ED_BLK;
      vblkids = VAR_ID_ED_BLK;
      vblksta = VAR_STAT_ED_BLK;
      break;
    case EX_FACE_BLOCK:
      dnumblk = DIM_NUM_FA_BLK;
      vblkids = VAR_ID_FA_BLK;
      vblksta = VAR_STAT_FA_BLK;
      break;
    case EX_ELEM_BLOCK:
      dnumblk = DIM_NUM_EL_BLK;
      vblkids = VAR_ID_EL_BLK;
      vblksta = VAR_STAT_EL_BLK;
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf( errmsg, "Error: Bad block type (%d) specified for entry %d file id %d",
	       blocks[i].type, (int)i, exoid );
      ex_err( "ex_put_block_params", errmsg, exerrval );
      free(blocks_to_define);
      return (EX_FATAL);
    }

    /* first check if any blocks of that type are specified */
    if ((status = ex_get_dimension(exoid, dnumblk, ex_name_of_object(blocks[i].type),
				   &num_blk, &dimid, "ex_put_block_params")) != NC_NOERR) {
      sprintf(errmsg,
	      "Error: No %ss defined in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return EX_FATAL;
    }

    /* Next: Make sure that there are not any duplicate block ids by
       searching the vblkids array.
       WARNING: This must be done outside of define mode because id_lkup accesses
       the database to determine the position
    */

    if ((status = nc_inq_varid(exoid, vblkids, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s ids in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return EX_FATAL;
    }

    ex_id_lkup(exoid,blocks[i].type,blocks[i].id); /* Error value used, but don't need return value */
    if (exerrval != EX_LOOKUPFAIL) {   /* found the element block id */
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: %s id %"PRId64" already exists in file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    /* Keep track of the total number of element blocks defined using a counter 
       stored in a linked list keyed by exoid.
       NOTE: ex_get_file_item  is a function that finds the number of element 
       blocks for a specific file and returns that value.
    */
    cur_num_blk=ex_get_file_item(exoid, ex_get_counter_list(blocks[i].type));
    if (cur_num_blk >= (int)num_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of %ss (%d) defined in file id %d",
	      ex_name_of_object(blocks[i].type), (int)num_blk,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    /*   NOTE: ex_inc_file_item  is a function that finds the number of element
	 blocks for a specific file and returns that value incremented. */
    cur_num_blk=ex_inc_file_item(exoid, ex_get_counter_list(blocks[i].type));
    start[0] = cur_num_blk;

    /* write out block id to previously defined id array variable*/
    status = nc_put_var1_longlong(exoid, varid, start, (long long*)&blocks[i].id);

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s id to file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    blocks_to_define[i] = start[0]+1; /* element id index into vblkids array*/

    if (blocks[i].num_entry == 0) /* Is this a NULL element block? */
      blk_stat = 0; /* change element block status to NULL */
    else
      blk_stat = 1; /* change element block status to EX_EX_TRUE */

    if ((status = nc_inq_varid (exoid, vblksta, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s status in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    if ((status = nc_put_var1_int(exoid, varid, start, &blk_stat)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s id %"PRId64" status to file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }
  }

  /* put netcdf file into define mode  */
  if ((status=nc_redef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
    ex_err("ex_put_block_params",errmsg,exerrval);
    free(blocks_to_define);
    return (EX_FATAL);
  }


  for (i=0; i < block_count; i++) {
    if (blocks[i].num_entry == 0) {/* Is this a NULL element block? */
      continue;
    }

    blk_id_ndx = blocks_to_define[i];

    switch (blocks[i].type) {
    case EX_EDGE_BLOCK:
      dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
      dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx);
      dnepe = 0;
      dnfpe = 0;
      dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
      vblkatt = VAR_EATTRIB(blk_id_ndx);
      vattnam = VAR_NAME_EATTRIB(blk_id_ndx);
      vnodcon = VAR_EBCONN(blk_id_ndx);
      vedgcon = 0;
      vfaccon = 0;
      break;
    case EX_FACE_BLOCK:
      dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
      dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx);
      dnepe = 0;
      dnfpe = 0;
      dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
      vblkatt = VAR_FATTRIB(blk_id_ndx);
      vattnam = VAR_NAME_FATTRIB(blk_id_ndx);
      vnodcon = VAR_FBCONN(blk_id_ndx);
      vnpecnt = VAR_FBEPEC(blk_id_ndx);
      vedgcon = 0;
      vfaccon = 0;
      break;
    case EX_ELEM_BLOCK:
      dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx);
      dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx);
      dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx);
      dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx);
      dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
      vblkatt = VAR_ATTRIB(blk_id_ndx);
      vattnam = VAR_NAME_ATTRIB(blk_id_ndx);
      vnodcon = VAR_CONN(blk_id_ndx);
      vnpecnt = VAR_EBEPEC(blk_id_ndx);
      vedgcon = VAR_ECONN(blk_id_ndx);
      vfaccon = VAR_FCONN(blk_id_ndx);
      break;
    default:
      goto error_ret;
    }

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid,dneblk,blocks[i].num_entry, &numblkdim )) != NC_NOERR) {
      if (status == NC_ENAMEINUSE) {        /* duplicate entry */
	exerrval = status;
	sprintf(errmsg,
		"Error: %s %"PRId64" already defined in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of entities/block for %s %"PRId64" file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */
    }

    if ( dnnpe && blocks[i].num_nodes_per_entry > 0) {
      /* A nfaced block would not have any nodes defined... */
      if ((status = nc_def_dim(exoid,dnnpe,blocks[i].num_nodes_per_entry, &nnodperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of nodes/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    if (dnepe && blocks[i].num_edges_per_entry > 0 ) {
      if ((status = nc_def_dim (exoid,dnepe,blocks[i].num_edges_per_entry, &nedgperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of edges/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    if ( dnfpe && blocks[i].num_faces_per_entry > 0 ) {
      if ((status = nc_def_dim(exoid,dnfpe,blocks[i].num_faces_per_entry, &nfacperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of faces/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    /* element attribute array */
    if (blocks[i].num_attribute > 0) {

      if ((status = nc_def_dim(exoid, dnape, blocks[i].num_attribute, &numattrdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of attributes in %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

      dims[0] = numblkdim;
      dims[1] = numattrdim;

      if ((status = nc_def_var(exoid, vblkatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error:  failed to define attributes for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      ex_compress_variable(exoid, varid, 2);

      /* inquire previously defined dimensions  */
      if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get string length in file id %d",exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;
      }
     
      /* Attribute names... */
      dims[0] = numattrdim;
      dims[1] = strdim;
	    
      if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &att_name_varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define %s attribute name array in file id %d",
		ex_name_of_object(blocks[i].type), exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    conn_int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
      conn_int_type = NC_INT64;
    }

    /* See if storing an 'nsided' element block (arbitrary 2d polyhedra or super element) */
    if (strlen(blocks[i].topology) >= 3) {
      if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') &&
	  (blocks[i].topology[1] == 's' || blocks[i].topology[1] == 'S') &&
	  (blocks[i].topology[2] == 'i' || blocks[i].topology[2] == 'I'))
	arbitrary_polyhedra = 1;
      else if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') &&
	       (blocks[i].topology[1] == 'f' || blocks[i].topology[1] == 'F') &&
	       (blocks[i].topology[2] == 'a' || blocks[i].topology[2] == 'A'))
	/* If a FACE_BLOCK, then we are dealing with the faces of the nfaced blocks[i]. */
	arbitrary_polyhedra = blocks[i].type == EX_FACE_BLOCK ? 1 : 2;
    }

    /* element connectivity array */
    if (arbitrary_polyhedra > 0) {
      if (blocks[i].type != EX_FACE_BLOCK && blocks[i].type != EX_ELEM_BLOCK) {
	exerrval = EX_BADPARAM;
	sprintf( errmsg, "Error: Bad block type (%d) for nsided/nfaced block in file id %d",
		 blocks[i].type, exoid );
	ex_err( "ex_put_block_params", errmsg, exerrval );
	goto error_ret;
      }

      if (arbitrary_polyhedra == 1) {
	dims[0] = nnodperentdim;
	vconn = vnodcon;

	/* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
	strcpy(entity_type1, "NODE");
	if (blocks[i].type == EX_ELEM_BLOCK)
	  strcpy(entity_type2, "ELEM");
	else
	  strcpy(entity_type2, "FACE");
      } else if (arbitrary_polyhedra == 2) {
	dims[0] = nfacperentdim;
	vconn = vfaccon;

	/* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
	strcpy(entity_type1, "FACE");
	strcpy(entity_type2, "ELEM");
      }

      if ((status = nc_def_var(exoid, vconn, conn_int_type, 1, dims, &connid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    
      /* element face-per-element or node-per-element count array */
      dims[0] = numblkdim;
    
      if ((status = nc_def_var(exoid, vnpecnt, conn_int_type, 1, dims, &npeid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create face- or node- per-entity count array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

      if ((status = nc_put_att_text(exoid, npeid, "entity_type1", strlen(entity_type1)+1,
				    entity_type1)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store entity type attribute text for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      if ((status = nc_put_att_text(exoid, npeid, "entity_type2", strlen(entity_type2)+1,
				    entity_type2)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store entity type attribute text for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    } else {
      /* "Normal" (non-polyhedra) element block type */
      dims[0] = numblkdim;
      dims[1] = nnodperentdim;
    
      if ((status = nc_def_var(exoid, vnodcon, conn_int_type, 2, dims, &connid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      ex_compress_variable(exoid, connid, 1);
    }
    /* store element type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(blocks[i].topology)+1, 
				  blocks[i].topology)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s type name %s in file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].topology,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if (arbitrary_polyhedra == 0) {
      if (vedgcon && blocks[i].num_edges_per_entry ) {
	dims[0] = numblkdim;
	dims[1] = nedgperentdim;
      
	if ((status = nc_def_var(exoid, vedgcon, conn_int_type, 2, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create edge connectivity array for %s %"PRId64" in file id %d",
		  ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	  ex_err("ex_put_block_params",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
      }
    
      if ( vfaccon && blocks[i].num_faces_per_entry ) {
	dims[0] = numblkdim;
	dims[1] = nfacperentdim;
      
	if ((status = nc_def_var(exoid, vfaccon, conn_int_type, 2, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create face connectivity array for %s %"PRId64" in file id %d",
		  ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	  ex_err("ex_put_block_params",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
      }
    }
  }

  free(blocks_to_define);

  /* leave define mode  */
  if ((exerrval=nc_enddef (exoid)) != NC_NOERR) {
    sprintf(errmsg,
	    "Error: failed to complete %s definition in file id %d", 
	    ex_name_of_object(blocks[i].type), exoid);
    ex_err("ex_put_block_params",errmsg,exerrval);
    return (EX_FATAL);
  }


  for (i=0; i < block_count; i++) {
    switch (blocks[i].type) {
    case EX_EDGE_BLOCK:
      vblkids = VAR_ID_ED_BLK;
      break;
    case EX_FACE_BLOCK:
      vblkids = VAR_ID_FA_BLK;
      break;
    case EX_ELEM_BLOCK:
      vblkids = VAR_ID_EL_BLK;
      break;
    default:
      return (EX_FATAL); /* should have been handled earlier; quiet compiler here */
    }

    nc_inq_varid(exoid, vblkids, &att_name_varid);

    if (blocks[i].num_attribute > 0 && att_name_varid >= 0) {
      /* Output a dummy empty attribute name in case client code doesn't
	 write anything; avoids corruption in some cases.
      */
      size_t  count[2];
      char *text = "";
      size_t j;

      count[0] = 1;
      start[1] = 0;
      count[1] = strlen(text)+1;
  
      for (j = 0; j < blocks[i].num_attribute; j++) {
	start[0] = j;
	nc_put_vara_text(exoid, att_name_varid, start, count, text);
      }
    }
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  free(blocks_to_define);

  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_block_params",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#10
0
int ex_get_conn( int   exoid,
                 int   blk_type,
                 int   blk_id,
                 int*  nodeconn,
                 int*  edgeconn,
                 int*  faceconn )
{
   int numblkentriesdim, connid, econnid, fconnid, blk_id_ndx, iresult;
   int numnodperentdim, numedgperentdim, numfacperentdim;
   int iexit = (EX_NOERR); /* exit status */
   long num_entries_this_blk, num_nodes_per_entry, num_edges_per_entry, num_faces_per_entry;
   long start[2], count[2]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   const char* tname;
   const char* vblkids;
   const char* dnumblkent;
   const char* dnumnodent;
   const char* dnumedgent;
   const char* dnumfacent;
   const char* vnodeconn;
   const char* vedgeconn;
   const char* vfaceconn;

   /* Should we warn if edgeconn or faceconn are non-NULL?
    * No, fail silently so the same code can be used to read any type of block info.
    * However, we will warn if edgeconn or faceconn are NULL but num_edges_per_entry
    * or num_faces_per_entry (respectively) are positive.
    */
   switch (blk_type) {
   case EX_EDGE_BLOCK:
     tname = "edge";
     vblkids = VAR_ID_ED_BLK;
     break;
   case EX_FACE_BLOCK:
     tname = "face";
     vblkids = VAR_ID_FA_BLK;
     break;
   case EX_ELEM_BLOCK:
     tname = "element";
     vblkids = VAR_ID_EL_BLK;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg, "Error: Invalid block type (%d) specified in file id %d", blk_type, exoid );
     ex_err( "ex_get_conn", errmsg, exerrval );
     return (EX_FATAL);
   }

   exerrval = 0; /* clear error code */

   /* Locate index of element block id in VAR_ID_EL_BLK array */

   blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
   if (exerrval != 0) 
   {
     if (exerrval == EX_NULLENTITY)
     {
       sprintf(errmsg,
              "Warning: no connectivity array for NULL %s block %d in file id %d",
               tname,blk_id,exoid);
       ex_err("ex_get_conn",errmsg,EX_MSG);
       return (EX_WARN); /* no connectivity array for this element block */
     }
     else
     {
       sprintf(errmsg,
        "Error: failed to locate %s block id %d in %s array in file id %d",
               tname,blk_id,vblkids,exoid);
       ex_err("ex_get_conn",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   switch (blk_type) {
   case EX_EDGE_BLOCK:
     dnumblkent = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
     dnumedgent = 0;
     dnumfacent = 0;
     vnodeconn = VAR_EBCONN(blk_id_ndx);
     vedgeconn = 0;
     vfaceconn = 0;
     break;
   case EX_FACE_BLOCK:
     dnumblkent = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
     dnumedgent = 0;
     dnumfacent = 0;
     vnodeconn = VAR_FBCONN(blk_id_ndx);
     vedgeconn = 0;
     vfaceconn = 0;
     break;
   case EX_ELEM_BLOCK:
     dnumblkent = DIM_NUM_EL_IN_BLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
     dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
     dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
     vnodeconn = VAR_CONN(blk_id_ndx);
     vedgeconn = VAR_ECONN(blk_id_ndx);
     vfaceconn = VAR_FCONN(blk_id_ndx);
     break;
   }
/* inquire id's of previously defined dimensions  */

   if ((numblkentriesdim = ncdimid (exoid, dnumblkent)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to locate number of elements in %s block %d in file id %d",
              tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq (exoid, numblkentriesdim, (char *) 0, &num_entries_this_blk) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
           "Error: failed to get number of entries in %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg,exerrval);
     return(EX_FATAL);
   }


   if ((numnodperentdim = ncdimid (exoid, dnumnodent)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
      "Error: failed to locate number of nodes/elem for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg,exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq (exoid, numnodperentdim, (char *) 0, &num_nodes_per_entry) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
       "Error: failed to get number of nodes/elem for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( dnumedgent ) {
     num_edges_per_entry = 0;
     if ((numedgperentdim = ncdimid (exoid, dnumedgent)) == -1) {
       numedgperentdim = -1;
     } else {
       if (ncdiminq (exoid, numedgperentdim, (char *) 0, &num_edges_per_entry) == -1) {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of edges/entry for %s block %d in file id %d",
           tname,blk_id,exoid);
         ex_err("ex_get_conn",errmsg, exerrval);
         return(EX_FATAL);
       }
       if ( num_edges_per_entry < 0 )
         num_edges_per_entry = 0;
     }
     if ( num_edges_per_entry > 0 && (!edgeconn) ) {
       exerrval = EX_BADPARAM;
       sprintf( errmsg, "Edge connectivity present but NULL pointer passed for file id %d", exoid );
       ex_err( "ex_get_conn", errmsg, exerrval );
       iexit = exerrval;
     }
   }

   if ( dnumfacent ) {
     num_faces_per_entry = 0;
     if ((numfacperentdim = ncdimid (exoid, dnumfacent)) == -1) {
       numfacperentdim = -1;
     } else {
       if (ncdiminq (exoid, numfacperentdim, (char *) 0, &num_faces_per_entry) == -1) {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of faces/entry for %s block %d in file id %d",
           tname,blk_id,exoid);
         ex_err("ex_get_conn",errmsg, exerrval);
         return(EX_FATAL);
       }
       if ( num_faces_per_entry < 0 )
         num_faces_per_entry = 0;
     }
     if ( num_faces_per_entry > 0 && (!faceconn) ) {
       exerrval = EX_BADPARAM;
       sprintf( errmsg, "Face connectivity present but NULL pointer passed for file id %d", exoid );
       ex_err( "ex_get_conn", errmsg, exerrval );
       iexit = exerrval;
     }
   }


   if ((connid = ncvarid (exoid, vnodeconn)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate connectivity array for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( edgeconn && (numedgperentdim > 0) && ((econnid = ncvarid (exoid, vedgeconn)) == -1) )
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate edge connectivity array for %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( faceconn && (numfacperentdim > 0) && ((fconnid = ncvarid (exoid, vfaceconn)) == -1) )
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate face connectivity array for %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }


/* read in the connectivity array */

/* application code has allocated an array of ints but netcdf is expecting
   a pointer to nclongs;  if ints are different sizes than nclongs,
   we must allocate an array of nclongs then convert them to ints with ltoi */

   start[0] = 0;
   start[1] = 0;

   if ( edgeconn && num_edges_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_edges_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, econnid, start, count, edgeconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_edges_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for edge connectivity array for file id %d",
           exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, econnid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get edge connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, edgeconn, num_entries_this_blk*num_edges_per_entry);
       free (longs);
     }
   }

   if ( faceconn && num_faces_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_faces_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, fconnid, start, count, faceconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_faces_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for face connectivity array of %s blockfor file id %d",
           tname,exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, fconnid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get face connectivity array for %s block %d in file id %d",
         tname,blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, faceconn, num_entries_this_blk*num_faces_per_entry);
       free (longs);
     }
   }

   if ( nodeconn && num_nodes_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_nodes_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, connid, start, count, nodeconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_nodes_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for element connectivity array for file id %d",
           exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, connid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, nodeconn, num_entries_this_blk*num_nodes_per_entry);
       free (longs);
     }
   }

   return iexit;
}
示例#11
0
文件: exgblk.c 项目: hs9906/paraview
int ex_get_block( int exoid,
  int blk_type,
  int blk_id,
  char* elem_type,
  int* num_entries_this_blk,
  int* num_nodes_per_entry,
  int* num_edges_per_entry,
  int* num_faces_per_entry,
  int* num_attr_per_entry )
{
   int dimid, connid, len, blk_id_ndx;
   long lnum_entries_this_blk, lnum_nodes_per_entry, lnum_attr_per_entry;
   long lnum_edges_per_entry, lnum_faces_per_entry;
   char *ptr;
   char  errmsg[MAX_ERR_LENGTH];
   nc_type dummy;
   const char* tname;
   const char* dnument;
   const char* dnumnod;
   const char* dnumedg;
   const char* dnumfac;
   const char* dnumatt;
   const char* ablknam;
   const char* vblkcon;
   const char* vblkids;

   exerrval = 0;

   /* First, locate index of element block id in VAR_ID_EL_BLK array */
   switch (blk_type) {
   case EX_EDGE_BLOCK:
     tname = "edge";
     vblkids = VAR_ID_ED_BLK;
     blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
     dnument = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
     dnumnod = DIM_NUM_NOD_PER_ED(blk_id_ndx);
     dnumedg = 0;
     dnumfac = 0;
     dnumatt = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
     vblkcon = VAR_EBCONN(blk_id_ndx);
     ablknam = ATT_NAME_ELB;
     break;
   case EX_FACE_BLOCK:
     tname = "face";
     vblkids = VAR_ID_FA_BLK;
     blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
     dnument = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
     dnumnod = DIM_NUM_NOD_PER_FA(blk_id_ndx);
     dnumedg = 0; /* it is possible this might be non-NULL some day */
     dnumfac = 0;
     dnumatt = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
     vblkcon = VAR_FBCONN(blk_id_ndx);
     ablknam = ATT_NAME_ELB;
     break;
   case EX_ELEM_BLOCK:
     tname = "element";
     vblkids = VAR_ID_EL_BLK;
     blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
     dnument = DIM_NUM_EL_IN_BLK(blk_id_ndx);
     dnumnod = DIM_NUM_NOD_PER_EL(blk_id_ndx);
     dnumedg = DIM_NUM_EDG_PER_EL(blk_id_ndx);
     dnumfac = DIM_NUM_FAC_PER_EL(blk_id_ndx);
     dnumatt = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
     vblkcon = VAR_CONN(blk_id_ndx);
     ablknam = ATT_NAME_ELB;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg, "Bad block type parameter (%d) specified for file id %d.",
       blk_type, exoid );
     return (EX_FATAL);
   }

   if (exerrval != 0) 
     {
     if (exerrval == EX_NULLENTITY)     /* NULL element block?    */
       {
       if ( elem_type )
         strcpy(elem_type, "NULL");     /* NULL element type name */
       *num_entries_this_blk = 0;       /* no elements            */
       *num_nodes_per_entry = 0;        /* no nodes               */
       *num_attr_per_entry = 0;         /* no attributes          */
       return (EX_NOERR);
       }
     else
       {
       sprintf(errmsg,
        "Error: failed to locate element block id %d in %s array in file id %d",
               blk_id,vblkids,exoid);
       ex_err("ex_get_block",errmsg,exerrval);
       return (EX_FATAL);
       }
     }

   /* inquire values of some dimensions */
   if ( num_entries_this_blk )
     {
     if ((dimid = ncdimid (exoid, dnument)) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate number of %ss in block %d in file id %d",
         tname,blk_id,exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (ncdiminq (exoid, dimid, (char *) 0, &lnum_entries_this_blk) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get number of %ss in block %d in file id %d",
         tname,blk_id, exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }
     *num_entries_this_blk = lnum_entries_this_blk;
     }

   if ( num_nodes_per_entry )
     {
     if ((dimid = ncdimid (exoid, dnumnod)) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate number of nodes/%s in block %d in file id %d",
         tname,blk_id,exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }
     if (ncdiminq (exoid, dimid, (char *) 0, &lnum_nodes_per_entry) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get number of nodes/%s in block %d in file id %d",
         tname,blk_id, exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }
     *num_nodes_per_entry = lnum_nodes_per_entry;
     }

   if ( num_edges_per_entry )
     {
     if ( blk_type != EX_ELEM_BLOCK )
       {
       exerrval = (EX_WARN);
       sprintf(errmsg,
         "Warning: non-NULL pointer passed to num_edges_per_entry for %s block query in file id %d",
         tname,exoid);
       ex_err("ex_get_block",errmsg,exerrval);
       }
     else
       {
       if ((dimid = ncdimid (exoid, dnumedg)) == -1)
         {
         /* undefined => no edge entries per element */
         lnum_edges_per_entry = 0;
         }
       else
         {
         if (ncdiminq (exoid, dimid, (char *) 0, &lnum_edges_per_entry) == -1)
           {
           exerrval = ncerr;
           sprintf(errmsg,
             "Error: failed to get number of edges/%s in block %d in file id %d",
             tname,blk_id, exoid);
           ex_err("ex_get_block",errmsg, exerrval);
           return(EX_FATAL);
           }
         }
       *num_edges_per_entry = lnum_edges_per_entry;
       }
     }

   if ( num_faces_per_entry )
     {
     if ( blk_type != EX_ELEM_BLOCK )
       {
       exerrval = (EX_WARN);
       sprintf(errmsg,
         "Warning: non-NULL pointer passed to num_faces_per_entry for %s block query in file id %d",
         tname,exoid);
       ex_err("ex_get_block",errmsg,exerrval);
       }
     else
       {
       if ((dimid = ncdimid (exoid, dnumfac)) == -1)
         {
         /* undefined => no face entries per element */
         lnum_faces_per_entry = 0;
         }
       else
         {
         if (ncdiminq (exoid, dimid, (char *) 0, &lnum_faces_per_entry) == -1)
           {
           exerrval = ncerr;
           sprintf(errmsg,
             "Error: failed to get number of faces/%s in block %d in file id %d",
             tname,blk_id, exoid);
           ex_err("ex_get_block",errmsg, exerrval);
           return(EX_FATAL);
           }
         }
         *num_faces_per_entry = lnum_faces_per_entry;
       }
     }

   if ( num_attr_per_entry )
     {
     if ((dimid = ncdimid (exoid, dnumatt)) == -1)
       {
       /* dimension is undefined */
       *num_attr_per_entry = 0;
       }
     else
       {
       if (ncdiminq (exoid, dimid, (char *) 0, &lnum_attr_per_entry) == -1)
         {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of attributes in %s block %d in file id %d",
           tname,blk_id, exoid);
         ex_err("ex_get_block",errmsg, exerrval);
         return(EX_FATAL);
         }
       *num_attr_per_entry = lnum_attr_per_entry;
       }
     }

   if ( elem_type )
     {
     /* look up connectivity array for this element block id */
     if ((connid = ncvarid (exoid, vblkcon)) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate connectivity array for element block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (ncattinq (exoid, connid, ablknam, &dummy, &len) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get element block %d type in file id %d",
         blk_id,exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (len > (MAX_STR_LENGTH+1))
       {
       len = MAX_STR_LENGTH;
       sprintf (errmsg,
         "Warning: element block %d type will be truncated to %d chars", 
         blk_id,len);
       ex_err("ex_get_block",errmsg,EX_MSG);
       }
     /* get the element type name */

     if (ncattget (exoid, connid, ablknam, elem_type) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,"Error: failed to get element block %d type in file id %d",
         blk_id, exoid);
       ex_err("ex_get_block",errmsg, exerrval);
       return(EX_FATAL);
       }

     /* get rid of trailing blanks */
     ptr = elem_type;
     /* fprintf(stderr,"[exgblk] %s, len: %d\n",ptr,len); */
     while (ptr < elem_type + len && *ptr != ' ')
       {
       ptr++;
       }
     *(ptr) = '\0';
     }

   return (EX_NOERR);
}
示例#12
0
int ex_put_conn (int   exoid,
                 int   blk_type,
                 int   blk_id,
                 const int  *node_conn,
                 const int  *elem_edge_conn,
                 const int  *elem_face_conn)
{
   int numelbdim=-1, nelnoddim=-1, connid=-1, blk_id_ndx, iresult;
   char* var_id_blk;
   long num_entry_this_blk, num_id_per_entry, start[2], count[2]; 
   nclong *lptr;
   char errmsg[MAX_ERR_LENGTH];
   const char* blk_typename;

   exerrval = 0; /* clear error code */

   switch (blk_type) {
   case EX_ELEM_BLOCK:
     /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
     var_id_blk = VAR_ID_EL_BLK;
     blk_typename = "element";
     break;
   case EX_FACE_BLOCK:
     var_id_blk = VAR_ID_FA_BLK;
     blk_typename = "face";
     break;
   case EX_EDGE_BLOCK:
     var_id_blk = VAR_ID_ED_BLK;
     blk_typename = "edge";
     break;
   default:
     sprintf(errmsg,"Error: Invalid block type %d passed for file id %d",
             blk_type,exoid);
     ex_err("ex_put_conn",errmsg,EX_MSG);
     return (EX_FATAL);
   }

   blk_id_ndx = ex_id_lkup(exoid,var_id_blk,blk_id);
   if (exerrval != 0) 
     {
     if (exerrval == EX_NULLENTITY)
       {
       sprintf(errmsg,
         "Warning: connectivity array not allowed for NULL %s block %d in file id %d",
         blk_typename,blk_id,exoid);
       ex_err("ex_put_conn",errmsg,EX_MSG);
       return (EX_WARN);
       }
     else
       {
       sprintf(errmsg,
         "Error: failed to locate %s block id %d in %s array in file id %d",
         blk_typename,blk_id,var_id_blk, exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }
     }

/* inquire id's of previously defined dimensions  */

   switch (blk_type) {
   case EX_ELEM_BLOCK:
     /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
     numelbdim = ncdimid (exoid, DIM_NUM_EL_IN_BLK(blk_id_ndx));
     break;
   case EX_FACE_BLOCK:
     numelbdim = ncdimid (exoid, DIM_NUM_FA_IN_FBLK(blk_id_ndx));
     break;
   case EX_EDGE_BLOCK:
     numelbdim = ncdimid (exoid, DIM_NUM_ED_IN_EBLK(blk_id_ndx));
     break;
   }
   if (numelbdim == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to locate number of %ss in block %d in file id %d",
              blk_typename,blk_id,exoid);
     ex_err("ex_put_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq(exoid, numelbdim, NULL, &num_entry_this_blk) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of elements in block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_conn",errmsg,exerrval);
     return(EX_FATAL);
   }


   switch (blk_type) {
   case EX_ELEM_BLOCK:
     nelnoddim = ncdimid (exoid, DIM_NUM_NOD_PER_EL(blk_id_ndx));
     break;
   case EX_FACE_BLOCK:
     nelnoddim = ncdimid (exoid, DIM_NUM_NOD_PER_FA(blk_id_ndx));
     break;
   case EX_EDGE_BLOCK:
     nelnoddim = ncdimid (exoid, DIM_NUM_NOD_PER_ED(blk_id_ndx));
     break;
   }
   if (nelnoddim == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
       "Error: failed to locate number of nodes/%s in block %d in file id %d",
             blk_typename,blk_id,exoid);
     ex_err("ex_put_conn",errmsg,exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq (exoid, nelnoddim, NULL, &num_id_per_entry) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
       "Error: failed to get number of nodes/elem in block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_conn",errmsg,exerrval);
     return(EX_FATAL);
   }


   switch (blk_type) {
   case EX_ELEM_BLOCK:
     connid = ncvarid (exoid, VAR_CONN(blk_id_ndx));
     break;
   case EX_FACE_BLOCK:
     connid = ncvarid (exoid, VAR_FBCONN(blk_id_ndx));
     break;
   case EX_EDGE_BLOCK:
     connid = ncvarid (exoid, VAR_EBCONN(blk_id_ndx));
     break;
   }
   if (connid == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
"Error: failed to locate connectivity array for %s block %d in file id %d",
             blk_typename,blk_id,exoid);
     ex_err("ex_put_conn",errmsg, exerrval);
     return(EX_FATAL);
   }


/* write out the connectivity array */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size */
#define EX_WRITE_CONN(TNAME,ARRDIM0,ARRDIM1,VARCONN,VARCONNVAL) \
   start[0] = 0; \
   start[1] = 0; \
 \
   count[0] = (ARRDIM0); \
   count[1] = (ARRDIM1); \
 \
   if (sizeof(int) == sizeof(nclong)) { \
      iresult = ncvarput (exoid, VARCONN, start, count, VARCONNVAL); \
   } else { \
      lptr = itol (VARCONNVAL, (int)((ARRDIM0)*(ARRDIM1))); \
      iresult = ncvarput (exoid, VARCONN, start, count, lptr); \
      free(lptr); \
   } \
 \
   if (iresult == -1) \
   { \
      exerrval = ncerr; \
      sprintf(errmsg, \
      "Error: failed to write connectivity array for %s block %d in file id %d", \
                TNAME,blk_id,exoid); \
      ex_err("ex_put_conn",errmsg, exerrval); \
      return(EX_FATAL); \
   }

   EX_WRITE_CONN(blk_typename,num_entry_this_blk,num_id_per_entry,connid,node_conn);

   /* If there are edge and face connectivity arrays that belong with the element
    * block, write them now. Warn if they are required but not specified or
    * specified but not required.
    */
   if ( blk_type == EX_ELEM_BLOCK ) {
     int nedpereldim, nfapereldim;
     long num_ed_per_elem, num_fa_per_elem;

     nedpereldim = ncdimid (exoid, DIM_NUM_EDG_PER_EL(blk_id_ndx));
     if (nedpereldim == -1 && elem_edge_conn != 0)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: edge connectivity specified but failed to "
         "locate number of edges/element in block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     nfapereldim = ncdimid (exoid, DIM_NUM_FAC_PER_EL(blk_id_ndx));
     if (nfapereldim == -1 && elem_face_conn != 0)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: face connectivity specified but failed to "
         "locate number of faces/element in block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     if (ncdiminq (exoid, nedpereldim, NULL, &num_ed_per_elem) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get number of edges/elem in block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     if (ncdiminq (exoid, nfapereldim, NULL, &num_fa_per_elem) == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get number of edges/elem in block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     if ( (num_ed_per_elem == 0 && elem_edge_conn != 0) ||
          (num_ed_per_elem != 0 && elem_edge_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of edges per element (%ld) doesn't "
         "agree with elem_edge_conn (0x%p)",
         num_ed_per_elem, elem_edge_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( (num_fa_per_elem == 0 && elem_face_conn != 0) ||
          (num_fa_per_elem != 0 && elem_face_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of faces per element (%ld) doesn't "
         "agree with elem_face_conn (0x%p)",
         num_fa_per_elem, elem_face_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( num_ed_per_elem != 0 ) {
       connid = ncvarid (exoid, VAR_ECONN(blk_id_ndx));
       if (connid == -1)
         {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element edge block %d in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element edge",num_entry_this_blk,num_ed_per_elem,connid,elem_edge_conn);
     }

     if ( num_fa_per_elem != 0 ) {
       connid = ncvarid (exoid, VAR_FCONN(blk_id_ndx));
       if (connid == -1)
         {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element face block %d in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element face",num_entry_this_blk,num_fa_per_elem,connid,elem_face_conn);
     }
   }

   return (EX_NOERR);

}
示例#13
0
文件: exgblk.c 项目: 0004c/VTK
int ex_get_block( int exoid,
      ex_entity_type blk_type,
      int blk_id,
      char* elem_type,
      int* num_entries_this_blk,
      int* num_nodes_per_entry,
      int* num_edges_per_entry,
      int* num_faces_per_entry,
      int* num_attr_per_entry )
{
  int dimid, connid, blk_id_ndx;
  size_t len;
  char *ptr;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  const char* dnument;
  const char* dnumnod;
  const char* dnumedg;
  const char* dnumfac;
  const char* dnumatt;
  const char* ablknam;
  const char* vblkcon;

  exerrval = 0;

  /* First, locate index of element block id in VAR_ID_EL_BLK array */
  blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
  if (exerrval != 0)  {
    if (exerrval == EX_NULLENTITY) {    /* NULL element block?    */
      if ( elem_type )
  strcpy(elem_type, "NULL");     /* NULL element type name */
      *num_entries_this_blk = 0;       /* no elements            */
      *num_nodes_per_entry = 0;        /* no nodes               */
      *num_attr_per_entry = 0;         /* no attributes          */
      return (EX_NOERR);
    } else {
      sprintf(errmsg,
        "Error: failed to locate %s id %d in id array in file id %d",
        ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_get_block",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnument = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedg = 0;
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
    vblkcon = VAR_EBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_FACE_BLOCK:
    dnument = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedg = 0; /* it is possible this might be non-NULL some day */
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
    vblkcon = VAR_FBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_ELEM_BLOCK:
    dnument = DIM_NUM_EL_IN_BLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedg = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfac = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    dnumatt = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
    vblkcon = VAR_CONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Bad block type parameter (%d) specified for file id %d.",
       blk_type, exoid );
    return (EX_FATAL);
  }

  /* inquire values of some dimensions */
  if ( num_entries_this_blk ) {
    if ((status = nc_inq_dimid (exoid, dnument, &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to locate number of entities in %s %d in file id %d",
        ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_block",errmsg, exerrval);
      return(EX_FATAL);
    }

    if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to get number of %ss in block %d in file id %d",
        ex_name_of_object(blk_type),blk_id, exoid);
      ex_err("ex_get_block",errmsg, exerrval);
      return(EX_FATAL);
    }
    *num_entries_this_blk = len;
  }

  if ( num_nodes_per_entry ) {
    if ((status = nc_inq_dimid (exoid, dnumnod, &dimid)) != NC_NOERR) {
      /* undefined => no node entries per element */
      len = 0;
    } else {
      if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get number of nodes/entity in %s %d in file id %d",
    ex_name_of_object(blk_type),blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
    }
    *num_nodes_per_entry = len;
  }

  if ( num_edges_per_entry ) {
    if ( blk_type != EX_ELEM_BLOCK ) {
      exerrval = (EX_WARN);
      sprintf(errmsg,
        "Warning: non-NULL pointer passed to num_edges_per_entry for %s query in file id %d",
        ex_name_of_object(blk_type),exoid);
      ex_err("ex_get_block",errmsg,exerrval);
    } else {
      if ((status = nc_inq_dimid (exoid, dnumedg, &dimid)) != NC_NOERR) {
  /* undefined => no edge entries per element */
  len = 0;
      } else {
  if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to get number of edges/entry in %s %d in file id %d",
      ex_name_of_object(blk_type),blk_id, exoid);
    ex_err("ex_get_block",errmsg, exerrval);
    return(EX_FATAL);
  }
      }
      *num_edges_per_entry = len;
    }
  }

  if ( num_faces_per_entry ) {
    if ( blk_type != EX_ELEM_BLOCK ) {
      exerrval = (EX_WARN);
      sprintf(errmsg,
        "Warning: non-NULL pointer passed to num_faces_per_entry for %s query in file id %d",
        ex_name_of_object(blk_type),exoid);
      ex_err("ex_get_block",errmsg,exerrval);
    } else {
      if ((status = nc_inq_dimid (exoid, dnumfac, &dimid)) != NC_NOERR) {
  /* undefined => no face entries per element */
  len = 0;
      } else {
  if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to get number of faces/entity in %s %d in file id %d",
      ex_name_of_object(blk_type),blk_id, exoid);
    ex_err("ex_get_block",errmsg, exerrval);
    return(EX_FATAL);
  }
      }
      *num_faces_per_entry = len;
    }
  }

  if ( num_attr_per_entry ) {
    if ((status = nc_inq_dimid (exoid, dnumatt, &dimid)) != NC_NOERR) {
      /* dimension is undefined */
      *num_attr_per_entry = 0;
    } else {
      if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get number of attributes in %s %d in file id %d",
    ex_name_of_object(blk_type),blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
      *num_attr_per_entry = len;
    }
  }

  if ( elem_type ) {
    if (*num_nodes_per_entry > 0) {
      ; /* Do nothing, vblkcon should be correctly set already */
    } else if (*num_edges_per_entry > 0) {
      vblkcon = VAR_EBCONN(blk_id_ndx);
    } else if (*num_faces_per_entry > 0) {
      vblkcon = VAR_FCONN(blk_id_ndx);
    }

    if (vblkcon) {
      /* look up connectivity array for this element block id */
      if ((status = nc_inq_varid (exoid, vblkcon, &connid)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to locate connectivity array for %s %d in file id %d",
    ex_name_of_object(blk_type), blk_id,exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }

      if ((status = nc_inq_attlen (exoid, connid, ablknam, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get %s %d type in file id %d",
    ex_name_of_object(blk_type), blk_id,exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }

      if (len > (MAX_STR_LENGTH+1)) {
  len = MAX_STR_LENGTH;
  sprintf (errmsg,
     "Warning: %s %d type will be truncated to %ld chars", 
     ex_name_of_object(blk_type), blk_id, (long)len);
  ex_err("ex_get_block",errmsg,EX_MSG);
      }
      
      /* get the element type name */
      if ((status = nc_get_att_text (exoid, connid, ablknam, elem_type)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,"Error: failed to get %s %d type in file id %d",
    ex_name_of_object(blk_type), blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
      
      /* get rid of trailing blanks */
      ptr = elem_type;
      /* fprintf(stderr,"[exgblk] %s, len: %d\n",ptr,len); */
      while (ptr < elem_type + len && *ptr != ' ') {
  ptr++;
      }
      *(ptr) = '\0';
    }
  }
  return (EX_NOERR);
}