Ejemplo n.º 1
0
/*!
 * updates and then closes an open EXODUS II file
 */
int ex_close (int exoid)
{
   char errmsg[MAX_ERR_LENGTH];
   int status;
   
   exerrval = 0; /* clear error code */

   if ((status = nc_sync(exoid)) != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,"Error: failed to update file id %d",exoid);
     ex_err("ex_close",errmsg,exerrval);
     return(EX_FATAL);
   }
   /* Check header size.  Will print message if too big... */
   ex_header_size(exoid);

   if ((status = nc_close (exoid)) == NC_NOERR) {
     ex_conv_exit(exoid);

     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_SIDE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP));

     ex_rm_stat_ptr (exoid, &exoII_ed);
     ex_rm_stat_ptr (exoid, &exoII_fa);
     ex_rm_stat_ptr (exoid, &exoII_eb);
     ex_rm_stat_ptr (exoid, &exoII_ns);
     ex_rm_stat_ptr (exoid, &exoII_es);
     ex_rm_stat_ptr (exoid, &exoII_fs);
     ex_rm_stat_ptr (exoid, &exoII_ss);
     ex_rm_stat_ptr (exoid, &exoII_els);
     ex_rm_stat_ptr (exoid, &exoII_nm);
     ex_rm_stat_ptr (exoid, &exoII_edm);
     ex_rm_stat_ptr (exoid, &exoII_fam);
     ex_rm_stat_ptr (exoid, &exoII_em);
   }
   else {
     exerrval = status;
     sprintf(errmsg, "Error: failed to close file id %d",exoid);
     ex_err("ex_close",errmsg, status);
     return(EX_FATAL);
   }
   return(EX_NOERR);
}
Ejemplo n.º 2
0
/*!
 * updates and then closes an open EXODUS II file
 */
int ex_close (int exoid)
{
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   if (ncsync (exoid) == -1) {
     exerrval = ncerr;
     sprintf(errmsg,"Error: failed to update file id %d",exoid);
     ex_err("ex_close",errmsg,exerrval);
     return(EX_FATAL);
   }
   /* Check header size.  Will print message if too big... */
   ex_header_size(exoid);

   if (ncclose (exoid) >= 0 ) {
     ex_conv_exit(exoid);
     ex_rm_file_item(exoid, &ed_ctr_list);
     ex_rm_file_item(exoid, &fa_ctr_list);
     ex_rm_file_item(exoid, &eb_ctr_list);
     ex_rm_file_item(exoid, &ns_ctr_list);
     ex_rm_file_item(exoid, &es_ctr_list);
     ex_rm_file_item(exoid, &fs_ctr_list);
     ex_rm_file_item(exoid, &ss_ctr_list);
     ex_rm_file_item(exoid, &els_ctr_list);
     ex_rm_file_item(exoid, &nm_ctr_list);
     ex_rm_file_item(exoid, &edm_ctr_list);
     ex_rm_file_item(exoid, &fam_ctr_list);
     ex_rm_file_item(exoid, &em_ctr_list);

     rm_stat_ptr (exoid, &ed);
     rm_stat_ptr (exoid, &fa);
     rm_stat_ptr (exoid, &eb);
     rm_stat_ptr (exoid, &ns);
     rm_stat_ptr (exoid, &es);
     rm_stat_ptr (exoid, &fs);
     rm_stat_ptr (exoid, &ss);
     rm_stat_ptr (exoid, &els);
     rm_stat_ptr (exoid, &nm);
     rm_stat_ptr (exoid, &edm);
     rm_stat_ptr (exoid, &fam);
     rm_stat_ptr (exoid, &em);
   }
   else {
     exerrval = ncerr;
     sprintf(errmsg, "Error: failed to close file id %d",exoid);
     ex_err("ex_close",errmsg,ncerr);
     return(EX_FATAL);
   }
   return(EX_NOERR);
}
Ejemplo n.º 3
0
/*!

The function ex_close() updates and then closes an open exodus file.

\return In case of an error, ex_close() returns a negative number; a
        warning will return a positive number. Possible causes of errors
	include:
 - data file not properly opened with call to ex_create() or ex_open()

 \param exoid      exodus file ID returned from a previous call to ex_create() or ex_open().

The following code segment closes an open exodus file:

\code
int error,exoid;
error = ex_close (exoid);
\endcode

 */
