18 #include <H5Tpublic.h>
19 #include <H5Gpublic.h>
20 #include <H5Dpublic.h>
21 #include <H5Spublic.h>
22 #include <H5Apublic.h>
23 #include <H5Ppublic.h>
34 hid_t tmp_id, type_id;
38 cls = H5Tget_class( input_type );
45 return H5T_NATIVE_FLOAT;
47 return H5T_NATIVE_DOUBLE;
49 return H5T_NATIVE_LDOUBLE;
56 sgn = H5Tget_sign( input_type );
57 if( H5T_SGN_ERROR == sgn )
59 mhdf_setFail( status,
"Internall errror calling H5Tget_sign." );
62 if(
sizeof(
char ) ==
size )
63 return sgn == H5T_SGN_NONE ? H5T_NATIVE_UCHAR : H5T_NATIVE_SCHAR;
64 else if(
sizeof(
short ) ==
size )
65 return sgn == H5T_SGN_NONE ? H5T_NATIVE_USHORT : H5T_NATIVE_SHORT;
66 else if(
sizeof(
int ) ==
size )
67 return sgn == H5T_SGN_NONE ? H5T_NATIVE_UINT : H5T_NATIVE_INT;
68 else if(
sizeof(
long ) ==
size )
69 return sgn == H5T_SGN_NONE ? H5T_NATIVE_ULONG : H5T_NATIVE_LONG;
70 else if( (
int)H5Tget_size( H5T_NATIVE_LLONG ) ==
size )
71 return sgn == H5T_SGN_NONE ? H5T_NATIVE_ULLONG : H5T_NATIVE_LLONG;
77 tmp_id = H5Tget_super( input_type );
80 mhdf_setFail( status,
"Internal error calling H5Tget_super." );
97 mhdf_setFail( status,
"Only atomic types are supported." );
101 mhdf_setFail( status,
"Internal error calling H5Tget_class. Bad handle?" );
108 hid_t group_id, tag_id;
115 if( NULL != id_type ) *id_type = file_ptr->
id_type;
118 if( NULL == path )
return -1;
120 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
132 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
133 tag_id = H5Gopen2( group_id, path, H5P_DEFAULT );
135 tag_id = H5Gopen( group_id, path );
137 H5Gclose( group_id );
141 mhdf_setFail( status,
"Failed to open tag data for tag \"%s\".", tag_name );
151 hid_t group_id, tag_id, type_id;
153 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
164 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
165 tag_id = H5Gopen2( group_id, tag_path, H5P_DEFAULT );
167 tag_id = H5Gopen( group_id, tag_path );
169 H5Gclose( group_id );
172 mhdf_setFail( status,
"Failed to open group for tag \"%s\".", tag_path );
176 #if defined( H5Topen_vers ) && H5Topen_vers > 1
184 mhdf_setFail( status,
"Failed to open type data for tag \"%s\".", tag_path );
200 const char* attrib_name,
208 if( value_size == 1 )
209 write_type = type_id;
210 else if( H5Tget_class( type_id ) == H5T_OPAQUE )
212 write_type = H5Tcreate( H5T_OPAQUE, value_size );
216 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
217 write_type = H5Tarray_create2( type_id, 1, &value_size );
219 write_type = H5Tarray_create( type_id, 1, &value_size, 0 );
225 mhdf_setFail( status,
"Error constructing type object for tag mesh/default value" );
230 if( write_type != type_id ) H5Tclose( write_type );
236 const char* tag_name,
240 const void* default_value,
241 int default_value_size_in,
242 const void* global_value,
243 int global_value_size_in,
248 hid_t temp_id, group_id, tag_id;
253 int one = 1, var_len = 0;
254 hsize_t default_value_size = default_value_size_in;
255 hsize_t global_value_size = global_value_size_in;
256 int close_base_type = 0;
268 if( !tag_name || !*tag_name )
276 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
292 H5Gclose( group_id );
298 #if defined( H5Gcreate_vers ) && H5Gcreate_vers > 1
299 tag_id = H5Gcreate2( group_id, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
301 tag_id = H5Gcreate( group_id, path, 3 );
305 mhdf_setFail( status,
"H5Gcreate( \"%s\" ) failed.", path );
307 H5Gclose( group_id );
313 rval = H5Gset_comment( group_id, path, tag_name );
314 H5Gclose( group_id );
318 mhdf_setFail( status,
"H5Gset_comment failed for tag \"%s\"", tag_name );
334 hdf_type = H5Tcopy( hdf_type );
344 hdf_type = H5Tcreate( H5T_OPAQUE, abs(
size ) );
345 H5Tset_tag( hdf_type,
"tag_data" );
356 hdf_type = H5Tcopy( H5T_NATIVE_B8 );
357 else if(
size <= 16 )
358 hdf_type = H5Tcopy( H5T_NATIVE_B16 );
359 else if(
size <= 32 )
360 hdf_type = H5Tcopy( H5T_NATIVE_B32 );
361 else if(
size <= 64 )
362 hdf_type = H5Tcopy( H5T_NATIVE_B64 );
365 mhdf_setFail( status,
"Cannot create a bit tag larger than 64-bits. %d bits requested.\n",
370 if( 0 > H5Tset_precision( hdf_type,
size ) )
378 arr_len = abs(
size );
379 hdf_type = H5Tcopy( H5T_NATIVE_ULONG );
383 arr_len = abs(
size );
384 hdf_type = H5Tcopy( H5T_NATIVE_UCHAR );
388 arr_len = abs(
size );
389 hdf_type = H5Tcopy( H5T_NATIVE_INT );
393 arr_len = abs(
size );
394 hdf_type = H5Tcopy( H5T_NATIVE_DOUBLE );
401 mhdf_setFail( status,
"Failed to create tag type object." );
406 if( hdf_base_type && H5Tget_class( hdf_type ) != H5Tget_class( hdf_base_type ) )
408 mhdf_setFail( status,
"Invalid base type for tag default/global data" );
413 if(
size < -1 || !arr_len )
415 mhdf_setFail( status,
"Invalid 'size' parameter passed to mhdf_createTag (%d)", (
int)
size );
419 else if(
size == -1 )
428 else if( arr_len > 1 )
430 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
431 temp_id = H5Tarray_create2( hdf_type, 1, &arr_len );
433 temp_id = H5Tarray_create( hdf_type, 1, &arr_len, NULL );
435 H5Tclose( hdf_type );
438 mhdf_setFail( status,
"Failed to create tag type object." );
446 if( H5Tequal( hdf_base_type, hdf_type ) > 0 )
448 hdf_base_type = hdf_type;
452 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
453 temp_id = H5Tarray_create2( hdf_base_type, 1, &arr_len );
455 temp_id = H5Tarray_create( hdf_base_type, 1, &arr_len, NULL );
459 mhdf_setFail( status,
"Failed to create tag type object." );
461 H5Tclose( hdf_type );
464 hdf_base_type = temp_id;
470 if( !hdf_base_type ) hdf_base_type = hdf_type;
474 #if defined( H5Tcommit_vers ) && H5Tcommit_vers > 1
475 rval = H5Tcommit2( tag_id,
TAG_TYPE_NAME, hdf_type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
481 mhdf_setFail( status,
"H5Tcommit failed for tag \"%s\"", tag_name );
482 if( close_base_type ) H5Tclose( hdf_base_type );
483 H5Tclose( hdf_type );
494 if( close_base_type ) H5Tclose( hdf_base_type );
496 H5Tclose( hdf_type );
506 var_len ? default_value_size : 1, status );
509 if( close_base_type ) H5Tclose( hdf_base_type );
511 H5Tclose( hdf_type );
521 var_len ? global_value_size : 1, status );
524 if( close_base_type ) H5Tclose( hdf_base_type );
526 H5Tclose( hdf_type );
531 if( close_base_type ) H5Tclose( hdf_base_type );
532 H5Tclose( hdf_type );
549 if( !tag_name || !*tag_name )
571 const char* tag_name,
575 const void* default_value,
576 const void* global_value,
583 tag_id =
create_tag_common( file_handle, tag_name, tag_type,
size, storage, default_value, 1, global_value, 1,
584 hdf_type, hdf_base_type, status );
585 if( tag_id >= 0 ) H5Gclose( tag_id );
590 const char* tag_name,
593 const void* default_value,
594 int default_value_length,
595 const void* global_value,
596 int global_value_length,
605 tag_id =
create_tag_common( file_handle, tag_name, tag_type, -1, storage, default_value, default_value_length,
606 global_value, global_value_length, hdf_type, hdf_base_type, status );
629 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
642 if( H5Gget_num_objs( group_id, &result ) < 0 )
644 mhdf_setFail( status,
"Internal failure calling H5Gget_num_objs." );
645 H5Gclose( group_id );
649 H5Gclose( group_id );
672 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
685 if( H5Gget_num_objs( group_id, &count ) < 0 )
687 mhdf_setFail( status,
"Internal failure calling H5Gget_num_objs." );
688 H5Gclose( group_id );
694 *num_names_out = (int)count;
697 H5Gclose( group_id );
704 result = (
char**)
mhdf_malloc(
sizeof(
char* ) * count, status );
707 H5Gclose( group_id );
713 for( idx = 0; idx < count; ++idx )
715 size = H5Gget_objname_by_idx( group_id, idx, NULL, 0 );
718 while( ( --idx ) > 0 )
721 H5Gclose( group_id );
722 mhdf_setFail( status,
"Internal failure calling H5Gget_objname_by_idx." );
726 H5Gget_objname_by_idx( group_id, idx, name,
size + 1 );
729 mhdf_setFail( status,
"Invalid character string in internal file path: \"%s\"\n", name );
735 H5Gclose( group_id );
745 hsize_t dims[H5S_MAX_RANK];
746 int perm[H5S_MAX_RANK];
748 type_id = H5Aget_type( attrib_id );
749 switch( H5Tget_class( type_id ) )
755 dims[0] = H5Tget_size( type_id );
758 #if defined( H5Tget_array_dims_vers ) && H5Tget_array_dims_vers > 1
760 rank = H5Tget_array_dims2( type_id, dims );
762 rank = H5Tget_array_dims( type_id, dims, perm );
798 attrib_id = H5Aopen_name( file, path );
799 if( attrib_id < 0 )
return -1;
802 H5Aclose( attrib_id );
807 const char* tag_name,
810 int* tstt_storage_out,
811 int* have_default_out,
812 int* have_global_out,
813 int* have_sparse_out,
816 hid_t tag_id, type_id, super_id;
817 int i, rval, is_handle;
818 hsize_t
size, sup_size;
821 hsize_t dims[H5S_MAX_RANK];
822 int perm[H5S_MAX_RANK];
823 H5T_class_t class_tmp;
828 if( NULL == tag_name || NULL == class_out || NULL == size_out || NULL == tstt_storage_out ||
829 NULL == have_default_out || NULL == have_global_out || NULL == have_sparse_out )
836 tag_id =
get_tag( file_handle, tag_name, NULL, status );
837 if( tag_id < 0 )
return;
846 *have_sparse_out = rval ? 1 : 0;
855 var_data = rval ? 1 : 0;
865 *have_default_out = 0;
867 *have_default_out = 1;
872 if( *have_default_out < 0 )
874 mhdf_setFail( status,
"Error checking length of default value for tag: %s\n", tag_name );
888 *have_global_out = 0;
890 *have_global_out = 1;
895 if( *have_global_out < 0 )
897 mhdf_setFail( status,
"Error checking length of global value for tag: %s\n", tag_name );
921 #if defined( H5Topen_vers ) && H5Topen_vers > 1
929 mhdf_setFail( status,
"Failed to get type object for tag \"%s\".", tag_name );
933 class_tmp = H5Tget_class( type_id );
942 size = H5Tget_size( type_id );
965 *size_out = H5Tget_precision( type_id );
983 #if defined( H5Tget_array_dims_vers ) && H5Tget_array_dims_vers > 1
985 rank = H5Tget_array_dims2( type_id, dims );
987 rank = H5Tget_array_dims( type_id, dims, perm );
996 for( i = 1; i < rank; ++i )
999 super_id = H5Tget_super( type_id );
1004 H5Tclose( type_id );
1008 class_tmp = H5Tget_class( super_id );
1013 H5Tclose( type_id );
1014 H5Tclose( super_id );
1018 sup_size = H5Tget_size( super_id );
1019 H5Tclose( super_id );
1024 H5Tclose( type_id );
1032 *size_out = dims[0];
1037 *size_out = dims[0];
1048 H5Tclose( type_id );
1055 mhdf_setFail( status,
"Non-integer tag marked as handle type." );
1065 mhdf_setFail( status,
"Invalid or unexpected variable-length tag data" );
1076 const char* attrib_name,
1084 hid_t read_type = type_id;
1091 else if( 0 == rval )
1106 mhdf_setFail( status,
"Failed to read length of default/mesh value for tag" );
1113 read_type = H5Tcreate( H5T_OPAQUE, len );
1116 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
1117 read_type = H5Tarray_create2( type_id, 1, &len );
1119 read_type = H5Tarray_create( type_id, 1, &len, 0 );
1124 mhdf_setFail( status,
"Failed to read mesh/default value for tag" );
1130 if( is_var_len ) H5Tclose( read_type );
1136 const char* tag_name,
1137 hid_t output_data_type,
1138 void* default_value,
1148 if( NULL == tag_name || !*tag_name )
1155 tag_id =
get_tag( file_handle, tag_name, NULL, status );
1156 if( tag_id < 0 )
return;
1165 var_data = rval ? 1 : 0;
1191 hid_t elem_id, group_id;
1201 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1206 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open node group." );
1210 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1215 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open set group." );
1221 if( elem_id < 0 )
return -1;
1226 H5Gclose( elem_id );
1229 else if( rval == 0 )
1231 H5Gclose( elem_id );
1236 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1241 H5Gclose( elem_id );
1244 mhdf_setFail( status,
"Could not open tag subgroup." );
1251 H5Gclose( group_id );
1256 H5Gclose( group_id );
1269 const char* tag_name,
1270 const char* type_handle,
1275 hid_t elem_id, data_id, type_id;
1277 size_t name_len, path_len, dir_len;
1286 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1291 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open node group." );
1295 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1300 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open set group." );
1306 if( elem_id < 0 )
return -1;
1310 path_len = dir_len + name_len + 1;
1314 H5Gclose( elem_id );
1320 type_id =
get_tag_type( file_ptr, path + dir_len, status );
1323 H5Gclose( elem_id );
1327 size = (hsize_t)num_values;
1330 H5Gclose( elem_id );
1331 H5Tclose( type_id );
1340 const char* tag_name,
1341 const char* type_handle,
1342 long* num_values_out,
1346 hid_t elem_id, data_id;
1348 size_t name_len, path_len, dir_len;
1357 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1362 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open node group." );
1366 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
1371 if( elem_id < 0 )
mhdf_setFail( status,
"Could not open set group." );
1377 if( elem_id < 0 )
return -1;
1381 path_len = dir_len + name_len + 1;
1385 H5Gclose( elem_id );
1393 H5Gclose( elem_id );
1394 *num_values_out = (long)
size;
1403 const char* tag_name,
1405 hid_t handles_out[2],
1408 hid_t tag_id, index_id, data_id, type_id, id_type;
1409 hsize_t count = (hsize_t)num_values;
1412 tag_id =
get_tag( file_handle, tag_name, &id_type, status );
1413 if( tag_id < 0 )
return;
1415 #if defined( H5Topen_vers ) && H5Topen_vers > 1
1423 mhdf_setFail( status,
"Failed to get type object for tag \"%s\".", tag_name );
1431 H5Tclose( type_id );
1436 H5Tclose( type_id );
1440 H5Dclose( index_id );
1444 handles_out[0] = index_id;
1445 handles_out[1] = data_id;
1451 const char* tag_name,
1454 hid_t handles_out[3],
1457 hid_t tag_id, index_id, data_id, type_id, offset_id, id_type;
1458 hsize_t count = (hsize_t)num_entities;
1461 tag_id =
get_tag( file_handle, tag_name, &id_type, status );
1462 if( tag_id < 0 )
return;
1464 #if defined( H5Topen_vers ) && H5Topen_vers > 1
1472 mhdf_setFail( status,
"Failed to get type object for tag \"%s\".", tag_name );
1480 H5Tclose( type_id );
1487 H5Dclose( offset_id );
1489 H5Tclose( type_id );
1493 count = (hsize_t)num_values;
1495 H5Tclose( type_id );
1499 H5Dclose( offset_id );
1500 H5Dclose( index_id );
1504 handles_out[0] = index_id;
1505 handles_out[1] = data_id;
1506 handles_out[2] = offset_id;
1512 const char* tag_name,
1513 long* num_entity_out,
1514 long* num_values_out,
1515 hid_t handles_out[3],
1518 hid_t tag_id, index_id, data_id, offset_id = -1;
1519 hsize_t num_ent, data_size, num_data;
1524 tag_id =
get_tag( file_handle, tag_name, NULL, status );
1525 if( tag_id < 0 )
return;
1538 H5Dclose( index_id );
1547 H5Dclose( index_id );
1548 H5Dclose( data_id );
1559 H5Dclose( index_id );
1560 H5Dclose( data_id );
1567 num_data = data_size;
1571 if( num_ent != num_data )
1573 mhdf_setFail( status,
"Data length mismatch for sparse tag data -- invalid file." );
1574 if( offset_id >= 0 ) H5Dclose( offset_id );
1575 H5Dclose( index_id );
1576 H5Dclose( data_id );
1579 *num_entity_out = (long)num_ent;
1580 if( num_values_out ) *num_values_out = (long)data_size;
1582 handles_out[0] = index_id;
1583 handles_out[1] = data_id;
1584 if( offset_id >= 0 ) handles_out[2] = offset_id;
1593 const void* id_list,
1597 mhdf_write_data( table_id, offset, count, int_type, id_list, H5P_DEFAULT, status );
1604 const void* id_list,
1609 mhdf_write_data( table_id, offset, count, int_type, id_list, io_prop, status );
1617 const void* tag_data,
1627 const void* tag_data,
1632 mhdf_write_data( table_id, offset, count, tag_type, tag_data, io_prop, status );
1640 const void* indices,
1644 mhdf_write_data( table_id, offset, count, int_type, indices, H5P_DEFAULT, status );
1651 const void* indices,
1656 mhdf_write_data( table_id, offset, count, int_type, indices, io_prop, status );
1668 mhdf_read_data( table_id, offset, count, int_type, id_list, H5P_DEFAULT, status );
1680 mhdf_read_data( table_id, offset, count, int_type, id_list, io_prop, status );
1697 mhdf_read_data( table_id, offset, count, tag_type, tag_data, io_prop, status );
1709 mhdf_read_data( table_id, offset, count, int_type, indices, H5P_DEFAULT, status );
1721 mhdf_read_data( table_id, offset, count, int_type, indices, io_prop, status );