This is the correct behavior. Using H5Fmount
only mounts the file at that location in memory. So when you close the files and exit your program the newfile (new.h5
) does not (and will not) show the contents of the mounted files.
If you want this kind of behavior, use H5Lcreate_external
to create external links.
I've changed your code to be C (not C++ - sorry, but the idea is the same):
#include <stdlib.h>
#include <stdio.h>
#include <hdf5.h>
#define FILE_NAME_1 "file1.h5"
#define FILE_NAME_2 "file2.h5"
#define FILE_NAME_ALL "new.h5"
int main(void)
{
hid_t fid1; /* Files identifier */
fid1 = H5Fcreate(FILE_NAME_ALL, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Link "file1.h5" to group F1
*/
H5Lcreate_external(FILE_NAME_1, "/", fid1, "/F1", H5P_DEFAULT, H5P_DEFAULT);
/*
* Link "file2.h5" to group F2
*/
H5Lcreate_external(FILE_NAME_2, "/", fid1, "/F2", H5P_DEFAULT, H5P_DEFAULT);
H5Fclose(fid1);
return 0;
}
Where the contents of file1.h5
and file2.h5
are the same for the test case:
h5dump file1.h5
HDF5 "file1.h5" {
GROUP "/" {
DATASET "D" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 4, 5 ) / ( 4, 5 ) }
DATA {
(0,0): 0, 1, 2, 3, 4,
(1,0): 1, 2, 3, 4, 5,
(2,0): 2, 3, 4, 5, 6,
(3,0): 3, 4, 5, 6, 7
}
}
}
}
Then if we compile and run the test program:
h5cc -o test test.c && ./test
Finally dump the new file:
h5dump new.h5
HDF5 "new.h5" {
GROUP "/" {
EXTERNAL_LINK "F1" {
TARGETFILE "file1.h5"
TARGETPATH "/"
GROUP "/" {
DATASET "D" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 4, 5 ) / ( 4, 5 ) }
DATA {
(0,0): 0, 1, 2, 3, 4,
(1,0): 1, 2, 3, 4, 5,
(2,0): 2, 3, 4, 5, 6,
(3,0): 3, 4, 5, 6, 7
}
}
}
}
EXTERNAL_LINK "F2" {
TARGETFILE "file2.h5"
TARGETPATH "/"
GROUP "/" {
DATASET "D" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 4, 5 ) / ( 4, 5 ) }
DATA {
(0,0): 0, 1, 2, 3, 4,
(1,0): 1, 2, 3, 4, 5,
(2,0): 2, 3, 4, 5, 6,
(3,0): 3, 4, 5, 6, 7
}
}
}
}
}
}