summaryrefslogtreecommitdiffstats
path: root/doc/html/Tutor/mount.html
blob: 9d0e4944381a5551130bab441c0578648c73c658 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<HTML><HEAD>
<TITLE>HDF5 Tutorial - Mounting Files 
</TITLE> 
</HEAD>

<body bgcolor="#ffffff">

<!-- BEGIN MAIN BODY -->

<A HREF="http://www.ncsa.uiuc.edu/"><img border=0 
src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
width=78 height=27 alt="NCSA"><P></A>

 [ <A HREF="title.html"><I>HDF5 Tutorial Top</I></A> ]
<H1>
<BIG><BIG><BIG><FONT COLOR="#c101cd">Mounting Files</FONT>
</BIG></BIG></BIG></H1>

<hr noshade size=1>

<BODY>
<H2>Contents:</H2>
<UL>
    <LI> <A HREF="#def">Mounting Files</A>
    <LI> Programming Example 
    <UL>
      <LI> <A HREF="#desc">Description</A> 
      <LI> <A HREF="#rem">Remarks</A> 
<!--
      <LI> <A HREF="#fc">File Contents</A>
-->
    </UL>
</UL>
<HR>
<A NAME="def">
<H2>Mounting Files</H2>

HDF5 allows you to combine two or more HDF5 files in a manner similar to mounting
files in UNIX. The group structure and metadata from one file appear as though
they exist in another file. The following steps are involved:
<OL>
<LI>Open the files.

<LI>Choose the "mount point" in the first file (parent). The "mount point" in 
    HDF5 is a group ( it can also be the root group ).

<LI>Use the HDF5 API function H5Fmount to mount the second file (child) in 
    the first one.

<LI>Work with the objects in the second file as if they were members of 
   the "mount point" group in the first file.  The previous contents of
   the "mount point" group are temporarily hidden.

<LI>Unmount the second file using the H5Funmount function when the work is done.
</OL>

<H2> Programming Example</H2>
<A NAME="desc">
<H3><U>Description</U></H3>      

In the following example we create one file with a group in it, and another
file with a dataset. Mounting is used to access the dataset from the second 
file as a member of a group in the first file. The following picture 
illustrates this concept.
<PRE>

    'FILE1'                                 'FILE2'
  
--------------------                   --------------------
!                  !                   !                  !
!      /           !                   !       /          !
!       |          !                   !        |         !
!       |          !                   !        |         !
!       V          !                   !        V         !
!     --------     !                   !     ----------   !
!     ! Group !    !                   !     ! Dataset!   !
!     ---------    !                   !     ----------   !
!------------------!                   !------------------! 
</PRE>
After mounting the second file, 'FILE2', under the group in the file, 'FILE1', 
the parent has the following structure:
<PRE>
 
                                'FILE1'                                 
  
                           --------------------                   
                           !                  !                  
                           !      /           !               
                           !       |          !            
                           !       |          !         
                           !       V          !    
                           !     --------     !              
                           !     ! Group !    !            
                           !     ---------    !           
                           !         |        !
                           !         |        !
                           !         V        !
                           !    -----------   !
                           !    ! Dataset !   !
                           !    !----------   !
                           !                  !
                           !------------------!                    

</PRE>
[ <A HREF="examples/h5_mount.c">Download h5_mount.c</A> ]
<PRE>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include&lt;hdf5.h&gt;

#define FILE1 "mount1.h5"
#define FILE2 "mount2.h5"

#define RANK 2
#define NX 4
#define NY 5

