diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-05-12 20:20:00 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-05-12 20:20:00 (GMT) |
commit | 20c6bdda65bb2e069701c759057d4535e53d4898 (patch) | |
tree | a0d786c1e8a4c52b716c5974599d57a1095b0350 | |
parent | f02082b56859a96ae591fe06c82e619dff4c35c2 (diff) | |
download | hdf5-20c6bdda65bb2e069701c759057d4535e53d4898.zip hdf5-20c6bdda65bb2e069701c759057d4535e53d4898.tar.gz hdf5-20c6bdda65bb2e069701c759057d4535e53d4898.tar.bz2 |
[svn-r14978] Support for external links follow up. The format is to print the target object as part of TARGETPATH, noted with some extra indentation
The previous printing of
LINKCLASS 64
was removed
HDF5 "textlinksrc.h5" {
GROUP "/" {
EXTERNAL_LINK "ext_link1" {
TARGETFILE "textlinktar.h5"
TARGETPATH "dset"
DATASET "dset" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 6 ) / ( 6 ) }
DATA {
(0): 1, 2, 3, 4, 5, 6
}
}
}
}
}
There is no script test for this behavior so far, because test script uses complete paths that vary from test to test, making not possible to define a valid TARGETFILE in the file
tested: windows, linux, solaris
-rw-r--r-- | tools/h5dump/h5dump.c | 162 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 69 | ||||
-rw-r--r-- | tools/testfiles/tall-1.ddl | 1 | ||||
-rw-r--r-- | tools/testfiles/tall-2A.ddl | 1 | ||||
-rw-r--r-- | tools/testfiles/tall-2B.ddl | 1 |
5 files changed, 194 insertions, 40 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 9802ad0..4c853f3 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -107,6 +107,8 @@ static void init_prefix(char **prfx, size_t prfx_len); static void add_prefix(char **prfx, size_t *prfx_len, const char *name); /* callback function used by H5Literate() */ static herr_t dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void *op_data); +static int dump_extlink(const char *filename, const char *targname); + static h5tool_format_t dataformat = { @@ -359,7 +361,7 @@ static char *xml_escape_the_name(const char *); /* a structure for handling the order command-line parameters come in */ struct handler_t { - void (*func)(hid_t, char *, void *); + void (*func)(hid_t, const char *, void *, int); char *obj; struct subset_t *subset_info; }; @@ -1379,6 +1381,9 @@ dump_selected_attr(hid_t loc_id, const char *name) * RMcG, November 2000 * Added XML support. Also, optionally checks the op_data argument * + * PVN, May 2008 + * Dump external links + * *------------------------------------------------------------------------- */ static herr_t @@ -1663,11 +1668,14 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void UNUSED else { if(!doxml) { indentation(indent + COL); - printf("LINKCLASS %d\n", linfo->type); - indentation(indent + COL); printf("TARGETFILE \"%s\"\n", filename); indentation(indent + COL); printf("TARGETPATH \"%s\"\n", targname); + + /* dump the external link */ + dump_extlink(filename,targname); + + } /* end if */ /* XML */ else { @@ -3117,10 +3125,13 @@ set_sort_order(const char *form) * * Modifications: * + * PVN, May 2008 + * add an extra parameter PE, to allow printing/not printing of error messages + * *------------------------------------------------------------------------- */ static void -handle_attributes(hid_t fid, char *attr, void UNUSED * data) +handle_attributes(hid_t fid, const char *attr, void UNUSED * data, int pe) { dump_selected_attr(fid, attr); } @@ -3262,25 +3273,34 @@ parse_subset_params(char *dset) * * Modifications: * Pedro Vicente, Tuesday, January 15, 2008 - * check for block overlap + * check for block overlap\ + * + * Pedro Vicente, May 8, 2008 + * added a flag PE that prints/not prints error messages + * added for cases of external links not found, to avoid printing of + * objects not found, since external links are dumped on a trial error basis * *------------------------------------------------------------------------- */ static void -handle_datasets(hid_t fid, char *dset, void *data) +handle_datasets(hid_t fid, const char *dset, void *data, int pe) { H5O_info_t oinfo; hid_t dsetid; struct subset_t *sset = (struct subset_t *)data; - if((dsetid = H5Dopen2(fid, dset, H5P_DEFAULT)) < 0) { - begin_obj(dump_header_format->datasetbegin, dset, - dump_header_format->datasetblockbegin); - indentation(COL); - error_msg(progname, "unable to open dataset \"%s\"\n", dset); - end_obj(dump_header_format->datasetend, + if((dsetid = H5Dopen2(fid, dset, H5P_DEFAULT)) < 0) + { + if (pe) + { + begin_obj(dump_header_format->datasetbegin, dset, + dump_header_format->datasetblockbegin); + indentation(COL); + error_msg(progname, "unable to open dataset \"%s\"\n", dset); + end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend); - d_status = EXIT_FAILURE; + d_status = EXIT_FAILURE; + } return; } /* end if */ @@ -3410,21 +3430,29 @@ handle_datasets(hid_t fid, char *dset, void *data) * Modifications: Pedro Vicente, September 26, 2007 * handle creation order * + * Pedro Vicente, May 8, 2008 + * added a flag PE that prints/not prints error messages + * added for cases of external links not found, to avoid printing of + * objects not found, since external links are dumped on a trial error basis + * *------------------------------------------------------------------------- */ static void -handle_groups(hid_t fid, char *group, void UNUSED * data) +handle_groups(hid_t fid, const char *group, void UNUSED * data, int pe) { hid_t gid; if((gid = H5Gopen2(fid, group, H5P_DEFAULT)) < 0) { - begin_obj(dump_header_format->groupbegin, group, dump_header_format->groupblockbegin); - indentation(COL); - error_msg(progname, "unable to open group \"%s\"\n", group); - end_obj(dump_header_format->groupend, dump_header_format->groupblockend); - d_status = EXIT_FAILURE; + if ( pe ) + { + begin_obj(dump_header_format->groupbegin, group, dump_header_format->groupblockbegin); + indentation(COL); + error_msg(progname, "unable to open group \"%s\"\n", group); + end_obj(dump_header_format->groupend, dump_header_format->groupblockend); + d_status = EXIT_FAILURE; + } } else { @@ -3460,7 +3488,7 @@ handle_groups(hid_t fid, char *group, void UNUSED * data) *------------------------------------------------------------------------- */ static void -handle_links(hid_t fid, char *links, void UNUSED * data) +handle_links(hid_t fid, const char *links, void UNUSED * data, int pe) { H5L_info_t linfo; @@ -3546,21 +3574,29 @@ handle_links(hid_t fid, char *links, void UNUSED * data) * * Modifications: * + * Pedro Vicente, May 8, 2008 + * added a flag PE that prints/not prints error messages + * added for cases of external links not found, to avoid printing of + * objects not found, since external links are dumped on a trial error basis + * *------------------------------------------------------------------------- */ static void -handle_datatypes(hid_t fid, char *type, void UNUSED * data) +handle_datatypes(hid_t fid, const char *type, void UNUSED * data, int pe) { hid_t type_id; - if((type_id = H5Topen2(fid, type, H5P_DEFAULT)) < 0) { + if((type_id = H5Topen2(fid, type, H5P_DEFAULT)) < 0) + { /* check if type is unamed datatype */ unsigned idx = 0; - while(idx < type_table->nobjs ) { + while(idx < type_table->nobjs ) + { char name[128]; - if(!type_table->objs[idx].recorded) { + if(!type_table->objs[idx].recorded) + { /* unamed datatype */ sprintf(name, "/#"H5_PRINTF_HADDR_FMT, type_table->objs[idx].objno); @@ -3571,23 +3607,31 @@ handle_datatypes(hid_t fid, char *type, void UNUSED * data) idx++; } /* end while */ - if(idx == type_table->nobjs) { - /* unknown type */ - begin_obj(dump_header_format->datatypebegin, type, - dump_header_format->datatypeblockbegin); - indentation(COL); - error_msg(progname, "unable to open datatype \"%s\"\n", type); - end_obj(dump_header_format->datatypeend, + if(idx == type_table->nobjs) + { + if ( pe ) + { + /* unknown type */ + begin_obj(dump_header_format->datatypebegin, type, + dump_header_format->datatypeblockbegin); + indentation(COL); + error_msg(progname, "unable to open datatype \"%s\"\n", type); + end_obj(dump_header_format->datatypeend, dump_header_format->datatypeblockend); - d_status = EXIT_FAILURE; - } else { + d_status = EXIT_FAILURE; + } + } + else + { hid_t dsetid = H5Dopen2(fid, type_table->objs[idx].objname, H5P_DEFAULT); type_id = H5Dget_type(dsetid); dump_named_datatype(type_id, type); H5Tclose(type_id); H5Dclose(dsetid); } - } else { + } + else + { dump_named_datatype(type_id, type); if(H5Tclose(type_id) < 0) @@ -4196,7 +4240,7 @@ main(int argc, const char *argv[]) for(i = 0; i < argc; i++) if(hand[i].func) - hand[i].func(fid, hand[i].obj, hand[i].subset_info); + hand[i].func(fid, hand[i].obj, hand[i].subset_info, 1); } if (!doxml) { @@ -6632,3 +6676,51 @@ add_prefix(char **prfx, size_t *prfx_len, const char *name) HDstrcat(HDstrcat(*prfx, "/"), name); } /* end add_prefix */ + +/*------------------------------------------------------------------------- + * Function: dump_extlink + * + * made by: PVN + * + * Purpose: Dump an external link + * Since external links are soft links, they are dumped on a trial error + * basis, attempting to dump as a dataset, as a group and as a named datatype + * Error messages are supressed + * + *------------------------------------------------------------------------- + */ + +static int dump_extlink(const char *filename, const char *targname) +{ + hid_t fid; + + + fid = h5tools_fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT, driver, NULL, 0); + + if (fid < 0) + { + goto fail; + } + + /* add some indentation to distinguish that these objects are external */ + indent += 2*COL; + + handle_datasets(fid, targname, NULL, 0); + handle_groups(fid, targname, NULL, 0); + handle_datatypes(fid, targname, NULL, 0); + + indent -= 2*COL; + + + if (H5Fclose(fid) < 0) + d_status = EXIT_FAILURE; + + + return SUCCEED; + +fail: + + return FAIL; + +} + diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 270f2ee..63cb1e8 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -88,6 +88,9 @@ #define FILE58 "tordergr.h5" #define FILE59 "torderattr.h5" #define FILE60 "tfpformat.h5" +#define FILE61 "textlinksrc.h5" +#define FILE62 "textlinktar.h5" + @@ -5544,14 +5547,14 @@ error: * Contains: * 1) an integer dataset * 2) a float dataset - * 4) a double dataset + * 3) a double dataset * *------------------------------------------------------------------------- */ static void gent_binary(void) { - hid_t fid, sid, did, tid; + hid_t fid, sid, did; hsize_t dims[1] = {6}; int ibuf[6] = {1,2,3,4,5,6}; float fbuf[6] = {1,2,3,4,5,6}; @@ -6175,6 +6178,67 @@ gent_fpformat(void) } /*------------------------------------------------------------------------- + * Function: gent_extlinks + * + * Purpose: Generate 2 files to be used in the external links test + * External links point from one HDF5 file to an object (Group, Dataset, or + * committed Datatype) in another file. + * + *------------------------------------------------------------------------- + */ +static void +gent_extlinks(void) +{ + hid_t source_fid, target_fid, sid, did, gid, tid; + hsize_t dims[1] = {6}; + int buf[6] = {1, 2, 3, 4, 5, 6}; + + /* create two files, a source and a target */ + source_fid = H5Fcreate(FILE61, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + target_fid = H5Fcreate(FILE62, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + +/*------------------------------------------------------------------------- + * create a Group, a Dataset, and a committed Datatype in the target + *------------------------------------------------------------------------- + */ + + gid = H5Gcreate2(target_fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + sid = H5Screate_simple(1, dims, NULL); + did = H5Dcreate2(gid, "dset", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + H5Dclose(did); + H5Sclose(sid); + H5Gclose(gid); + + + sid = H5Screate_simple(1, dims, NULL); + did = H5Dcreate2(target_fid, "dset", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + H5Dclose(did); + H5Sclose(sid); + + tid = H5Tcopy(H5T_NATIVE_INT); + H5Tcommit2(target_fid, "type", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Tclose(tid); + +/*------------------------------------------------------------------------- + * create external links in the source file pointing to the target objects + *------------------------------------------------------------------------- + */ + + H5Lcreate_external(FILE62, "group", source_fid, "ext_link1", H5P_DEFAULT, H5P_DEFAULT); + H5Lcreate_external(FILE62, "dset", source_fid, "ext_link2", H5P_DEFAULT, H5P_DEFAULT); + H5Lcreate_external(FILE62, "type", source_fid, "ext_link3", H5P_DEFAULT, H5P_DEFAULT); + + /* close */ + H5Fclose(source_fid); + H5Fclose(target_fid); +} + + + +/*------------------------------------------------------------------------- * Function: main * *------------------------------------------------------------------------- @@ -6242,6 +6306,7 @@ int main(void) gent_group_creation_order(); gent_attr_creation_order(); gent_fpformat(); + gent_extlinks(); return 0; diff --git a/tools/testfiles/tall-1.ddl b/tools/testfiles/tall-1.ddl index cd5f721..9a72484 100644 --- a/tools/testfiles/tall-1.ddl +++ b/tools/testfiles/tall-1.ddl @@ -65,7 +65,6 @@ GROUP "/" { } GROUP "g1.2" { EXTERNAL_LINK "extlink" { - LINKCLASS 64 TARGETFILE "somefile" TARGETPATH "somepath" } diff --git a/tools/testfiles/tall-2A.ddl b/tools/testfiles/tall-2A.ddl index 2c56501..c6ff136 100644 --- a/tools/testfiles/tall-2A.ddl +++ b/tools/testfiles/tall-2A.ddl @@ -49,7 +49,6 @@ GROUP "/" { } GROUP "g1.2" { EXTERNAL_LINK "extlink" { - LINKCLASS 64 TARGETFILE "somefile" TARGETPATH "somepath" } diff --git a/tools/testfiles/tall-2B.ddl b/tools/testfiles/tall-2B.ddl index ec220e9..5642d2c 100644 --- a/tools/testfiles/tall-2B.ddl +++ b/tools/testfiles/tall-2B.ddl @@ -45,7 +45,6 @@ GROUP "/" { } GROUP "g1.2" { EXTERNAL_LINK "extlink" { - LINKCLASS 64 TARGETFILE "somefile" TARGETPATH "somepath" } |