diff options
Diffstat (limited to 'tools/test/misc/talign.c')
-rw-r--r-- | tools/test/misc/talign.c | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/tools/test/misc/talign.c b/tools/test/misc/talign.c index c69d1f7..2cf73ae 100644 --- a/tools/test/misc/talign.c +++ b/tools/test/misc/talign.c @@ -20,7 +20,7 @@ #include "H5private.h" #include "h5tools.h" -const char *fname = "talign.h5"; +const char *fname = "talign.h5"; const char *setname = "align"; /* @@ -30,26 +30,27 @@ const char *setname = "align"; * another per construction) */ -int main(void) +int +main(void) { - hid_t fil=H5I_INVALID_HID, spc=H5I_INVALID_HID, set=H5I_INVALID_HID; - hid_t cs6=H5I_INVALID_HID, cmp=H5I_INVALID_HID, fix=H5I_INVALID_HID; - hid_t cmp1=H5I_INVALID_HID, cmp2=H5I_INVALID_HID, cmp3=H5I_INVALID_HID; - hid_t plist=H5I_INVALID_HID; - hid_t array_dt=H5I_INVALID_HID; + hid_t fil = H5I_INVALID_HID, spc = H5I_INVALID_HID, set = H5I_INVALID_HID; + hid_t cs6 = H5I_INVALID_HID, cmp = H5I_INVALID_HID, fix = H5I_INVALID_HID; + hid_t cmp1 = H5I_INVALID_HID, cmp2 = H5I_INVALID_HID, cmp3 = H5I_INVALID_HID; + hid_t plist = H5I_INVALID_HID; + hid_t array_dt = H5I_INVALID_HID; hsize_t dim[2]; hsize_t cdim[4]; - char string5[5]; - float fok[2] = {1234.0f, 2341.0f}; - float fnok[2] = {5678.0f, 6785.0f}; - float *fptr = NULL; + char string5[5]; + float fok[2] = {1234.0f, 2341.0f}; + float fnok[2] = {5678.0f, 6785.0f}; + float *fptr = NULL; char *data = NULL; - int result = 0; - herr_t error = 1; + int result = 0; + herr_t error = 1; HDprintf("%-70s", "Testing alignment in compound datatypes"); @@ -62,9 +63,8 @@ int main(void) return 1; } - H5E_BEGIN_TRY { - (void)H5Ldelete(fil, setname, H5P_DEFAULT); - } H5E_END_TRY; + H5E_BEGIN_TRY { (void)H5Ldelete(fil, setname, H5P_DEFAULT); } + H5E_END_TRY; cs6 = H5Tcopy(H5T_C_S1); H5Tset_size(cs6, sizeof(string5)); @@ -73,20 +73,20 @@ int main(void) cmp = H5Tcreate(H5T_COMPOUND, sizeof(fok) + sizeof(string5) + sizeof(fnok)); H5Tinsert(cmp, "Awkward length", 0, cs6); - cdim[0] = sizeof(fok) / sizeof(float); + cdim[0] = sizeof(fok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp, "Ok", sizeof(string5), array_dt); H5Tclose(array_dt); - cdim[0] = sizeof(fnok) / sizeof(float); + cdim[0] = sizeof(fnok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt); H5Tclose(array_dt); - fix = H5Tget_native_type(cmp, H5T_DIR_DEFAULT); + fix = H5Tget_native_type(cmp, H5T_DIR_DEFAULT); cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok)); - cdim[0] = sizeof(fok) / sizeof(float); + cdim[0] = sizeof(fok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp1, "Ok", 0, array_dt); H5Tclose(array_dt); @@ -96,13 +96,13 @@ int main(void) cmp3 = H5Tcreate(H5T_COMPOUND, sizeof(fnok)); - cdim[0] = sizeof(fnok) / sizeof(float); + cdim[0] = sizeof(fnok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp3, "Not Ok", 0, array_dt); H5Tclose(array_dt); plist = H5Pcreate(H5P_DATASET_XFER); - if((error = H5Pset_preserve(plist, 1)) < 0) + if ((error = H5Pset_preserve(plist, 1)) < 0) goto out; /* @@ -110,8 +110,8 @@ int main(void) * in turn so that we are avoid alignment issues at this point */ dim[0] = 1; - spc = H5Screate_simple(1, dim, NULL); - set = H5Dcreate2(fil, setname, cmp, spc, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + spc = H5Screate_simple(1, dim, NULL); + set = H5Dcreate2(fil, setname, cmp, spc, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(set, cmp1, spc, H5S_ALL, plist, fok); H5Dwrite(set, cmp2, spc, H5S_ALL, plist, string5); @@ -122,7 +122,7 @@ int main(void) /* Now open the set, and read it back in */ data = (char *)HDmalloc(H5Tget_size(fix)); - if(!data) { + if (!data) { HDperror("malloc() failed"); HDabort(); } @@ -134,61 +134,56 @@ int main(void) H5Dclose(set); out: - if(error < 0) { + if (error < 0) { result = 1; HDputs("*FAILED - HDF5 library error*"); - } else if(!(H5_FLT_ABS_EQUAL(fok[0], fptr[0])) - || !(H5_FLT_ABS_EQUAL(fok[1], fptr[1])) - || !(H5_FLT_ABS_EQUAL(fnok[0], fptr[2])) - || !(H5_FLT_ABS_EQUAL(fnok[1], fptr[3]))) { + } + else if (!(H5_FLT_ABS_EQUAL(fok[0], fptr[0])) || !(H5_FLT_ABS_EQUAL(fok[1], fptr[1])) || + !(H5_FLT_ABS_EQUAL(fnok[0], fptr[2])) || !(H5_FLT_ABS_EQUAL(fnok[1], fptr[3]))) { char *mname; result = 1; - mname = H5Tget_member_name(fix, 0); - HDprintf("%14s (%2d) %6s = %s\n", - mname ? mname : "(null)", (int)H5Tget_member_offset(fix,0), - string5, (char *)(data + H5Tget_member_offset(fix, 0))); - if(mname) + mname = H5Tget_member_name(fix, 0); + HDprintf("%14s (%2d) %6s = %s\n", mname ? mname : "(null)", (int)H5Tget_member_offset(fix, 0), + string5, (char *)(data + H5Tget_member_offset(fix, 0))); + if (mname) H5free_memory(mname); - fptr = (float *)((void *)(data + H5Tget_member_offset(fix, 1))); + fptr = (float *)((void *)(data + H5Tget_member_offset(fix, 1))); mname = H5Tget_member_name(fix, 1); HDprintf("Data comparison:\n" - "%14s (%2d) %6f = %f\n" - " %6f = %f\n", - mname ? mname : "(null)", (int)H5Tget_member_offset(fix,1), - (double)fok[0], (double)fptr[0], - (double)fok[1], (double)fptr[1]); - if(mname) + "%14s (%2d) %6f = %f\n" + " %6f = %f\n", + mname ? mname : "(null)", (int)H5Tget_member_offset(fix, 1), (double)fok[0], (double)fptr[0], + (double)fok[1], (double)fptr[1]); + if (mname) H5free_memory(mname); - fptr = (float *)((void *)(data + H5Tget_member_offset(fix, 2))); + fptr = (float *)((void *)(data + H5Tget_member_offset(fix, 2))); mname = H5Tget_member_name(fix, 2); HDprintf("%14s (%2d) %6f = %f\n" - " %6f = %6f\n", - mname ? mname : "(null)", (int)H5Tget_member_offset(fix,2), - (double)fnok[0], (double)fptr[0], - (double)fnok[1], (double)fptr[1]); - if(mname) + " %6f = %6f\n", + mname ? mname : "(null)", (int)H5Tget_member_offset(fix, 2), (double)fnok[0], + (double)fptr[0], (double)fnok[1], (double)fptr[1]); + if (mname) H5free_memory(mname); fptr = (float *)((void *)(data + H5Tget_member_offset(fix, 1))); HDprintf("\n" - "Short circuit\n" - " %6f = %f\n" - " %6f = %f\n" - " %6f = %f\n" - " %6f = %f\n", - (double)fok[0], (double)fptr[0], - (double)fok[1], (double)fptr[1], - (double)fnok[0], (double)fptr[2], - (double)fnok[1], (double)fptr[3]); + "Short circuit\n" + " %6f = %f\n" + " %6f = %f\n" + " %6f = %f\n" + " %6f = %f\n", + (double)fok[0], (double)fptr[0], (double)fok[1], (double)fptr[1], (double)fnok[0], + (double)fptr[2], (double)fnok[1], (double)fptr[3]); HDputs("*FAILED - compound type alignmnent problem*"); - } else { + } + else { HDputs(" PASSED"); } - if(data) + if (data) HDfree(data); H5Sclose(spc); H5Tclose(cs6); @@ -203,4 +198,3 @@ out: HDfflush(stdout); return result; } - |