Skip to content

Commit

Permalink
Update subset check; fix non-cmpd conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Apr 10, 2024
1 parent 712d2b2 commit 2e83194
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/rest_vol_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ RV_dataset_write(size_t count, void *dset[], hid_t mem_type_id[], hid_t _mem_spa
dest_dtype_size = dense_dtype_size;
}
else {
dest_dtype = transfer_info[i].mem_type_id;
dest_dtype_size = mem_type_size;
dest_dtype = transfer_info[i].file_type_id;
dest_dtype_size = file_type_size;
}

/* Initialize type conversion */
Expand Down
134 changes: 126 additions & 8 deletions src/rest_vol_datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2616,10 +2616,11 @@ RV_get_cmpd_subset_type(hid_t src_type_id, hid_t dst_type_id, RV_subset_t *subse
{
herr_t ret_value = SUCCEED;
H5T_class_t dst_type_class = H5T_NO_CLASS, src_type_class = H5T_NO_CLASS;
char *src_member_name = NULL, *dst_member_name = NULL;
size_t src_member_offset = 0, dst_member_offset = 0;
hid_t src_member_type = H5I_INVALID_HID, dst_member_type = H5I_INVALID_HID;
int dst_nmembs = 0, src_nmembs = 0;
htri_t types_same = false;
bool match_for_src_member = false;
hbool_t member_match = FALSE;

if (H5T_NO_CLASS == (src_type_class = H5Tget_class(src_type_id)))
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "source datatype is invalid");
Expand All @@ -2638,20 +2639,137 @@ RV_get_cmpd_subset_type(hid_t src_type_id, hid_t dst_type_id, RV_subset_t *subse
if ((src_nmembs = H5Tget_nmembers(src_type_id)) < 0)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get nmembers of source datatype");

/* The library just compares the number of members to determine if two
* compounds are subsets, so that should suffice here as well. */
/* Determine subset status by comparing members */
if (src_nmembs < dst_nmembs) {
for (unsigned src_idx = 0; src_idx < src_nmembs; src_idx++) {
member_match = FALSE;

if (src_nmembs > dst_nmembs) {
*subset = H5T_SUBSET_DST;
if ((src_member_type = H5Tget_member_type(src_type_id, src_idx)) == H5I_INVALID_HID)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get memory datatype member type");

if ((src_member_name = H5Tget_member_name(src_type_id, src_idx)) == NULL)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get memory datatype member name");

if ((src_member_offset = H5Tget_member_offset(src_type_id, src_idx)) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get memory datatype member offset");

/* Search for match in dst compound */
for (unsigned dst_idx = 0; dst_idx < dst_nmembs; dst_idx++) {
if ((dst_member_type = H5Tget_member_type(dst_type_id, dst_idx)) == H5I_INVALID_HID)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member type");

if ((dst_member_name = H5Tget_member_name(dst_type_id, dst_idx)) == NULL)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member name");

if ((dst_member_offset = H5Tget_member_offset(dst_type_id, dst_idx)) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member offset");

/* Compare member names and offsets */
if (!strcmp(src_member_name, dst_member_name) && (src_member_offset == dst_member_offset)) {
member_match = TRUE;
}

/* Clean up */
H5free_memory(dst_member_name);
dst_member_name = NULL;

if (H5Tclose(dst_member_type) < 0)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL,
"can't close destination datatype member type");
dst_member_type = H5T_NO_CLASS;

/* If no match exists for this source member, the src compound is not a subset */
if ((dst_idx == dst_nmembs - 1) && !member_match) {
*subset = H5T_SUBSET_FALSE;
FUNC_GOTO_DONE(SUCCEED);
}
}

/* Clean up */
H5free_memory(src_member_name);
src_member_name = NULL;

if (H5Tclose(src_member_type) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close source datatype member");
src_member_type = H5T_NO_CLASS;

/* If a match was found for every member, src is a subset of dst */
*subset = H5T_SUBSET_SRC;
}
}
else if (src_nmembs < dst_nmembs) {
*subset = H5T_SUBSET_SRC;
else if (dst_nmembs < src_nmembs) {
for (unsigned dst_idx = 0; dst_idx < dst_nmembs; dst_idx++) {
member_match = FALSE;
if ((dst_member_type = H5Tget_member_type(dst_type_id, dst_idx)) == H5I_INVALID_HID)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member type");

if ((dst_member_name = H5Tget_member_name(dst_type_id, dst_idx)) == NULL)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member name");

if ((dst_member_offset = H5Tget_member_offset(dst_type_id, dst_idx)) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get destination datatype member offset");

/* Search for match in src compound */
for (unsigned src_idx = 0; src_idx < src_nmembs; src_idx++) {
if ((src_member_type = H5Tget_member_type(src_type_id, src_idx)) == H5I_INVALID_HID)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get memory datatype member type");

if ((src_member_name = H5Tget_member_name(src_type_id, src_idx)) == NULL)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get memory datatype member name");

if ((src_member_offset = H5Tget_member_offset(src_type_id, src_idx)) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL,
"can't get memory datatype member offset");

/* Compare member names and offsets */
if (!strcmp(dst_member_name, src_member_name) && (dst_member_offset == src_member_offset)) {
member_match = TRUE;
}
/* Clean up */
H5free_memory(src_member_name);
src_member_name = NULL;

if (H5Tclose(src_member_type) < 0)
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL,
"can't close memory datatype member type");
src_member_type = H5T_NO_CLASS;

/* If no match exists for this destination member, the dst compound is not a subset */
if ((src_idx == src_nmembs - 1) && !member_match) {
*subset = H5T_SUBSET_FALSE;
FUNC_GOTO_DONE(SUCCEED);
}
}

/* Clean up */
H5free_memory(dst_member_name);
dst_member_name = NULL;

if (H5Tclose(dst_member_type) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL,
"can't close destination datatype member");
dst_member_type = H5T_NO_CLASS;

/* If a match was found for every member, dst is a subset of source */
*subset = H5T_SUBSET_DST;
}
}
else {
*subset = H5T_SUBSET_FALSE;
}

done:
if (src_member_name)
H5free_memory(src_member_name);
if (dst_member_name)
H5free_memory(dst_member_name);

if (src_member_type > 0)
if (H5Tclose(src_member_type) < 0)
FUNC_DONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close source datatype member");
Expand Down

0 comments on commit 2e83194

Please sign in to comment.