Exemple #1
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;
}
Exemple #2
0
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;
}
Exemple #3
0
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);
}