Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <hdf5.h>
#include "util.h"
#include "status.h"
#include "names-and-paths.h"
+ Include dependency graph for util.c:

Go to the source code of this file.

Macros

#define VALGRIND_CHECK_MEM_IS_DEFINED(A, B)
 
#define VALGRIND_MAKE_MEM_UNDEFINED(A, B)
 

Functions

void * mhdf_malloc (size_t size, mhdf_Status *status)
 
void * mhdf_realloc (void *ptr, size_t size, mhdf_Status *status)
 
size_t mhdf_name_to_path (const char *name, char *path, size_t path_len)
 
static int mhdf_hex_char (int c)
 
int mhdf_path_to_name (const char *path, char *name)
 
char * mhdf_name_to_path_copy (const char *name, mhdf_Status *status)
 
char * mhdf_name_to_path_cat (const char *prefix, const char *name, mhdf_Status *status)
 
hid_t mhdf_elem_group_from_handle (FileHandle *file_ptr, const char *elem_handle, mhdf_Status *status)
 
int mhdf_create_scalar_attrib (hid_t object, const char *name, hid_t type, const void *value, mhdf_Status *status)
 
int mhdf_read_scalar_attrib (hid_t object, const char *name, hid_t type, void *value, mhdf_Status *status)
 
static herr_t find_attr_by_name (hid_t handle, const char *name, void *mydata)
 
int mhdf_find_attribute (hid_t object, const char *attrib_name, unsigned int *index_out, mhdf_Status *status)
 
static herr_t find_link_by_name (hid_t handle, const char *name, void *mydata)
 
int mhdf_is_in_group (hid_t group, const char *name, mhdf_Status *status)
 
static int mhdf_readwrite (hid_t data_id, int read, long offset, long count, hid_t type, void *array, hid_t io_prop, mhdf_Status *status)
 
static int mhdf_readwrite_column (hid_t data_id, int read, int column, long offset, long count, hid_t type, void *array, hid_t io_prop, mhdf_Status *status)
 
int mhdf_write_data (hid_t data_id, long offset, long count, hid_t type_id, const void *array, hid_t prop, mhdf_Status *status)
 
int mhdf_read_data (hid_t data_id, long offset, long count, hid_t type_id, void *array, hid_t prop, mhdf_Status *status)
 
int mhdf_read_column (hid_t data_id, int column, long offset, long count, hid_t type, void *array, hid_t prop, mhdf_Status *status)
 
int mhdf_write_column (hid_t data_id, int column, long offset, long count, hid_t type, const void *array, hid_t prop, mhdf_Status *status)
 
hid_t mhdf_create_table (hid_t group_id, const char *path, hid_t type, int rank, hsize_t *dims, mhdf_Status *status)
 
hid_t mhdf_create_table_with_prop (hid_t group_id, const char *path, hid_t type, int rank, hsize_t *dims, hid_t create_prop, mhdf_Status *status)
 
hid_t mhdf_open_table (hid_t group_id, const char *path, int columns, hsize_t *rows_out, mhdf_Status *status)
 
hid_t mhdf_open_table2 (hid_t group_id, const char *path, int rank, hsize_t *dims_out, long *start_id_out, mhdf_Status *status)
 
hid_t mhdf_open_table_simple (hid_t group_id, const char *path, mhdf_Status *status)
 
static int qs_comp_int (const void *ptr1, const void *ptr2)
 
int mhdf_compact_to_ranges (int *length, int *ids, int ordered)
 
hid_t get_elem_type_enum (FileHandle *file_ptr, mhdf_Status *status)
 
int mhdf_write_max_id (FileHandle *file_ptr, mhdf_Status *status)
 
static int num_open (void)
 
void mhdf_api_begin_internal (void)
 
void mhdf_api_end_internal (int expected_diff, const char *filename, int linenumber)
 

Variables

static int mhdf_api_handle_count = 0
 

Macro Definition Documentation

◆ VALGRIND_CHECK_MEM_IS_DEFINED

#define VALGRIND_CHECK_MEM_IS_DEFINED (   A,
 
)

MOAB, a Mesh-Oriented datABase, is a software component for creating, storing and accessing finite element mesh data.

Copyright 2004 Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Definition at line 28 of file util.c.

◆ VALGRIND_MAKE_MEM_UNDEFINED

#define VALGRIND_MAKE_MEM_UNDEFINED (   A,
 
)

Definition at line 29 of file util.c.

Function Documentation

◆ find_attr_by_name()

static herr_t find_attr_by_name ( hid_t  handle,
const char *  name,
void *  mydata 
)
static

Definition at line 246 of file util.c.