int ex_close (int exoid)
{
   char errmsg[MAX_ERR_LENGTH];
   int status;
   int parent_id = 0;

   exerrval = 0; /* clear error code */
   /*
    * NOTE: If using netcdf-4, exoid must refer to the root group.
    * Need to determine whether there are any groups and if so,
    * call ex_rm_file_item and ex_rm_stat_ptr on each group.
    */

#if defined(ENABLE_NETCDF4)
   /* nc_inq_grp_parent() will return NC_ENOGRP error if exoid
    * refers to the root group (which is what we want)
    */
   if ((status = nc_inq_grp_parent(exoid, &parent_id)) != NC_ENOGRP) {
     exerrval = EX_NOTROOTID;
     sprintf(errmsg,"Error: file id %d does not refer to root group.",exoid);
     ex_err("ex_close",errmsg,exerrval);
     return(EX_FATAL);
   }
#endif
   
   if ((status = nc_sync(exoid)) != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,"Error: failed to update file id %d",exoid);
     ex_err("ex_close",errmsg,exerrval);
     return(EX_FATAL);
   }
   if ((status = nc_close (exoid)) == NC_NOERR) {
     ex_conv_exit(exoid);

     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_SIDE_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_SET));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_MAP));
     ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP));

     ex_rm_stat_ptr (exoid, &exoII_ed);
     ex_rm_stat_ptr (exoid, &exoII_fa);
     ex_rm_stat_ptr (exoid, &exoII_eb);
     ex_rm_stat_ptr (exoid, &exoII_ns);
     ex_rm_stat_ptr (exoid, &exoII_es);
     ex_rm_stat_ptr (exoid, &exoII_fs);
     ex_rm_stat_ptr (exoid, &exoII_ss);
     ex_rm_stat_ptr (exoid, &exoII_els);
     ex_rm_stat_ptr (exoid, &exoII_nm);
     ex_rm_stat_ptr (exoid, &exoII_edm);
     ex_rm_stat_ptr (exoid, &exoII_fam);
     ex_rm_stat_ptr (exoid, &exoII_em);
   }
   else {
     exerrval = status;
     sprintf(errmsg, "Error: failed to close file id %d",exoid);
     ex_err("ex_close",errmsg, status);
     return(EX_FATAL);
   }
   return(EX_NOERR);
}
Ejemplo n.º 4
0
/*!

The function ex_close() updates and then closes an open exodus file.

\return In case of an error, ex_close() returns a negative number; a
        warning will return a positive number. Possible causes of errors
        include:
 - data file not properly opened with call to ex_create() or ex_open()

 \param exoid      exodus file ID returned from a previous call to ex_create()
or ex_open().

The following code segment closes an open exodus file:

~~~{.c}
int error,exoid;
error = ex_close (exoid);
~~~

 */
int ex_close(int exoid)
{
  char errmsg[MAX_ERR_LENGTH];
  int  status;
  int  status1;
  int  status2;
#if NC_HAS_HDF5
  int parent_id = 0;
#endif

  EX_FUNC_ENTER();

  ex_check_valid_file_id(exoid, __func__);

  /*
   * NOTE: If using netcdf-4, exoid must refer to the root group.
   * Need to determine whether there are any groups and if so,
   * call ex_rm_file_item and ex_rm_stat_ptr on each group.
   */

#if NC_HAS_HDF5
  /* nc_inq_grp_parent() will return NC_ENOGRP error if exoid
   * refers to the root group (which is what we want)
   */
  if ((status = nc_inq_grp_parent(exoid, &parent_id)) != NC_ENOGRP) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: file id %d does not refer to root group.", exoid);
    ex_err(__func__, errmsg, EX_NOTROOTID);
    EX_FUNC_LEAVE(EX_FATAL);
  }
#endif

  if ((status1 = nc_sync(exoid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to update file id %d", exoid);
    ex_err(__func__, errmsg, status1);
  }

  if ((status2 = nc_close(exoid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to close file id %d", exoid);
    ex_err(__func__, errmsg, status2);
  }

  /* Even if we have failures above due to nc_sync() or nc_close(), we still need to clean up our
   * internal datastructures.
   */

  ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_SET));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_SET));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_SET));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_SIDE_SET));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_SET));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_MAP));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_MAP));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_MAP));
  ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP));

  ex_rm_stat_ptr(exoid, &exoII_ed);
  ex_rm_stat_ptr(exoid, &exoII_fa);
  ex_rm_stat_ptr(exoid, &exoII_eb);
  ex_rm_stat_ptr(exoid, &exoII_ns);
  ex_rm_stat_ptr(exoid, &exoII_es);
  ex_rm_stat_ptr(exoid, &exoII_fs);
  ex_rm_stat_ptr(exoid, &exoII_ss);
  ex_rm_stat_ptr(exoid, &exoII_els);
  ex_rm_stat_ptr(exoid, &exoII_nm);
  ex_rm_stat_ptr(exoid, &exoII_edm);
  ex_rm_stat_ptr(exoid, &exoII_fam);
  ex_rm_stat_ptr(exoid, &exoII_em);

  ex_conv_exit(exoid);

  status = EX_NOERR;
  if (status1 != NC_NOERR || status2 != NC_NOERR) {
    status = EX_FATAL;
  }
  EX_FUNC_LEAVE(status);
}