Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
util.h File Reference
#include <sys/types.h>
#include <H5Ipublic.h>
#include "status.h"
#include "file-handle.h"
+ Include dependency graph for util.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define API_BEGIN
 
#define API_END_H(n)
 
#define API_END   API_END_H( 0 )
 

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)
 
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)
 
int mhdf_find_attribute (hid_t object, const char *attrib_name, unsigned int *index_out, mhdf_Status *status)
 
int mhdf_is_in_group (hid_t group, const char *name, mhdf_Status *status)
 
int mhdf_read_data (hid_t data_table, long offset, long count, hid_t type, void *array, hid_t read_prop, mhdf_Status *status)
 
int mhdf_write_data (hid_t data_table, long offset, long count, hid_t type, const void *array, hid_t write_prop, mhdf_Status *status)
 
int mhdf_read_column (hid_t data_table, int column, long offset, long count, hid_t type, void *array, hid_t read_prop, mhdf_Status *status)
 
int mhdf_write_column (hid_t data_table, int column, long offset, long count, hid_t type, const void *array, hid_t write_prop, mhdf_Status *status)
 
hid_t mhdf_create_table (hid_t group, const char *path, hid_t type, int rank, hsize_t *dims, mhdf_Status *status)
 
hid_t mhdf_create_table_with_prop (hid_t group, const char *path, hid_t type, int rank, hsize_t *dims, hid_t dataset_creation_prop, mhdf_Status *status)
 
hid_t mhdf_open_table (hid_t group, const char *path, int columns, hsize_t *rows_out, mhdf_Status *status)
 
hid_t mhdf_open_table2 (hid_t group, 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, const char *path, mhdf_Status *status)
 
int mhdf_compact_to_ranges (int *length_in_out, int *ids_in, int ordered)
 
hid_t get_elem_type_enum (FileHandle *file_ptr, mhdf_Status *status)
 
void mhdf_api_begin_internal (void)
 
void mhdf_api_end_internal (int expected_diff, const char *filename, int linenumber)
 
int mhdf_write_max_id (FileHandle *file_ptr, mhdf_Status *status)
 

Macro Definition Documentation

◆ API_BEGIN

#define API_BEGIN

Definition at line 122 of file util.h.

◆ API_END

#define API_END   API_END_H( 0 )

Definition at line 128 of file util.h.

◆ API_END_H

#define API_END_H (   n)

Definition at line 123 of file util.h.

Function Documentation

◆ 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  */
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 
885 }

References mhdf_api_handle_count, and num_open().

◆ mhdf_compact_to_ranges()

int mhdf_compact_to_ranges ( int *  length_in_out,
int *  ids_in,
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,
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,
const char *  path,
hid_t  type,
int  rank,
hsize_t *  dims,
hid_t  dataset_creation_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_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,
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,
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,
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_table,
int  column,
long  offset,
long  count,
hid_t  type,
void *  array,
hid_t  read_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_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_table,
int  column,
long  offset,
long  count,
hid_t  type,
const void *  array,
hid_t  write_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().