Пример #1
0
static int
scan_for_max_id( FileHandle* file_ptr, mhdf_Status* status )
{
  hid_t group_id;
  herr_t rval;
  
    /* Check for new format, with max_id as attrib of root 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
  if (group_id < 0)
  {
    mhdf_setFail( status, "Internal error - invalid file.");
    return 0;
  }
  if (mhdf_read_scalar_attrib( group_id, MAX_ID_ATTRIB,
                               H5T_NATIVE_ULONG, &file_ptr->max_id,
                               status ))
  {
    H5Gclose( group_id );
    return 1;
  }
  
    /* Didn't find it, scan the elements group */
  rval = H5Giterate( group_id, ELEMENT_GROUP_NAME, 0, &max_id_iter, &file_ptr->max_id );
  if (rval)
  {
    H5Gclose( group_id );
    mhdf_setFail( status, "Internal error -- invalid file." );
    return 0;
  }
  
    /* Check node table too */
  rval = get_max_id( group_id, NODE_GROUP_NAME, "coordinates", (unsigned long*)(&file_ptr->max_id) );
  if (rval)
  {
    H5Gclose( group_id );
    mhdf_setFail( status, "Internal error -- invalid file." );
    return 0;
  }
  
    /* Check set table, if it exists */
  rval = mhdf_is_in_group( group_id, SET_GROUP_NAME, status );
  if (rval < 1)
  {
    H5Gclose( group_id );
    return !rval;
  }
  rval = get_max_id( group_id, SET_GROUP_NAME, SET_META_NAME, (unsigned long*)(&file_ptr->max_id) );
  H5Gclose( group_id );
  if (rval)
  {
    mhdf_setFail( status, "Internal error -- invalid file." );
    return 0;
  }

  return 1;
}    
Пример #2
0
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);
}