1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/************************************************************
This example shows how to use the external file cache.
This file is intended for use with HDF5 Library version
1.8.7 or newer
************************************************************/
#include "hdf5.h"
#define FILE "h5efc.h5"
#define EXT_FILE1 "h5efc1.h5"
#define EXT_FILE2 "h5efc2.h5"
#define EXT_FILE3 "h5efc3.h5"
int
main(void)
{
hid_t file1, file2, group, fapl; /* Handles */
herr_t status;
/*
* Create file access property list and set it to allow caching of open
* files visited through external links.
*/
fapl = H5Pcreate(H5P_FILE_ACCESS);
status = H5Pset_elink_file_cache_size(fapl, 8);
/*
* Create a new file using the file access property list.
*/
file1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/*
* Create files to serve as targets for external links.
*/
file2 = H5Fcreate(EXT_FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file2);
file2 = H5Fcreate(EXT_FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file2);
file2 = H5Fcreate(EXT_FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file2);
/*
* Create external links to the target files.
*/
status = H5Lcreate_external(EXT_FILE1, "/", file1, "link_to_1", H5P_DEFAULT, H5P_DEFAULT);
status = H5Lcreate_external(EXT_FILE2, "/", file1, "link_to_2", H5P_DEFAULT, H5P_DEFAULT);
status = H5Lcreate_external(EXT_FILE3, "/", file1, "link_to_3", H5P_DEFAULT, H5P_DEFAULT);
/*
* Open and close the targets of all three external links (these will be the
* root groups of the target files). The target files should be held open
* by the root file's external file cache after traversal.
*/
group = H5Gopen(file1, "/link_to_1", H5P_DEFAULT);
status = H5Gclose(group);
group = H5Gopen(file1, "/link_to_2", H5P_DEFAULT);
status = H5Gclose(group);
group = H5Gopen(file1, "/link_to_3", H5P_DEFAULT);
status = H5Gclose(group);
/*
* Open and close the targets of all three external links again. The target
* files should already be held open by the root file's external file cache,
* so the library will not actually have to issue an "open" system call.
*/
group = H5Gopen(file1, "/link_to_1", H5P_DEFAULT);
status = H5Gclose(group);
group = H5Gopen(file1, "/link_to_2", H5P_DEFAULT);
status = H5Gclose(group);
group = H5Gopen(file1, "/link_to_3", H5P_DEFAULT);
status = H5Gclose(group);
/*
* Release the root file's external file cache. This will close all the
* external link target files.
*/
status = H5Frelease_file_cache(file1);
/*
* Close and release resources.
*/
status = H5Pclose(fapl);
status = H5Fclose(file1);
return 0;
}
|