1 #include "mfhdf.h"
2 
3 
4 #define FILE1_NAME         "hdifftst1.hdf"
5 #define FILE2_NAME         "hdifftst2.hdf"
6 
7 /* big file for hyperslab I/O */
8 #define FILE3_NAME         "hdifftst3.hdf"
9 #define FILE4_NAME         "hdifftst4.hdf"
10 
11 /* lones */
12 #define FILE5_NAME         "hdifftst5.hdf"
13 #define FILE6_NAME         "hdifftst6.hdf"
14 
15 /* groups */
16 #define FILE7_NAME         "hdifftst7.hdf"
17 
18 
19 #define X_LENGTH           2
20 #define Y_LENGTH           3
21 #define RANK               2
22 #define FILE_ATTR_NAME     "File_contents"
23 #define SDS_ATTR_NAME      "Valid_range"
24 
25 
26 #define  CLASS1_NAME       "5x1 Array"
27 #define  CLASS2_NAME       "6x4 Array"
28 #define  VDATA1_NAME       "vdata1"
29 #define  VDATA2_NAME       "vdata2"
30 #define  FIELD1_NAME       "Single-component Field"
31 #define  FIELD2_NAME       "Multi-component Field"
32 #define  N_RECORDS_1       5    /* number of records the first vdata contains  */
33 #define  N_RECORDS_2       2    /* number of records the second vdata contains */
34 #define  ORDER_2           4    /* order of the field in the second vdata      */
35 
36 #define  CLASS3_NAME       "Particle Data"
37 #define  VDATA3_NAME       "vdata3"
38 #define  FIELD3_NAME1      "Position"
39 #define  FIELD3_NAME2      "Mass"
40 #define  FIELD3_NAME3      "Temperature"
41 #define  FIELDNAME3_LIST   "Position,Mass,Temperature"      /* No spaces b/w names */
42 #define  ORDER3_1          3                                /* order of first field */
43 #define  ORDER3_2          1                                /* order of second field */
44 #define  ORDER3_3          2                                /* order of third field */
45 #define  N_VALS_PER_REC   (ORDER3_1 + ORDER3_2 + ORDER3_3)  /* number of values per record */
46 
47 
48 
49 /*-------------------------------------------------------------------------
50  * local prototypes
51  *-------------------------------------------------------------------------
52  */
53 static int do_big_file(void);
54 static int do_groups(void);
55 
56 /*-------------------------------------------------------------------------
57  * main
58  *-------------------------------------------------------------------------
59  */
60 
main(void)61 int main(void)
62 {
63  int32 sd1_id;        /* SD interface identifier */
64  int32 sd2_id;        /* SD interface identifier */
65  int32 sds1_id;       /* SDS identifier */
66  int32 sds2_id;       /* SDS identifier */
67  int32 dim_sizes[2];  /* sizes of the SDS dimensions */
68  int32 start[2];      /* start location to write */
69  int32 edges[2];      /* number of elements to write */
70  int32 n_values;
71  int32 buf1a[Y_LENGTH][X_LENGTH] = {{1,1},{1,1},{5,6}};
72  int32 buf1b[Y_LENGTH][X_LENGTH] = {{1,2},{3,4},{5,6}};
73 
74  /* percent test: compare divide by zero, both zero */
75  int32 buf2a[Y_LENGTH][X_LENGTH] = {{100,100},{100,0},{0,100}};
76  int32 buf2b[Y_LENGTH][X_LENGTH] = {{120,80},{0,100},{0,50}};
77 
78  /* global attributes */
79  char8 bufga1[] = "Storm_track_data1";
80  char8 bufga2[] = "Storm_track_data2";
81  float32 bufa1[2] = {1., 1.};
82  float32 bufa2[2] = {1., 2.};
83 
84  /*vdata*/
85  int32 file1_id;
86  int32 file2_id;
87  int32 vdata1_id;
88  int32 vdata2_id;
89  char8 vdata1_buf1 [N_RECORDS_1] = {'V', 'D', 'A', 'T', 'A'};
90  char8 vdata1_buf2 [N_RECORDS_1] = {'X', 'D', 'A', 'T', 'A'};
91  int32 vdata2_buf1  [N_RECORDS_2][ORDER_2] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
92  int32 vdata2_buf2  [N_RECORDS_2][ORDER_2] = {{1, 1, 1, 1}, {5, 6, 7, 8}};
93  float32 vdata3_buf1[N_RECORDS_2][N_VALS_PER_REC]={{1,2,3,4,5,6},{7,8,9,10,11,12}};
94  float32 vdata3_buf2[N_RECORDS_2][N_VALS_PER_REC]={{1,1,1,1,1,1},{7,8,9,10,11,12}};
95 
96 /* Define the location and size of the data to be written to the data set*/
97  start[0] = 0;
98  start[1] = 0;
99  edges[0] = Y_LENGTH;
100  edges[1] = X_LENGTH;
101 
102 /* Define the dimensions of the array to be created */
103  dim_sizes[0] = Y_LENGTH;
104  dim_sizes[1] = X_LENGTH;
105 
106 /*-------------------------------------------------------------------------
107  * SD data
108  *-------------------------------------------------------------------------
109  */
110 
111 
112 /* Create the files and initialize the SD interface */
113  if ((sd1_id = SDstart (FILE1_NAME, DFACC_CREATE))==FAIL)
114      goto error;
115  if ((sd2_id = SDstart (FILE2_NAME, DFACC_CREATE))==FAIL)
116      goto error;
117 
118 /* Set a global attribute */
119  n_values  = sizeof(bufga1);
120  if ( SDsetattr (sd1_id, FILE_ATTR_NAME, DFNT_CHAR8, n_values, (VOIDP)bufga1)==FAIL)
121      goto error;
122  if ( SDsetattr (sd2_id, FILE_ATTR_NAME, DFNT_CHAR8, n_values, (VOIDP)bufga2)==FAIL)
123      goto error;
124 
125 /* Create the data sets */
126  if ((sds1_id = SDcreate (sd1_id, "dset1", DFNT_INT32, RANK, dim_sizes))==FAIL)
127      goto error;
128  if ((sds2_id = SDcreate (sd2_id, "dset1", DFNT_INT32, RANK, dim_sizes))==FAIL)
129      goto error;
130 
131 /* Assign attribute */
132  n_values  = 2;
133  if ( SDsetattr (sds1_id, SDS_ATTR_NAME, DFNT_FLOAT32, n_values, (VOIDP)bufa1)==FAIL)
134      goto error;
135  if ( SDsetattr (sds2_id, SDS_ATTR_NAME, DFNT_FLOAT32, n_values, (VOIDP)bufa2)==FAIL)
136      goto error;
137 
138 /* Write the stored data to the data set */
139  if ( SDwritedata (sds1_id, start, NULL, edges, (VOIDP)buf1a)==FAIL)
140      goto error;
141  if ( SDwritedata (sds2_id, start, NULL, edges, (VOIDP)buf1b)==FAIL)
142      goto error;
143 
144 /* Terminate access to the data set */
145  if ( SDendaccess (sds1_id)==FAIL)
146      goto error;
147  if ( SDendaccess (sds2_id)==FAIL)
148      goto error;
149 
150  /* Create another data set */
151  if (( sds1_id = SDcreate (sd1_id, "dset2", DFNT_INT32, RANK, dim_sizes))==FAIL)
152      goto error;
153  if (( sds2_id = SDcreate (sd2_id, "dset2", DFNT_INT32, RANK, dim_sizes))==FAIL)
154      goto error;
155  if ( SDwritedata (sds1_id, start, NULL, edges, (VOIDP)buf1a)==FAIL)
156      goto error;
157  if ( SDwritedata (sds2_id, start, NULL, edges, (VOIDP)buf1b)==FAIL)
158      goto error;
159  if ( SDendaccess (sds1_id)==FAIL)
160      goto error;
161  if ( SDendaccess (sds2_id)==FAIL)
162      goto error;
163 
164  /* data sets for -p test */
165  if (( sds1_id = SDcreate (sd1_id, "dset3", DFNT_INT32, RANK, dim_sizes))==FAIL)
166      goto error;
167  if (( sds2_id = SDcreate (sd2_id, "dset3", DFNT_INT32, RANK, dim_sizes))==FAIL)
168      goto error;
169  if ( SDwritedata (sds1_id, start, NULL, edges, (VOIDP)buf2a)==FAIL)
170      goto error;
171  if ( SDwritedata (sds2_id, start, NULL, edges, (VOIDP)buf2b)==FAIL)
172      goto error;
173  if ( SDendaccess (sds1_id)==FAIL)
174      goto error;
175  if ( SDendaccess (sds2_id)==FAIL)
176      goto error;
177 
178 
179 /*-------------------------------------------------------------------------
180  * end SD
181  *-------------------------------------------------------------------------
182  */
183 
184  /* Terminate access to the SD interface and close the file */
185  if ( SDend (sd1_id)==FAIL)
186      goto error;
187  if ( SDend (sd2_id)==FAIL)
188      goto error;
189 
190 
191 
192 /*-------------------------------------------------------------------------
193  * VD data
194  *-------------------------------------------------------------------------
195  */
196 
197 /* Open the HDF file for writing */
198  if ((file1_id = Hopen (FILE1_NAME, DFACC_WRITE, 0))==FAIL)
199      goto error;
200  if ((file2_id = Hopen (FILE2_NAME, DFACC_WRITE, 0))==FAIL)
201      goto error;
202 
203 /* Initialize the VS interface */
204  if ( Vstart (file1_id)==FAIL)
205      goto error;
206  if ( Vstart (file2_id)==FAIL)
207      goto error;
208 
209 /*-------------------------------------------------------------------------
210  * VD data one field
211  *-------------------------------------------------------------------------
212  */
213 
214 /* Create the first vdata and populate it with data from vdata1_buf */
215  if (VHstoredata (file1_id, FIELD1_NAME, (uint8 *)vdata1_buf1,
216   N_RECORDS_1, DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME)==FAIL)
217      goto error;
218  if (VHstoredata (file2_id, FIELD1_NAME, (uint8 *)vdata1_buf2,
219   N_RECORDS_1, DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME)==FAIL)
220      goto error;
221 
222 /*-------------------------------------------------------------------------
223  * VD data one field, order 4
224  *-------------------------------------------------------------------------
225  */
226 
227 /* Create the second vdata and populate it with data from vdata2_buf */
228  if ( VHstoredatam (file1_id, FIELD2_NAME, (uint8 *)vdata2_buf1,
229   N_RECORDS_2, DFNT_INT32, VDATA2_NAME, CLASS2_NAME, ORDER_2)==FAIL)
230      goto error;
231  if ( VHstoredatam (file2_id, FIELD2_NAME, (uint8 *)vdata2_buf2,
232   N_RECORDS_2, DFNT_INT32, VDATA2_NAME, CLASS2_NAME, ORDER_2)==FAIL)
233      goto error;
234 
235 /*-------------------------------------------------------------------------
236  * VD data several fields
237  *-------------------------------------------------------------------------
238  */
239 
240 /* Create a new vdata */
241  if ((vdata1_id = VSattach (file1_id, -1, "w"))==FAIL)
242      goto error;
243  if ((vdata2_id = VSattach (file2_id, -1, "w"))==FAIL)
244      goto error;
245 
246 /* Set name and class name of the vdata */
247  if ( VSsetname (vdata1_id, VDATA3_NAME)==FAIL)
248      goto error;
249  if ( VSsetclass (vdata1_id, CLASS3_NAME)==FAIL)
250      goto error;
251  if ( VSsetname (vdata2_id, VDATA3_NAME)==FAIL)
252      goto error;
253  if ( VSsetclass (vdata2_id, CLASS3_NAME)==FAIL)
254      goto error;
255 
256 /* Define fields */
257  if ( VSfdefine (vdata1_id, FIELD3_NAME1, DFNT_FLOAT32, ORDER3_1 )==FAIL)
258      goto error;
259  if ( VSfdefine (vdata1_id, FIELD3_NAME2, DFNT_FLOAT32, ORDER3_2 )==FAIL)
260      goto error;
261  if ( VSfdefine (vdata1_id, FIELD3_NAME3, DFNT_FLOAT32, ORDER3_3 )==FAIL)
262      goto error;
263  if ( VSsetfields (vdata1_id, FIELDNAME3_LIST )==FAIL)
264      goto error;
265  if ( VSfdefine (vdata2_id, FIELD3_NAME1, DFNT_FLOAT32, ORDER3_1 )==FAIL)
266      goto error;
267  if ( VSfdefine (vdata2_id, FIELD3_NAME2, DFNT_FLOAT32, ORDER3_2 )==FAIL)
268      goto error;
269  if ( VSfdefine (vdata2_id, FIELD3_NAME3, DFNT_FLOAT32, ORDER3_3 )==FAIL)
270      goto error;
271  if ( VSsetfields (vdata2_id, FIELDNAME3_LIST)==FAIL)
272      goto error;
273 
274 /* Write the data with full interlacing mode */
275  if ( VSwrite (vdata1_id, (uint8 *)vdata3_buf1, N_RECORDS_2, FULL_INTERLACE)==FAIL)
276      goto error;
277  if ( VSwrite (vdata2_id, (uint8 *)vdata3_buf2, N_RECORDS_2, FULL_INTERLACE)==FAIL)
278      goto error;
279 
280  if ( VSdetach (vdata1_id)==FAIL)
281      goto error;
282  if ( VSdetach (vdata2_id)==FAIL)
283      goto error;
284 
285 /*-------------------------------------------------------------------------
286  * end VD data
287  *-------------------------------------------------------------------------
288  */
289 
290 /* Terminate access to the VS interface and close the HDF file */
291  if ( Vend (file1_id)==FAIL)
292      goto error;
293  if ( Vend (file2_id)==FAIL)
294      goto error;
295  if ( Hclose (file1_id)==FAIL)
296      goto error;
297  if ( Hclose (file2_id)==FAIL)
298      goto error;
299 
300 /*-------------------------------------------------------------------------
301  * write 2 big files for hyperslab reading
302  *-------------------------------------------------------------------------
303  */
304  if (do_big_file()==FAIL)
305      goto error;
306 
307 /*-------------------------------------------------------------------------
308  * groups
309  *-------------------------------------------------------------------------
310  */
311  if (do_groups()==FAIL)
312      goto error;
313 
314 
315  return 0;
316 
317 error:
318 
319  printf("Error...Exiting...\n");
320 
321  return 1;
322 
323 }
324 
325 
326 
327 #define DIM0     10
328 #define DIM1     10
329 #define ADD_ROWS ( 1024 * 1024 - 10 ) / 10
330 
331 /*-------------------------------------------------------------------------
332  * write 2 big files for hyperslab reading
333  *-------------------------------------------------------------------------
334  */
do_big_file(void)335 static int do_big_file(void)
336 {
337 
338     int32 sd1_id;        /* SD interface identifier */
339     int32 sd2_id;        /* SD interface identifier */
340     int32 sds1_id;       /* SDS identifier */
341     int32 sds2_id;       /* SDS identifier */
342     int32 dims[2];       /* sizes of the SDS dimensions */
343     int32 start[2];      /* start location to write */
344     int32 edges[2];      /* number of elements to write */
345 
346     int32 sds1_idx;
347     int32 sds2_idx;
348     int32 rank;
349 	uint8 array_data[DIM0][DIM1];
350     uint8 append_data1[DIM1];
351     uint8 append_data2[DIM1];
352 	intn  i, j, n;
353 
354 	/* Create 2 files and initiate the SD interface. */
355     if ((sd1_id = SDstart(FILE3_NAME, DFACC_CREATE))==FAIL)
356         goto error;
357     if ((sd2_id = SDstart(FILE4_NAME, DFACC_CREATE))==FAIL)
358         goto error;
359 
360 	/* Define the rank and dimensions of the data set to be created. */
361 	rank = 2;
362 	dims[0] = SD_UNLIMITED;
363 	dims[1] = DIM1;
364 
365 	/* Create 2 data sets */
366 	if ((sds1_id = SDcreate(sd1_id, "data1", DFNT_UINT8, rank, dims))==FAIL)
367         goto error;
368     if ((sds2_id = SDcreate(sd2_id, "data1", DFNT_UINT8, rank, dims))==FAIL)
369         goto error;
370 
371 	/* initial values */
372     for (j = 0; j < DIM0; j++)
373     {
374         for (i = 0; i < DIM1; i++)
375             array_data[j][i] = (i + j) + 1;
376     }
377 
378 	/* define the location, pattern, and size of the data set */
379     for (i = 0; i < rank; i++)
380     {
381         start[i] = 0;
382     }
383 	edges[0] = DIM0; /* 10 */
384 	edges[1] = DIM1; /* 5 */
385 
386     if ( SDwritedata(sds1_id, start, NULL, edges, (VOIDP)array_data)==FAIL)
387         goto error;
388     if ( SDwritedata(sds2_id, start, NULL, edges, (VOIDP)array_data)==FAIL)
389         goto error;
390 
391 	/* terminate access to the datasets and SD interface */
392     if ( SDendaccess(sds1_id)==FAIL)
393         goto error;
394     if ( SDendaccess(sds2_id)==FAIL)
395         goto error;
396     if ( SDend(sd1_id)==FAIL)
397         goto error;
398     if ( SDend(sd2_id)==FAIL)
399         goto error;
400 
401     /* append data */
402 	if (( sd1_id = SDstart(FILE3_NAME, DFACC_WRITE))==FAIL)
403         goto error;
404     if (( sd2_id = SDstart(FILE4_NAME, DFACC_WRITE))==FAIL)
405         goto error;
406 
407     if ((sds1_idx = SDnametoindex (sd1_id, "data1"))==FAIL)
408         goto error;
409     if ((sds2_idx = SDnametoindex (sd2_id, "data1"))==FAIL)
410         goto error;
411 
412     if ((sds1_id = SDselect (sd1_id, sds1_idx))==FAIL)
413         goto error;
414     if ((sds2_id = SDselect (sd2_id, sds2_idx))==FAIL)
415         goto error;
416 
417    	/* define the location of the append */
418     for (n = 0; n < ADD_ROWS; n++)
419     {
420         start[0] = DIM0 + n;   /* 10 */
421         start[1] = 0;
422         edges[0] = 1;          /* 1 row at a time */
423         edges[1] = DIM1;       /* 5 elements */
424 
425         /* store array values to be appended */
426         for (i = 0; i < DIM1; i++)
427             append_data1[i] = i + 1;
428         for (i = 0; i < DIM1; i++)
429             append_data2[i] = i + 1;
430 
431         if (n == 20 || n == ADD_ROWS / 2 || n == ADD_ROWS - 10 )
432         {
433             /* change a few values at 3 places evenly divided */
434             for (i = 0; i < DIM1; i++)
435                 append_data2[i] = 100;
436 
437             /* append data to file */
438             if ( SDwritedata (sds1_id, start, NULL, edges, (VOIDP) append_data1)==FAIL)
439                 goto error;
440             if ( SDwritedata (sds2_id, start, NULL, edges, (VOIDP) append_data2)==FAIL)
441                 goto error;
442 
443 
444         }
445 
446     }
447 
448     /* terminate access */
449     if ( SDendaccess (sds1_id)==FAIL)
450         goto error;
451     if ( SDendaccess (sds2_id)==FAIL)
452         goto error;
453     if ( SDend (sd1_id)==FAIL)
454         goto error;
455     if ( SDend (sd2_id)==FAIL)
456         goto error;
457 
458     return SUCCEED;
459 
460 error:
461 
462     printf("Error...Exiting...\n");
463 
464     return FAIL;
465 
466 
467 }
468 
469 
470 #define  FILE_LABEL_TXT  "created with HDF 4.2 Release 1"
471 
472 /*-------------------------------------------------------------------------
473  * do_lone
474  *-------------------------------------------------------------------------
475  */
476 
do_lone(char * file_name,int do_diffs)477 int do_lone(char* file_name, int do_diffs)
478 {
479     char    sds_name[]  = "lone";
480     int32   rank        = 1;
481     int32   dim_sds[1]  = {5};             /* dimension of the data set */
482     int32   data[5]     = {1, 2, 3, 4, 5};
483     int32   start[1];                      /* start position to write for each dimension */
484     int32   edges[1];                      /* number of elements to be written along each dimension */
485     int32   sds_id;
486     int32   dim_id;
487     int32   sd_id;
488 
489     if ( do_diffs )
490     {
491 
492         data[1] = data[2] = 0;
493     }
494 
495     sd_id  = SDstart(file_name, DFACC_CREATE);
496 
497     /* create the SDS */
498     if ((sds_id = SDcreate (sd_id, sds_name, DFNT_INT32, rank, dim_sds))<0)
499     {
500         printf( "Could not create SDS <%s>\n",sds_name);
501         goto fail;
502     }
503 
504     dim_id = SDgetdimid(sds_id, 0);
505     SDsetdimname(dim_id, sds_name);
506 
507     /* define the location and size of the data to be written to the data set */
508     start[0] = 0;
509     edges[0] = 5;
510 
511     /* write the stored data to the data set */
512     if (SDwritedata (sds_id, start, NULL, edges, (VOIDP)data)==FAIL)
513     {
514         printf( "Failed to set write for SDS <%s>\n", sds_name);
515         goto fail;
516     }
517 
518 
519     SDendaccess(sds_id);
520 
521 
522     /* create the SDS */
523     if ((sds_id = SDcreate (sd_id, "sds", DFNT_INT32, rank, dim_sds))<0)
524     {
525         printf( "Could not create SDS <%s>\n");
526         goto fail;
527     }
528 
529     if (SDwritedata (sds_id, start, NULL, edges, (VOIDP)data)==FAIL)
530     {
531         printf( "Failed to set write for SDS <%s>\n");
532         goto fail;
533     }
534 
535     SDendaccess(sds_id);
536 
537     SDend(sd_id);
538 
539 
540     {
541         int32 file1_id;      /*  HDF file identifier */
542         int32 an_id;        /* AN interface identifier */
543         int32 file_label_id;  /* file label identifier */
544 
545         /* open file */
546         if ((file1_id = Hopen (file_name, DFACC_WRITE, (int16)0))<0)
547         {
548             printf("Error: Could not open file <%s>\n",file_name);
549             return FAIL;
550         }
551 
552         /* Initialize the AN interface */
553         an_id = ANstart (file1_id);
554 
555         /* Create the file label */
556         file_label_id = ANcreatef (an_id, AN_FILE_LABEL);
557 
558         /* Write the annotations to the file label */
559         if (ANwriteann (file_label_id,FILE_LABEL_TXT,strlen (FILE_LABEL_TXT))==FAIL)
560         {
561             printf( "Could not write AN\n");
562             return FAIL;
563         }
564 
565         /* Terminate access to annotation */
566         if (ANendaccess (file_label_id)==FAIL)
567         {
568             printf( "Could not end AN\n");
569             return FAIL;
570         }
571 
572         /* Terminate access to the AN interface */
573         if (ANend (an_id)==FAIL)
574         {
575             printf( "Could not end AN\n");
576             return FAIL;
577         }
578 
579 
580         /* close the HDF file */
581         if (Hclose (file1_id)==FAIL)
582         {
583             printf( "Could not close file\n");
584             return FAIL;
585         }
586 
587     }
588 
589     return SUCCEED;
590 
591 fail:
592     SDend(sd_id);
593     return FAIL;
594 }
595 
596 
597 
598 /*-------------------------------------------------------------------------
599  * write groups
600  * a circular reference
601  *
602  *                g0 ----->   g1
603  *                 |       |    ^
604  *                 |       |    |
605  *                 |       \/   |
606  *                 |----->   g1.1
607  *
608  *-------------------------------------------------------------------------
609  */
610 
do_groups(void)611 static int do_groups(void)
612 {
613 
614      int32 vg0_id,    /* vgroup identifier */
615            vg1_id,    /* vgroup identifier */
616            vg2_id,    /* vgroup identifier */
617            file1_id;  /* HDF file identifier */
618 
619      /* create a HDF file */
620      if ((file1_id = Hopen (FILE7_NAME, DFACC_CREATE, (int16)0))<0)
621      {
622          printf("Error: Could not create file <%s>\n",FILE7_NAME);
623          return FAIL;
624      }
625 
626      /* initialize the V interface */
627      if (Vstart (file1_id)==FAIL)
628      {
629          printf( "Could not start VG\n");
630          return FAIL;
631      }
632 
633      /* create a vgroup */
634      vg0_id = Vattach (file1_id, -1, "w");
635      if (Vsetname (vg0_id, "g0")==FAIL)
636      {
637          printf( "Could not name group\n");
638          goto out;
639      }
640 
641      /* create the second vgroup */
642      vg1_id = Vattach (file1_id, -1, "w");
643      if (Vsetname (vg1_id, "g1")==FAIL)
644      {
645          printf( "Could not name group\n");
646          goto out;
647      }
648 
649      /* create the third vgroup */
650      vg2_id = Vattach (file1_id, -1, "w");
651      if (Vsetname (vg2_id, "g1.1")==FAIL)
652      {
653          printf( "Could not name group\n");
654          goto out;
655      }
656 
657      if (Vinsert (vg0_id, vg1_id)==FAIL)
658      {
659          printf( "Could not insert VG\n");
660          goto out;
661      }
662 
663      if (Vinsert (vg0_id, vg2_id)==FAIL)
664      {
665          printf( "Could not insert VG\n");
666          goto out;
667      }
668 
669      if (Vinsert (vg1_id, vg2_id)==FAIL)
670      {
671          printf( "Could not insert VG\n");
672          goto out;
673      }
674 
675      if (Vinsert (vg2_id, vg1_id)==FAIL)
676      {
677          printf( "Could not insert VG\n");
678          goto out;
679      }
680 
681      /* terminate access to the vgroup */
682      if (Vdetach (vg0_id)==FAIL)
683      {
684          printf( "Could not close group\n");
685          goto out;
686      }
687 
688      /* terminate access to the vgroup */
689      if (Vdetach (vg1_id)==FAIL)
690      {
691          printf( "Could not close group\n");
692          goto out;
693      }
694 
695      /* terminate access to the vgroup */
696      if (Vdetach (vg2_id)==FAIL)
697      {
698          printf( "Could not close group\n");
699          goto out;
700      }
701 
702      /* terminate access to the V interface */
703      if (Vend (file1_id)==FAIL)
704      {
705          printf( "Could not end VG\n");
706          goto out;
707      }
708 
709      /* close the HDF file */
710      if (Hclose (file1_id)==FAIL)
711      {
712          printf( "Could not close file\n");
713          return FAIL;
714      }
715 
716      return SUCCEED;
717 
718 out:
719      printf("Error...Exiting...\n");
720      return FAIL;
721 
722 }
723 
724