247 { 248 #endif 249  /* empty statement to remove compiler warning */ 250  if( handle ) 251  { 252  } 253  return !strcmp( name, (const char*)mydata ); 254 }

Referenced by mhdf_find_attribute().

◆ find_link_by_name()

static herr_t find_link_by_name ( hid_t  handle,
const char *  name,
void *  mydata 
)
static

Definition at line 271 of file util.c.

272 { 273  /* empty statement to remove compiler warning */ 274  if( handle ) 275  { 276  } 277  return !strcmp( name, (const char*)mydata ); 278 }

Referenced by mhdf_is_in_group().

◆ get_elem_type_enum()

hid_t get_elem_type_enum ( FileHandle file_ptr,
mhdf_Status status 
)

Definition at line 786 of file util.c.

787 { 788  hid_t result; 789 #if defined( H5Topen_vers ) && H5Topen_vers > 1 790  result = H5Topen2( file_ptr->hdf_handle, TYPE_ENUM_PATH, H5P_DEFAULT ); 791 #else 792  result = H5Topen( file_ptr->hdf_handle, TYPE_ENUM_PATH ); 793 #endif 794  if( result < 0 ) mhdf_setFail( status, "Element type enum does not exist in file. Invalid file." ); 795  return result; 796 }

References struct_FileHandle::hdf_handle, mhdf_setFail(), and TYPE_ENUM_PATH.

Referenced by mhdf_addElement(), and mhdf_getElemName().

◆ mhdf_api_begin_internal()

void mhdf_api_begin_internal ( void  )

Definition at line 862 of file util.c.

863 { 864  /* HDF5 docs are incorrect. Passing H5F_OBJ_ALL as the first 865  arg to H5Fget_obj_count returns the total number of open 866  handles, not just those in files (i.e. temporary types and such.) 867  mhdf_api_handle_count = H5Fget_obj_count( H5F_OBJ_ALL, H5F_OBJ_ALL ); 868  Need to loop to get actual file handles: 869  */ 870  mhdf_api_handle_count = num_open(); 871 }

References mhdf_api_handle_count, and num_open().

◆ mhdf_api_end_internal()

void mhdf_api_end_internal ( int  expected_diff,
const char *  filename,
int  linenumber 
)

Definition at line 873 of file util.c.

874 { 875  if( mhdf_api_handle_count + expected_diff != num_open() ) 876  { 877  fprintf( stderr, "Unclosed handles at end of mhdf API call.\n" ); 878  fprintf( stderr, "Entered with %d, expected %d change, got %d.\n", mhdf_api_handle_count, expected_diff, 879  num_open() ); 880  fprintf( stderr, "%s:%d\n", filename, linenumber ); 881  abort(); 882  } 883  884  mhdf_api_handle_count = 0; 885 }

References mhdf_api_handle_count, and num_open().

◆ mhdf_compact_to_ranges()

int mhdf_compact_to_ranges ( int *  length,
int *  ids,
int  ordered 
)

Definition at line 733 of file util.c.

734 { 735  int new_length = 0; 736  int *iter, *end; 737  int prev, count; 738  int need_copy = 0; 739  int *copy_ptr = 0, *w_iter; 740  size_t blen; 741  742  if( !ordered ) qsort( ids, *length, sizeof( int ), &qs_comp_int ); 743  744  iter = ids; 745  end = ids + *length; 746  while( iter != end ) 747  { 748  prev = *( iter++ ); 749  while( iter < end && *( iter++ ) == ++prev ) 750  ; 751  new_length += 2; 752  if( new_length > ( iter - ids ) ) need_copy = 1; 753  } 754  755  if( new_length > *length ) return 0; 756  757  if( need_copy ) 758  { 759  blen = sizeof( int ) * *length; 760  copy_ptr = (int*)malloc( blen ); 761  memcpy( copy_ptr, ids, blen ); 762  iter = copy_ptr; 763  } 764  else 765  { 766  iter = ids; 767  } 768  769  end = iter + *length; 770  w_iter = ids; 771  while( iter != end ) 772  { 773  prev = *( iter++ ); 774  count = 1; 775  while( iter < end && *( iter++ ) == ++prev ) 776  ; 777  *( w_iter++ ) = prev - count; 778  *( w_iter++ ) = count; 779  } 780  781  *length = new_length; 782  if( need_copy ) free( copy_ptr ); 783  return 1; 784 }

References length(), and qs_comp_int().

◆ mhdf_create_scalar_attrib()

int mhdf_create_scalar_attrib ( hid_t  object,
const char *  name,
hid_t  type,
const void *  value,
mhdf_Status status 
)

Definition at line 164 of file util.c.

165 { 166  hid_t dspace_id, attr_id; 167  herr_t rval; 168  169  dspace_id = H5Screate( H5S_SCALAR ); 170  if( dspace_id < 0 ) 171  { 172  mhdf_setFail( status, "Internal error calling H5Screate_simple." ); 173  return 0; 174  } 175  176 #if defined( H5Acreate_vers ) && H5Acreate_vers > 1 177  attr_id = H5Acreate2( object, name, type, dspace_id, H5P_DEFAULT, H5P_DEFAULT ); 178 #else 179  attr_id = H5Acreate( object, name, type, dspace_id, H5P_DEFAULT ); 180 #endif 181  H5Sclose( dspace_id ); 182  if( attr_id < 0 ) 183  { 184  mhdf_setFail( status, "Failed to create \"%s\" attrib.", name ); 185  return 0; 186  } 187  188  VALGRIND_CHECK_MEM_IS_DEFINED( value, H5Tget_size( type ) ); 189  rval = H5Awrite( attr_id, type, value ); 190  H5Aclose( attr_id ); 191  if( rval < 0 ) 192  { 193  mhdf_setFail( status, "Failed to write \"%s\" attrib.", name ); 194  return 0; 195  } 196  197  return 1; 198 }

References mhdf_setFail(), and VALGRIND_CHECK_MEM_IS_DEFINED.

Referenced by create_tag_common(), mhdf_addElement(), mhdf_createConnectivity(), mhdf_createFile(), mhdf_createNodeCoords(), mhdf_createPolyConnectivity(), mhdf_createSetMeta(), mhdf_createVarLenTag(), and store_tag_val_in_attrib().

◆ mhdf_create_table()

hid_t mhdf_create_table ( hid_t  group_id,
const char *  path,
hid_t  type,
int  rank,
hsize_t *  dims,
mhdf_Status status 
)

◆ mhdf_create_table_with_prop()

hid_t mhdf_create_table_with_prop ( hid_t  group_id,
const char *  path,
hid_t  type,
int  rank,
hsize_t *  dims,
hid_t  create_prop,
mhdf_Status status 
)

Definition at line 568 of file util.c.

575 { 576  hid_t space_id, table_id; 577  578  space_id = H5Screate_simple( rank, dims, NULL ); 579  if( space_id < 0 ) 580  { 581  mhdf_setFail( status, "Internal error calling H5Screate_simple." ); 582  return -1; 583  } 584  585 #if defined( H5Dcreate_vers ) && H5Dcreate_vers > 1 586  table_id = H5Dcreate2( group_id, path, type, space_id, H5P_DEFAULT, create_prop, H5P_DEFAULT ); 587 #else 588  table_id = H5Dcreate( group_id, path, type, space_id, create_prop ); 589 #endif 590  H5Sclose( space_id ); 591  if( table_id < 0 ) 592  { 593  mhdf_setFail( status, "HDF5 DataSet creation failed." ); 594  return -1; 595  } 596  597  mhdf_setOkay( status ); 598  return table_id; 599 }

References mhdf_setFail(), and mhdf_setOkay().

Referenced by mhdf_create_table().

◆ mhdf_elem_group_from_handle()

hid_t mhdf_elem_group_from_handle ( FileHandle file_ptr,
const char *  elem_handle,
mhdf_Status status 
)

Definition at line 146 of file util.c.

147 { 148  char* path; 149  hid_t result; 150  151  path = mhdf_name_to_path_cat( ELEMENT_GROUP, elem_handle, status ); 152  if( NULL == path ) return -1; 153  154 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 155  result = H5Gopen2( file_ptr->hdf_handle, path, H5P_DEFAULT ); 156 #else 157  result = H5Gopen( file_ptr->hdf_handle, path ); 158 #endif 159  free( path ); 160  if( result < 0 ) mhdf_setFail( status, "Failed to open element group: \"%s\"", elem_handle ); 161  return result; 162 }

References ELEMENT_GROUP, struct_FileHandle::hdf_handle, mhdf_name_to_path_cat(), and mhdf_setFail().

Referenced by mhdf_createAdjacency(), mhdf_createConnectivity(), mhdf_createDenseTagData(), mhdf_createPolyConnectivity(), mhdf_getElemTypeName(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_isPolyElement(), mhdf_openAdjacency(), mhdf_openConnectivity(), mhdf_openConnectivitySimple(), mhdf_openDenseTagData(), and mhdf_openPolyConnectivity().

◆ mhdf_find_attribute()

int mhdf_find_attribute ( hid_t  object,
const char *  attrib_name,
unsigned int *  index_out,
mhdf_Status status 
)

Definition at line 256 of file util.c.

257 { 258  herr_t rval; 259 #if defined( H5Aiterate_vers ) && H5Aiterate_vers > 1 260  hsize_t idx = 0; 261  rval = H5Aiterate2( object, H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, &idx, &find_attr_by_name, (void*)attrib_name ); 262  *index_out = (unsigned int)idx; 263 #else 264  *index_out = 0; 265  rval = H5Aiterate( object, index_out, &find_attr_by_name, (void*)attrib_name ); 266 #endif 267  if( rval < 0 ) mhdf_setFail( status, "Internal error calling H5Aiterate." ); 268  return (int)rval; 269 }

References find_attr_by_name(), and mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_getTagValues(), mhdf_openSparseTagData(), and read_tag_attrib_data().

◆ mhdf_hex_char()

static int mhdf_hex_char ( int  c)
static

Definition at line 85 of file util.c.

86 { 87  if( isdigit( c ) ) 88  return c - '0'; 89  else 90  return toupper( c ) - ( 'A' - 10 ); 91 }

Referenced by mhdf_path_to_name().

◆ mhdf_is_in_group()

int mhdf_is_in_group ( hid_t  group,
const char *  name,
mhdf_Status status 
)

Definition at line 280 of file util.c.

281 { 282  int rval; 283  rval = H5Giterate( group, ".", NULL, &find_link_by_name, (void*)name ); 284  if( rval < 0 ) mhdf_setFail( status, "Internal error in H5Giterate." ); 285  return rval; 286 }

References find_link_by_name(), and mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_haveNodes(), mhdf_haveSets(), mhdf_isPolyElement(), mhdf_readHistory(), and scan_for_max_id().

◆ mhdf_malloc()

void* mhdf_malloc ( size_t  size,
mhdf_Status status 
)

MOAB, a Mesh-Oriented datABase, is a software component for creating, storing and accessing finite element mesh data.

Copyright 2004 Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Definition at line 32 of file util.c.

33 { 34  void* result; 35  result = malloc( size ); 36  if( !result ) mhdf_setFail( status, "Allocation of %d bytes failed.\n", (int)size ); 37  return result; 38 }

References mhdf_setFail(), and size.

Referenced by alloc_file_desc(), mhdf_addElement(), mhdf_alloc_FileHandle(), mhdf_createDenseTagData(), mhdf_getElemHandles(), mhdf_getFileSummary(), mhdf_getTagNames(), mhdf_name_to_path_cat(), mhdf_name_to_path_copy(), mhdf_openDenseTagData(), and mhdf_readHistory().

◆ mhdf_name_to_path()

size_t mhdf_name_to_path ( const char *  name,
char *  path,
size_t  path_len 
)

Definition at line 48 of file util.c.

49 { 50  size_t length = 1; 51  unsigned char* iter; 52  53  if( 0 == strcmp( name, "." ) ) 54  { 55  if( path_len >= 4 ) sprintf( path, "\\%02X", (int)*name ); 56  return 4; 57  } 58  59  for( iter = (unsigned char*)name; *iter; ++iter ) 60  { 61  if( iscntrl( *iter ) || *iter == '/' || *iter == '\\' || *iter > 127 ) 62  length += 3; 63  else 64  length += 1; 65  } 66  if( path_len < length ) return length; 67  68  for( iter = (unsigned char*)name; *iter; ++iter ) 69  { 70  if( iscntrl( *iter ) || *iter == '/' || *iter == '\\' || *iter > 127 ) 71  { 72  sprintf( path, "\\%02X", (int)( *iter ) ); 73  path += 3; 74  } 75  else 76  { 77  *( path++ ) = *iter; 78  } 79  } 80  81  *path = '\0'; 82  return length; 83 }

References length().

Referenced by mhdf_addElement(), mhdf_createDenseTagData(), mhdf_name_to_path_cat(), mhdf_name_to_path_copy(), and mhdf_openDenseTagData().

◆ mhdf_name_to_path_cat()

char* mhdf_name_to_path_cat ( const char *  prefix,
const char *  name,
mhdf_Status status 
)

Definition at line 131 of file util.c.

132 { 133  size_t size, plen; 134  char* buffer; 135  136  plen = strlen( prefix ); 137  size = mhdf_name_to_path( name, NULL, 0 ) + 1; 138  buffer = (char*)mhdf_malloc( size + plen, status ); 139  if( !buffer ) return NULL; 140  141  memcpy( buffer, prefix, plen ); 142  mhdf_name_to_path( name, buffer + plen, size ); 143  return buffer; 144 }

References buffer, mhdf_malloc(), mhdf_name_to_path(), and size.

Referenced by mhdf_elem_group_from_handle().

◆ mhdf_name_to_path_copy()

char* mhdf_name_to_path_copy ( const char *  name,
mhdf_Status status 
)

Definition at line 118 of file util.c.

119 { 120  size_t size; 121  char* buffer; 122  123  size = mhdf_name_to_path( name, NULL, 0 ); 124  buffer = (char*)mhdf_malloc( size, status ); 125  if( !buffer ) return NULL; 126  127  mhdf_name_to_path( name, buffer, size ); 128  return buffer; 129 }

References buffer, mhdf_malloc(), mhdf_name_to_path(), and size.

Referenced by create_tag_common(), get_tag(), mhdf_getTagDataType(), and mhdf_haveDenseTag().

◆ mhdf_open_table()

hid_t mhdf_open_table ( hid_t  group_id,
const char *  path,
int  columns,
hsize_t *  rows_out,
mhdf_Status status 
)

Definition at line 601 of file util.c.

602 { 603  hid_t table_id, space_id; 604  hsize_t dims[2]; 605  int rank; 606  607 #if defined( H5Dopen_vers ) && H5Dopen_vers > 1 608  table_id = H5Dopen2( group_id, path, H5P_DEFAULT ); 609 #else 610  table_id = H5Dopen( group_id, path ); 611 #endif 612  if( table_id < 0 ) 613  { 614  mhdf_setFail( status, "HDF5 DataSet creation failed." ); 615  return -1; 616  } 617  618  space_id = H5Dget_space( table_id ); 619  if( space_id < 0 ) 620  { 621  mhdf_setFail( status, "Internal error in H5Dget_space." ); 622  H5Dclose( table_id ); 623  return -1; 624  } 625  626  rank = H5Sget_simple_extent_ndims( space_id ); 627  if( rank != ( columns ? 1 : 2 ) ) 628  { 629  mhdf_setFail( status, "Incorrect DataSpace for DataSet." ); 630  H5Sclose( space_id ); 631  H5Dclose( table_id ); 632  return -1; 633  } 634  635  rank = H5Sget_simple_extent_dims( space_id, dims, NULL ); 636  H5Sclose( space_id ); 637  if( rank < 0 ) 638  { 639  mhdf_setFail( status, "Internal error calling H5Sget_simple_extent_dims." ); 640  H5Dclose( table_id ); 641  return -1; 642  } 643  644  *rows_out = dims[0]; 645  mhdf_setOkay( status ); 646  return table_id; 647 }

References mhdf_setFail(), and mhdf_setOkay().

Referenced by mhdf_openAdjacency(), mhdf_openDenseTagData(), mhdf_openPolyConnectivity(), mhdf_openSetChildren(), mhdf_openSetData(), mhdf_openSetParents(), and mhdf_openSparseTagData().

◆ mhdf_open_table2()

hid_t mhdf_open_table2 ( hid_t  group_id,
const char *  path,
int  rank,
hsize_t *  dims_out,
long *  start_id_out,
mhdf_Status status 
)

Definition at line 649 of file util.c.

655 { 656  hid_t table_id, space_id; 657  658 #if defined( H5Dopen_vers ) && H5Dopen_vers > 1 659  table_id = H5Dopen2( group_id, path, H5P_DEFAULT ); 660 #else 661  table_id = H5Dopen( group_id, path ); 662 #endif 663  if( table_id < 0 ) 664  { 665  mhdf_setFail( status, "HDF5 DataSet creation failed." ); 666  return -1; 667  } 668  669  space_id = H5Dget_space( table_id ); 670  if( space_id < 0 ) 671  { 672  mhdf_setFail( status, "Internal error in H5Dget_space." ); 673  H5Dclose( table_id ); 674  return -1; 675  } 676  677  if( H5Sget_simple_extent_ndims( space_id ) != rank ) 678  { 679  mhdf_setFail( status, "Incorrect DataSpace for DataSet." ); 680  H5Sclose( space_id ); 681  H5Dclose( table_id ); 682  return -1; 683  } 684  685  rank = H5Sget_simple_extent_dims( space_id, dims_out, NULL ); 686  H5Sclose( space_id ); 687  if( rank < 0 ) 688  { 689  mhdf_setFail( status, "Internal error calling H5Sget_simple_extent_dims." ); 690  H5Dclose( table_id ); 691  return -1; 692  } 693  694  if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, start_id_out, status ) ) 695  { 696  mhdf_setFail( status, "File format error. Failed to retreive ID offset." ); 697  H5Dclose( table_id ); 698  return -1; 699  } 700  701  mhdf_setOkay( status ); 702  return table_id; 703 }

References mhdf_read_scalar_attrib(), mhdf_setFail(), mhdf_setOkay(), and START_ID_ATTRIB.

Referenced by mhdf_openConnectivity(), mhdf_openNodeCoords(), and mhdf_openSetMeta().

◆ mhdf_open_table_simple()

hid_t mhdf_open_table_simple ( hid_t  group_id,
const char *  path,
mhdf_Status status 
)

Definition at line 705 of file util.c.

706 { 707  hid_t table_id; 708  709 #if defined( H5Dopen_vers ) && H5Dopen_vers > 1 710  table_id = H5Dopen2( group_id, path, H5P_DEFAULT ); 711 #else 712  table_id = H5Dopen( group_id, path ); 713 #endif 714  if( table_id < 0 ) 715  { 716  mhdf_setFail( status, "HDF5 DataSet creation failed." ); 717  } 718  else 719  { 720  mhdf_setOkay( status ); 721  } 722  723  return table_id; 724 }

References mhdf_setFail(), and mhdf_setOkay().

Referenced by mhdf_openConnectivitySimple(), mhdf_openNodeCoordsSimple(), and mhdf_openSetMetaSimple().

◆ mhdf_path_to_name()

int mhdf_path_to_name ( const char *  path,
char *  name 
)

Definition at line 93 of file util.c.

94 { 95  const char* iter; 96  char c1, c2; 97  98  for( iter = path; *iter; ++iter, ++name ) 99  { 100  if( *iter == '\\' ) 101  { 102  c1 = *++iter; 103  c2 = *++iter; 104  if( !isxdigit( c1 ) || !isxdigit( c2 ) ) return 0; 105  106  *name = (char)( 16 * mhdf_hex_char( c1 ) + mhdf_hex_char( c2 ) ); 107  } 108  else 109  { 110  *name = *iter; 111  } 112  } 113  114  *name = '\0'; 115  return 1; 116 }

References mhdf_hex_char().

Referenced by mhdf_addElement(), mhdf_getElemHandles(), and mhdf_getTagNames().

◆ mhdf_read_column()

int mhdf_read_column ( hid_t  data_id,
int  column,
long  offset,
long  count,
hid_t  type,
void *  array,
hid_t  prop,
mhdf_Status status 
)

Definition at line 539 of file util.c.

547 { 548  return mhdf_readwrite_column( data_id, 1, column, offset, count, type, array, prop, status ); 549 }

References mhdf_readwrite_column().

Referenced by mhdf_readNodeCoord(), and mhdf_readNodeCoordWithOpt().

◆ mhdf_read_data()

◆ mhdf_read_scalar_attrib()

int mhdf_read_scalar_attrib ( hid_t  object,
const char *  name,
hid_t  type,
void *  value,
mhdf_Status status 
)

Definition at line 200 of file util.c.

201 { 202  hid_t attr_id, type_id; 203  herr_t rval; 204  205  attr_id = H5Aopen_name( object, name ); 206  if( attr_id < 0 ) 207  { 208  mhdf_setFail( status, "Failed to create \"%s\" attrib.", name ); 209  return 0; 210  } 211  212  if( type > 0 ) 213  { 214  type_id = type; 215  } 216  else 217  { 218  type_id = H5Aget_type( attr_id ); 219  if( type_id < 0 ) 220  { 221  H5Aclose( attr_id ); 222  return 0; 223  } 224  } 225  226  rval = H5Aread( attr_id, type_id, value ); 227  H5Aclose( attr_id ); 228  if( type < 1 ) H5Tclose( type_id ); 229  if( rval < 0 ) 230  { 231  mhdf_setFail( status, "Failed to read \"%s\" attrib.", name ); 232  return 0; 233  } 234  235  return 1; 236 }

References mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_open_table2(), mhdf_openPolyConnectivity(), read_tag_attrib_data(), and scan_for_max_id().

◆ mhdf_readwrite()

static int mhdf_readwrite ( hid_t  data_id,
int  read,
long  offset,
long  count,
hid_t  type,
void *  array,
hid_t  io_prop,
mhdf_Status status 
)
static

Definition at line 288 of file util.c.

296 { 297  hid_t slab_id, mem_id; 298  hsize_t offsets[2], counts[2] = { 1, 1 }; 299  herr_t rval; 300  int dims; 301  /*#if (1000 * H5_VERS_MAJOR + H5_VERS_MINOR) < 1008*/ 302  const hsize_t one = 1; 303  /*#endif*/ 304  305  if( offset < 0 || count < 0 ) 306  { 307  mhdf_setFail( status, 308  "Invalid input for %s: " 309  "offset = %ld, count = %ld\n", 310  read ? "read" : "write", offset, count ); 311  return 0; 312  } 313  314  slab_id = H5Dget_space( data_id ); 315  if( slab_id < 0 ) 316  { 317  mhdf_setFail( status, "Internal error calling H5Dget_space." ); 318  return 0; 319  } 320  321  dims = H5Sget_simple_extent_ndims( slab_id ); 322  if( dims < 1 || dims > 2 ) 323  { 324  H5Sclose( slab_id ); 325  mhdf_setFail( status, "Internal error: unexpected dataset rank: %d.", dims ); 326  return 0; 327  } 328  329  dims = H5Sget_simple_extent_dims( slab_id, counts, NULL ); 330  if( dims < 0 ) 331  { 332  H5Sclose( slab_id ); 333  mhdf_setFail( status, "Internal error calling H5Sget_simple_extend_dims." ); 334  return 0; 335  } 336  337  if( (unsigned long)( offset + count ) > counts[0] ) 338  { 339  H5Sclose( slab_id ); 340  mhdf_setFail( status, "Requested %s of rows %ld to %ld of a %ld row table.\n", read ? "read" : "write", offset, 341  offset + count - 1, (long)counts[dims - 1] ); 342  return 0; 343  } 344  345  counts[0] = (hsize_t)count; 346  offsets[0] = (hsize_t)offset; 347  offsets[1] = 0; 348  if( count ) 349  rval = H5Sselect_hyperslab( slab_id, H5S_SELECT_SET, offsets, NULL, counts, NULL ); 350  else 351  rval = H5Sselect_none( slab_id ); 352  if( rval < 0 ) 353  { 354  H5Sclose( slab_id ); 355  mhdf_setFail( status, "Internal error calling H5Sselect_hyperslab." ); 356  return 0; 357  } 358  359  if( count ) 360  mem_id = H5Screate_simple( dims, counts, NULL ); 361  else 362  { 363  /*#if H5_VERS_MAJOR > 1 || H5_VERS_MINOR >= 8 364  mem_id = H5Screate(H5S_NULL); 365  #else*/ 366  mem_id = H5Screate_simple( 1, &one, NULL ); 367  if( mem_id && 0 > H5Sselect_none( mem_id ) ) 368  { 369  H5Sclose( mem_id ); 370  mem_id = -1; 371  } 372  /*#endif*/ 373  } 374  375  if( mem_id < 0 ) 376  { 377  H5Sclose( slab_id ); 378  mhdf_setFail( status, "Internal error calling H5Screate_simple." ); 379  return 0; 380  } 381  382  if( read ) 383  rval = H5Dread( data_id, type, mem_id, slab_id, io_prop, array ); 384  else 385  { 386  VALGRIND_CHECK_MEM_IS_DEFINED( array, counts[0] * counts[1] * H5Tget_size( type ) ); 387  rval = H5Dwrite( data_id, type, mem_id, slab_id, io_prop, array ); 388  } 389  H5Sclose( slab_id ); 390  H5Sclose( mem_id ); 391  if( rval < 0 ) 392  { 393  mhdf_setFail( status, "Internal error calling H5D%s.", read ? "read" : "write" ); 394  return 0; 395  } 396  397  mhdf_setOkay( status ); 398  return 1; 399 }

References mhdf_setFail(), mhdf_setOkay(), and VALGRIND_CHECK_MEM_IS_DEFINED.

Referenced by mhdf_read_data(), and mhdf_write_data().

◆ mhdf_readwrite_column()

static int mhdf_readwrite_column ( hid_t  data_id,
int  read,
int  column,
long  offset,
long  count,
hid_t  type,
void *  array,
hid_t  io_prop,
mhdf_Status status 
)
static

Definition at line 401 of file util.c.

410 { 411  hid_t slab_id, mem_id; 412  hsize_t offsets[2], counts[2]; 413  herr_t rval; 414  int dims; 415  /*#if (1000 * H5_VERS_MAJOR + H5_VERS_MINOR) < 1008*/ 416  const hsize_t one = 1; 417  /*#endif*/ 418  419  if( column < 0 || offset < 0 || count < 0 ) 420  { 421  mhdf_setFail( status, 422  "Invalid input for %s: " 423  "column = %d, offset = %ld, count = %ld\n", 424  read ? "read" : "write", column, offset, count ); 425  return 0; 426  } 427  428  slab_id = H5Dget_space( data_id ); 429  if( slab_id < 0 ) 430  { 431  mhdf_setFail( status, "Internal error calling H5Dget_space." ); 432  return 0; 433  } 434  435  dims = H5Sget_simple_extent_ndims( slab_id ); 436  if( dims < 1 || dims > 2 ) 437  { 438  H5Sclose( slab_id ); 439  mhdf_setFail( status, "Internal error: unexpected dataset rank: %d.", dims ); 440  return 0; 441  } 442  443  dims = H5Sget_simple_extent_dims( slab_id, counts, NULL ); 444  if( dims < 0 ) 445  { 446  H5Sclose( slab_id ); 447  mhdf_setFail( status, "Internal error calling H5Sget_simple_extend_dims." ); 448  return 0; 449  } 450  451  if( (unsigned long)( offset + count ) > counts[0] || (unsigned long)column > counts[1] ) 452  { 453  H5Sclose( slab_id ); 454  mhdf_setFail( status, "Requested %s of (%ld,%d)->(%ld,%ld) of (%ld, %ld) table.\n", read ? "read" : "write", 455  offset, column, offset + count - 1, column, (long)counts[0], (long)counts[1] ); 456  return 0; 457  } 458  459  counts[0] = (hsize_t)count; 460  offsets[0] = (hsize_t)offset; 461  counts[1] = 1; 462  offsets[1] = column; 463  if( count ) 464  rval = H5Sselect_hyperslab( slab_id, H5S_SELECT_SET, offsets, NULL, counts, NULL ); 465  else 466  rval = H5Sselect_none( slab_id ); 467  if( rval < 0 ) 468  { 469  H5Sclose( slab_id ); 470  mhdf_setFail( status, "Internal error calling H5Sselect_hyperslab." ); 471  return 0; 472  } 473  474  if( count ) 475  mem_id = H5Screate_simple( dims, counts, NULL ); 476  else 477  { 478  /*#if H5_VERS_MAJOR > 1 || H5_VERS_MINOR >= 8 479  mem_id = H5Screate(H5S_NULL); 480  #else*/ 481  mem_id = H5Screate_simple( 1, &one, NULL ); 482  if( mem_id && 0 > H5Sselect_none( mem_id ) ) 483  { 484  H5Sclose( mem_id ); 485  mem_id = -1; 486  } 487  /*#endif*/ 488  } 489  490  if( mem_id < 0 ) 491  { 492  H5Sclose( slab_id ); 493  mhdf_setFail( status, "Internal error calling H5Screate_simple." ); 494  return 0; 495  } 496  497  if( read ) 498  rval = H5Dread( data_id, type, mem_id, slab_id, io_prop, array ); 499  else 500  { 501  VALGRIND_CHECK_MEM_IS_DEFINED( array, count * H5Tget_size( type ) ); 502  rval = H5Dwrite( data_id, type, mem_id, slab_id, io_prop, array ); 503  VALGRIND_MAKE_MEM_UNDEFINED( array, count * H5Tget_size( type ) ); 504  } 505  H5Sclose( slab_id ); 506  H5Sclose( mem_id ); 507  if( rval < 0 ) 508  { 509  mhdf_setFail( status, "Internal error calling H5D%s.", read ? "read" : "write" ); 510  return 0; 511  } 512  513  mhdf_setOkay( status ); 514  return 1; 515 }

References mhdf_setFail(), mhdf_setOkay(), VALGRIND_CHECK_MEM_IS_DEFINED, and VALGRIND_MAKE_MEM_UNDEFINED.

Referenced by mhdf_read_column(), and mhdf_write_column().

◆ mhdf_realloc()

void* mhdf_realloc ( void *  ptr,
size_t  size,
mhdf_Status status 
)

Definition at line 40 of file util.c.

41 { 42  void* result; 43  result = realloc( ptr, size ); 44  if( !result ) mhdf_setFail( status, "Allocation of %d bytes failed.\n", (int)size ); 45  return result; 46 }

References mhdf_setFail(), and size.

Referenced by realloc_data().

◆ mhdf_write_column()

int mhdf_write_column ( hid_t  data_id,
int  column,
long  offset,
long  count,
hid_t  type,
const void *  array,
hid_t  prop,
mhdf_Status status 
)

Definition at line 551 of file util.c.

559 { 560  return mhdf_readwrite_column( data_id, 0, column, offset, count, type, (void*)array, prop, status ); 561 }

References mhdf_readwrite_column().

Referenced by mhdf_writeNodeCoord(), and mhdf_writeNodeCoordWithOpt().

◆ mhdf_write_data()

◆ mhdf_write_max_id()

int mhdf_write_max_id ( FileHandle file_ptr,
mhdf_Status status 
)

Definition at line 798 of file util.c.

799 { 800  hid_t group_id, attr_id, space_id; 801  herr_t rval; 802  803 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 804  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT ); 805 #else 806  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP ); 807 #endif 808  if( group_id < 0 ) 809  { 810  mhdf_setFail( status, "Internal error -- file invalid." ); 811  return 0; 812  } 813  814  attr_id = H5Aopen_name( group_id, MAX_ID_ATTRIB ); 815  if( attr_id < 0 ) 816  { 817  space_id = H5Screate( H5S_SCALAR ); 818 #if defined( H5Acreate_vers ) && H5Acreate_vers > 1 819  attr_id = H5Acreate2( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, space_id, H5P_DEFAULT, H5P_DEFAULT ); 820 #else 821  attr_id = H5Acreate( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, space_id, H5P_DEFAULT ); 822 #endif 823  H5Sclose( space_id ); 824  } 825  H5Gclose( group_id ); 826  if( attr_id < 0 ) 827  { 828  mhdf_setFail( status, "Failed to create attribute \"%s\" on \"%s\"", MAX_ID_ATTRIB, ROOT_GROUP ); 829  return 0; 830  } 831  832  rval = H5Awrite( attr_id, H5T_NATIVE_ULONG, &file_ptr->max_id ); 833  H5Aclose( attr_id ); 834  if( rval < 0 ) 835  { 836  mhdf_setFail( status, "Failed to write \"%s\" attrib.", MAX_ID_ATTRIB ); 837  return 0; 838  } 839  840  return 1; 841 }

References struct_FileHandle::hdf_handle, struct_FileHandle::max_id, MAX_ID_ATTRIB, mhdf_setFail(), and ROOT_GROUP.

Referenced by mhdf_createConnectivity(), mhdf_createNodeCoords(), mhdf_createPolyConnectivity(), and mhdf_createSetMeta().

◆ num_open()

static int num_open ( void  )
static

Definition at line 845 of file util.c.

846 { 847  hid_t list[64]; 848  int nf, rval, i, count = 0; 849  850  nf = H5Fget_obj_ids( H5F_OBJ_ALL, H5F_OBJ_FILE, sizeof( list ) / sizeof( hid_t ), list ); 851  if( nf <= 0 || nf > 64 ) return 0; 852  853  for( i = 0; i < nf; i++ ) 854  { 855  rval = H5Fget_obj_count( list[i], H5F_OBJ_ALL ); 856  if( rval > 0 ) count += rval; 857  } 858  859  return count; 860 }

Referenced by mhdf_api_begin_internal(), and mhdf_api_end_internal().

◆ qs_comp_int()

static int qs_comp_int ( const void *  ptr1,
const void *  ptr2 
)
static

Definition at line 726 of file util.c.

727 { 728  const int* left = (const int*)ptr1; 729  const int* right = (const int*)ptr2; 730  return *left < *right ? -1 : *left > *right ? 1 : 0; 731 }

Referenced by mhdf_compact_to_ranges().

Variable Documentation

◆ mhdf_api_handle_count

int mhdf_api_handle_count = 0
static

Definition at line 843 of file util.c.

Referenced by mhdf_api_begin_internal(), and mhdf_api_end_internal().