示例#1
0
文件: connectivity.c 项目: obmun/moab
hid_t
mhdf_openConnectivitySimple( mhdf_FileHandle file_handle,
                             const char* elem_handle,
                             mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, table_id;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file_handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return -1;
  
  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
  if (elem_id < 0) return -1;
  
  table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status );
  
  H5Gclose( elem_id );
  if (table_id < 0)
    return -1;
  
  file_ptr->open_handle_count++;
  mhdf_setOkay( status );
  API_END_H(1);
  return table_id;
}
示例#2
0
文件: file.c 项目: chrismullins/moab
void 
mhdf_closeFile( mhdf_FileHandle handle,
                mhdf_Status* status )
{
  FileHandle* file_ptr;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return;
/* 
  if (file_ptr->open_handle_count)
  {
    mhdf_setError( status, "Cannot close file with %d open data handles.", 
      file_ptr->open_handle_count );
    return;
  }
*/  
  
  /* Check for open handles.  HDF5 will not actually close the
     file until all handles are closed. */
  if (mhdf_checkOpenHandles( handle, status ))
    return;
 
  if (0 > H5Fclose( file_ptr->hdf_handle ))
  {
    mhdf_setFail( status, "H5FClose failed.  Invalid handle?" );
    return;
  } 
  
  memset( file_ptr, 0, sizeof(FileHandle) );
  free( file_ptr );
  mhdf_setOkay( status );
  API_END_H( -1 );
}
示例#3
0
文件: file.c 项目: chrismullins/moab
int
mhdf_checkOpenHandles( mhdf_FileHandle handle,
                       mhdf_Status* status )
{
  FileHandle* file_ptr;
  int result;
  API_BEGIN;

  file_ptr = (FileHandle*)(handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return -1;
  
  /* Check for open handles.  HDF5 will not actually close the
     file until all handles are closed. */
  result = H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_ALL );
  if (result != 1)
  {
    mhdf_setFail( status, "Cannot close file with open handles: "
                 "%d file, %d data, %d group, %d type, %d attr\n",
                  H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_FILE ) - 1,
                  H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_DATASET ),
                  H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_GROUP ),
                  H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_DATATYPE ),
                  H5Fget_obj_count( file_ptr->hdf_handle, H5F_OBJ_ATTR ) );
    return result - 1;
  }

  API_END_H( 0 );
  return 0;
}
示例#4
0
文件: connectivity.c 项目: obmun/moab
void
mhdf_openPolyConnectivity( mhdf_FileHandle file_handle,
                           const char* element_handle,
                           long* num_poly_out,
                           long* data_list_length_out,
                           long* first_poly_id_out,
                           hid_t handles_out[2],
                           mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, table_id, index_id;
  hsize_t row_count;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file_handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return ;
  
  if (!num_poly_out || !data_list_length_out || !first_poly_id_out)
  {
    mhdf_setFail( status, "Invalid argument." );
    return ;
  }
  
  elem_id = mhdf_elem_group_from_handle( file_ptr, element_handle, status );
  if (elem_id < 0) return ;
  
  index_id = mhdf_open_table( elem_id, POLY_INDEX_NAME,
                              1, &row_count, status );
  if (index_id < 0)
    { H5Gclose(elem_id); return ; }
  *num_poly_out = (int)row_count;
  
  table_id = mhdf_open_table( elem_id, CONNECTIVITY_NAME, 
                              1, &row_count, status );
  
  H5Gclose( elem_id );
  if (table_id < 0)
  {
    H5Dclose( index_id );
    return ;
  }
  *data_list_length_out = (long)row_count;
    
  if (!mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, 
                                first_poly_id_out, status ))
  {
    H5Dclose( table_id );
    H5Dclose( index_id );
    return ;
  }
  
  file_ptr->open_handle_count++;
  handles_out[0] = index_id;
  handles_out[1] = table_id;
  mhdf_setOkay( status );
  API_END_H(2);
}
示例#5
0
hid_t
mhdf_createAdjacency( mhdf_FileHandle file,
                      const char* elem_handle,
                      long adj_list_size,
                      mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, table_id;
  hsize_t dim = (hsize_t)adj_list_size;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return -1;

  if (adj_list_size < 1)
  {
    mhdf_setFail( status, "Invalid argument.\n" );
    return -1;
  }
  
  if (elem_handle == mhdf_node_type_handle())
  {
    table_id = mhdf_create_table( file_ptr->hdf_handle,
                                  NODE_ADJCY_PATH,
                                  file_ptr->id_type,
                                  1, &dim,
                                  status );
  }
  else
  {
    elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
    if (elem_id < 0) return -1;
    
    table_id = mhdf_create_table( elem_id,
                                  ADJACENCY_NAME,
                                  file_ptr->id_type,
                                  1, &dim,
                                  status );
    H5Gclose( elem_id );
  }
  
  API_END_H(1);
  return table_id;
}
示例#6
0
文件: connectivity.c 项目: obmun/moab
hid_t
mhdf_openConnectivity( mhdf_FileHandle file_handle,
                       const char* elem_handle,
                       int* num_nodes_per_elem_out,
                       long* num_elements_out,
                       long* first_elem_id_out,
                       mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, table_id;
  hsize_t dims[2];
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file_handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return -1;
  
  if (!num_nodes_per_elem_out || !num_elements_out || !first_elem_id_out)
  {
    mhdf_setFail( status, "Invalid argument." );
    return -1;
  }
  
  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
  if (elem_id < 0) return -1;
  
  table_id = mhdf_open_table2( elem_id, CONNECTIVITY_NAME, 
                               2, dims,
                               first_elem_id_out, status );
  
  H5Gclose( elem_id );
  if (table_id < 0)
    return -1;
  
  *num_elements_out = dims[0];
  *num_nodes_per_elem_out = dims[1];
  
  file_ptr->open_handle_count++;
  mhdf_setOkay( status );
  API_END_H(1);
  return table_id;
}
示例#7
0
文件: connectivity.c 项目: obmun/moab
hid_t 
mhdf_createConnectivity( mhdf_FileHandle file_handle,
                         const char* elem_handle,
                         int nodes_per_elem,
                         long count,
                         long* first_id_out,
                         mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, table_id;
  hsize_t dims[2];
  long first_id;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file_handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return -1;
  
  if (nodes_per_elem <= 0 || count < 0 || !first_id_out)
  {
    mhdf_setFail( status, "Invalid argument." );
    return -1;
  }
  
  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
  if (elem_id < 0) return -1;
  
  
  dims[0] = (hsize_t)count;
  dims[1] = (hsize_t)nodes_per_elem;
  table_id = mhdf_create_table( elem_id, 
                                CONNECTIVITY_NAME,
                                file_ptr->id_type,
                                2, dims, 
                                status );
  H5Gclose( elem_id );
  if (table_id < 0)
    return -1;
  
  first_id = file_ptr->max_id + 1;
  if (!mhdf_create_scalar_attrib( table_id, 
                                 START_ID_ATTRIB, 
                                 H5T_NATIVE_LONG,
                                 &first_id,
                                 status ))
  {
    H5Dclose( table_id );
    return -1;
  }
  
  *first_id_out = first_id;
  file_ptr->max_id += count;
  if (!mhdf_write_max_id( file_ptr, status))
  {
    H5Dclose( table_id );
    return -1;
  }
  file_ptr->open_handle_count++;
  mhdf_setOkay( status );
 
  API_END_H(1);
  return table_id;
}
示例#8
0
文件: connectivity.c 项目: obmun/moab
void 
mhdf_createPolyConnectivity( mhdf_FileHandle file_handle,
                             const char* elem_type,
                             long num_poly,
                             long data_list_length,
                             long* first_id_out,
                             hid_t handles_out[2],
                             mhdf_Status* status )
{
  FileHandle* file_ptr;
  hid_t elem_id, index_id, conn_id;
  hsize_t dim;
  long first_id;
  API_BEGIN;
  
  file_ptr = (FileHandle*)(file_handle);
  if (!mhdf_check_valid_file( file_ptr, status ))
    return;
  
  if (num_poly <= 0 || data_list_length <= 0 || !first_id_out)
  {
    mhdf_setFail( status, "Invalid argument." );
    return;
  }
  
  if (data_list_length < 3*num_poly)
  {
    /* Could check agains 4*num_poly, but allow degenerate polys
       (1 for count plus 2 dim-1 defining entities, where > 2
        defining entities is a normal poly, 2 defining entities 
        is a degenerate poly and 1 defning entity is not valid.)
    */
    
    mhdf_setFail( status, "Invalid polygon data:  data length of %ld is "
                          "insufficient for %ld poly(gons/hedra).\n",
                          data_list_length, num_poly );
    return;
  }
  
  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_type, status );
  if (elem_id < 0) return;
  
  dim = (hsize_t)num_poly;
  index_id = mhdf_create_table( elem_id,
                                POLY_INDEX_NAME,
                                MHDF_INDEX_TYPE,
                                1, &dim,
                                status );
  if (index_id < 0)
    { H5Gclose(elem_id); return; }
  
  
  dim = (hsize_t)data_list_length;
  conn_id = mhdf_create_table( elem_id, 
                                CONNECTIVITY_NAME,
                                file_ptr->id_type,
                                1, &dim, 
                                status );
  H5Gclose( elem_id );
  if (conn_id < 0)
  {
    H5Dclose(index_id);
    return;
  }
  
  first_id = file_ptr->max_id + 1;
  if (!mhdf_create_scalar_attrib( conn_id, 
                                 START_ID_ATTRIB, 
                                 H5T_NATIVE_LONG,
                                 &first_id,
                                 status ))
  {
    H5Dclose(index_id);
    H5Dclose( conn_id );
    return;
  }
  
  *first_id_out = first_id;
  file_ptr->max_id += num_poly;
  if (!mhdf_write_max_id( file_ptr, status))
  {
    H5Dclose(index_id);
    H5Dclose( conn_id );
    return;
  }
  file_ptr->open_handle_count++;
  mhdf_setOkay( status );
  handles_out[0] = index_id;
  handles_out[1] = conn_id;
  API_END_H(2);
}
示例#9
0
文件: file.c 项目: chrismullins/moab
mhdf_FileHandle
mhdf_createFile( const char* filename, 
                 int overwrite, 
                 const char** elem_type_list,
                 size_t elem_list_len,
                 hid_t id_type,
                 mhdf_Status* status )
{
  FileHandle* file_ptr;
  unsigned int flags;
  unsigned char idx;
  size_t i;
  hid_t enum_id, group_id;
  int rval;
  API_BEGIN;
  
  if (elem_list_len > 255)
  {
    mhdf_setFail( status, "Element type list too long." );
    return NULL;
  }
  mhdf_setOkay( status );
  
    /* Create struct to hold working data */
  file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
  if (!file_ptr) return NULL;

    /* Create the file */
  flags = overwrite ? H5F_ACC_TRUNC : H5F_ACC_EXCL;
  file_ptr->hdf_handle = H5Fcreate( filename, flags, H5P_DEFAULT, H5P_DEFAULT );
  if (file_ptr->hdf_handle < 0)
  {
    mhdf_setFail( status, "Failed to create file \"%s\"", filename );
    free( file_ptr );
    return NULL;
  }
  
  
    /* Create file structure */
  if (!make_hdf_group(     ROOT_GROUP, file_ptr->hdf_handle, 6, status )
   || !make_hdf_group(      TAG_GROUP, file_ptr->hdf_handle, 0, status )
   || !make_hdf_group(  ELEMENT_GROUP, file_ptr->hdf_handle, 8, status )
   || !make_hdf_group(     NODE_GROUP, file_ptr->hdf_handle, 3, status )
   || !make_hdf_group(      SET_GROUP, file_ptr->hdf_handle, 5, status )
   || !make_hdf_group( NODE_TAG_GROUP, file_ptr->hdf_handle, 0, status )
   || !make_hdf_group(  SET_TAG_GROUP, file_ptr->hdf_handle, 0, status ))
  {
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  
    /* Store the max ID as an attribite on the /tstt/ group */
#if defined(H5Gopen_vers) && H5Gopen_vers > 1  
  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
  rval = mhdf_create_scalar_attrib( group_id, 
                                    MAX_ID_ATTRIB, 
                                    H5T_NATIVE_ULONG, 
                                    &file_ptr->max_id,
                                    status );
  H5Gclose( group_id );
  if (!rval)
  {
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  
    /* Create the type name list in file */
  enum_id = H5Tenum_create( H5T_NATIVE_UCHAR );
  if (enum_id < 0)
  {
    mhdf_setFail( status, "Failed to store elem type list." );
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  for (i = 0; i < elem_list_len; ++i)
  {
    if (!elem_type_list[i] || !*elem_type_list[i])
      continue;
      
    idx = (unsigned char)i;
    if ( H5Tenum_insert( enum_id, elem_type_list[i], &idx ) < 0)
    {
      mhdf_setFail( status, "Failed to store elem type list." );
      H5Fclose( file_ptr->hdf_handle );
      free( file_ptr );
      return NULL;
    }
  }
#if defined(H5Tcommit_vers) && H5Tcommit_vers > 1
  if (H5Tcommit2( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) < 0)  
#else
  if (H5Tcommit( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id ) < 0)  
#endif
  {
    mhdf_setFail( status, "Failed to store elem type list." );
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  H5Tclose( enum_id );
  
  API_END_H( 1 );
  return file_ptr;
}
示例#10
0
文件: file.c 项目: chrismullins/moab
mhdf_FileHandle
mhdf_openFileWithOpt( const char* filename, 
                      int writable, 
                      unsigned long* max_id_out,
                      hid_t id_type,
                      hid_t access_prop,
                      mhdf_Status* status )
{
  FileHandle* file_ptr;
  unsigned int flags;
  hid_t group_id;
  int check_is_hdf5 = 1;
#ifdef HDF5_PARALLEL
  herr_t err;
  MPI_Comm comm;
  MPI_Info info;
#endif
  API_BEGIN;
  
    /* Check if file is HDF5 */
  /* Don't do this because it can't handle MPI-IO driver code that
     passes options via prefixes on the file name. */
#ifdef HDF5_PARALLEL
  if (access_prop != H5P_DEFAULT) {
    err = H5Pget_fapl_mpio( access_prop, &comm, &info );
    if (err >= 0) {
      check_is_hdf5 = 0;
      /* MPI Documentation is inconsistent with regards to whether
         or not the above call dup's these, but my testing with 1.8.3
         indicates that at least for that version they are not.
      MPI_Comm_free(&comm);
      MPI_Info_free(&info); */
    }
  }
#endif
  if (check_is_hdf5 && H5Fis_hdf5( filename ) <= 0) {
    mhdf_setFail( status, "%s: File is not HDF5", filename );
    return NULL;
  }
  
    /* Create struct to hold working data */
  file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
  if (!file_ptr) {
    mhdf_setFail( status, "Memory allocation failed" );
    return NULL;
  }  

    /* Create the file */
  flags = writable ? H5F_ACC_RDWR : H5F_ACC_RDONLY;
  file_ptr->hdf_handle = H5Fopen( filename, flags, access_prop );
  if (file_ptr->hdf_handle < 0)
  {
    mhdf_setFail( status, "Failed to open file \"%s\"", filename );
    free( file_ptr );
    return NULL;
  }
  
    /* Check for TSTT data in file */
#if defined(H5Gopen_vers) && H5Gopen_vers > 1  
  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
  if (group_id < 0)
  {
    mhdf_setFail( status, "Invalid file \"%s\"\n", filename );
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  H5Gclose( group_id );
  
    /* Get max id */
  if (!scan_for_max_id( file_ptr, status ))
  {
    H5Fclose( file_ptr->hdf_handle );
    mhdf_setFail( status, "Internal error reading file" );
    free( file_ptr );
    return NULL;
  }
  
  if (max_id_out)
    *max_id_out = file_ptr->max_id;
    
  mhdf_setOkay( status );
  API_END_H(1);
  return file_ptr;
}