int main(void) 
{

   hid_t fid1, fid2, gid;  /* Files and group identifiers */
   hid_t did, tid, sid;    /* Dataset and datatype identifiers */ 

   herr_t status;
   hsize_t dims[] = {NX,NY}; /* Dataset dimensions */

   int i, j;
   int bm[NX][NY], bm_out[NX][NY]; /* Data buffers */

   /*
    * Initialization of buffer matrix "bm" 
    */
   for(i =0; i &lt; NX; i++) {
    for(j = 0; j &lt; NY; j++)
      bm[i][j] = i + j;
   }

   /* 
    * Create first file and a group in it.
    */
   fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
   gid = H5Gcreate(fid1, "/G", 0);

   /* 
    * Close group and file 
    */
   H5Gclose(gid);
   H5Fclose(fid1);

   /* 
    * Create second file and dataset "D" in it.
    */
   fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
   dims[0] = NX;
   dims[1] = NY;
   sid = H5Screate_simple(RANK, dims, NULL);
   did = H5Dcreate(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT);
  
   /*
    * Write data to the dataset.
    */
   status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);

   /* 
    * Close all identifiers.
    */
   H5Sclose(sid);
   H5Dclose(did);
   H5Fclose(fid2);

   /* 
    * Reopen both files
    */
   fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
   fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
  
   /* 
    * Mount second file under G in the first file.
    */
   H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);

   /* 
    * Access dataset D in the first file under /G/D name.
    */
   did = H5Dopen(fid1,"/G/D");
   tid = H5Dget_type(did);
   status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);

   /*
    * Print out the data.
    */
   for(i=0; i &lt; NX; i++){
    for(j=0; j &lt; NY; j++)
        printf("  %d", bm_out[i][j]);
	printf("\n");
   }

   /* 
    * Close all identifers
    */
   H5Tclose(tid);
   H5Dclose(did);
	
   /* 
    * Unmounting second file
    */
   H5Funmount(fid1, "/G");

   /*
    * Close both files
    */
   H5Fclose(fid1);
   H5Fclose(fid2);

   return 0;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
</PRE>
<A NAME="rem">
<H3><U>Remarks</U></H3>
<UL>
<LI> The first part of the program creates a group in one file and creates 
     and writes a dataset to another file. 
<P>
<LI> Both files are reopened with the H5F_ACC_RDONLY access flag since no 
     objects will be modified. The child should be opened with H5F_ACC_RDWR if 
     the dataset is to be modified. 
<P>
<LI> The second file is mounted in the first using the H5Fmount function.
<PRE>
  herr_t  H5Fmount(hid_t loc_id, const char *name, hid_t file_id, hid_t plist_id)  
</PRE>
<UL>
   <LI> The first two arguments specify the location of the "mount point" 
        ( a group ).  In this example the "mount point" is a group "/G" in the 
        file specified by its handle <I>fid1</I>. Since group G is in the root 
        group of the first file, one can also use just "G" to identify it. 
<P>
        Below is a description of another scenario:<BR>
        Suppose group G was a member of group D in the first file (<I>fid1</I>).
        Then mounting point G can be specified in two different ways:
<P>
<UL>
          <LI> <I>loc_id</I> is <I>fid1</I><BR>
               <I>name</I> is "D/G"      
<P>
          <LI> <I>loc_id</I> is an identifier of the group "D"<BR> 
               <I>name</I> is just "G"  
</UL>
   <P>  
    <LI> The third argument is an identifier of the file which will be mounted.
         Only one file can be mounted per "mount point".
<P>
    <LI> The fourth argument is an identifier of the property list to be used.
         Currently, only the default property list, H5P_DEFAULT, can be used.
</UL>
<P>
<LI>  In this example we just read data from the dataset D. One can modify
    data also. If the dataset is modified while the file is mounted, it becomes
    modified in the original file too after the file is unmounted.
<P>
<LI> The file is unmounted with the H5Funmount function:
<PRE>
  herr_t H5Funmount(hid_t loc_id, const char *name)
</PRE>
    Arguments to this function specify the location of the "mount point".
    In our example <I>loc_id</I> is an identifier of the first file, and 
    <I>name</I> is the name of group G, "/G". One could also use "G" 
    instead of "/G" since G is a member of the root group in the file 
    <I>fid1</I>.  Notice that H5Funmount does not close files.  They are closed
    with the respective calls to the H5Fclose function. Closing the parent
    automatically unmounts the child.
<P> 
<LI>The h5dump utility cannot display files in memory, therefore no output 
    of FILE1 after FILE2 was mounted is provided. 
</UL>       
</UL>


<!-- BEGIN FOOTER INFO -->

<P><hr noshade size=1>
<font face="arial,helvetica" size="-1">
  <a href="http://www.ncsa.uiuc.edu/"><img border=0
     src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
     width=78 height=27 alt="NCSA"><br>
  The National Center for Supercomputing Applications</A><br>
  <a href="http://www.uiuc.edu/">University of Illinois
    at Urbana-Champaign</a><br>
  <br>
<!-- <A HREF="helpdesk.mail.html"> -->
<A HREF="mailto:hdfhelp@ncsa.uiuc.edu">
hdfhelp@ncsa.uiuc.edu</A>
<BR> <H6>Last Modified: August 27, 1999</H6><BR>
<!-- modified by Barbara Jones - bljones@ncsa.uiuc.edu -->
</FONT>
<BR>
<!-- <A HREF="mailto:hdfhelp@ncsa.uiuc.edu"> -->

</BODY>
</HTML>