2006-08-03 07:41:53 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2006-08-03 07:41:53 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2006-08-03 07:41:53 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*
|
2020-08-07 08:58:07 +08:00
|
|
|
* Programmer: James Laird
|
2006-08-03 07:41:53 +08:00
|
|
|
* Tuesday, June 6, 2006
|
|
|
|
*
|
|
|
|
* This program creates HDF5 files with user-defined links. These files
|
|
|
|
* should be created on a little-endian and a big-endian machine.
|
|
|
|
* They will be named according to the platform and should
|
|
|
|
* be placed in the hdf5/test directory so that the links test can use them.
|
2007-11-07 23:38:45 +08:00
|
|
|
*
|
2006-08-03 07:41:53 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hdf5.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define NAME_LE_1 "le_extlink1.h5"
|
|
|
|
#define NAME_LE_2 "le_extlink2.h5"
|
|
|
|
#define NAME_BE_1 "be_extlink1.h5"
|
|
|
|
#define NAME_BE_2 "be_extlink2.h5"
|
2006-08-03 07:41:53 +08:00
|
|
|
#define NAME_BUF_SIZE 25
|
|
|
|
|
|
|
|
int
|
2020-09-30 22:27:10 +08:00
|
|
|
main(void)
|
2006-08-03 07:41:53 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fid1 = -1;
|
|
|
|
hid_t fid2 = -1;
|
|
|
|
hid_t gid = -1;
|
|
|
|
char filename1[NAME_BUF_SIZE];
|
|
|
|
char filename2[NAME_BUF_SIZE];
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Name the files differently depending on the endianness of this platform */
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
switch (H5Tget_order(H5T_NATIVE_INT)) {
|
|
|
|
case H5T_ORDER_LE:
|
|
|
|
strcpy(filename1, NAME_LE_1);
|
|
|
|
strcpy(filename2, NAME_LE_2);
|
|
|
|
break;
|
|
|
|
case H5T_ORDER_BE:
|
|
|
|
strcpy(filename1, NAME_BE_1);
|
|
|
|
strcpy(filename2, NAME_BE_2);
|
|
|
|
break;
|
|
|
|
case H5T_ORDER_ERROR:
|
|
|
|
case H5T_ORDER_VAX:
|
|
|
|
case H5T_ORDER_MIXED:
|
|
|
|
case H5T_ORDER_NONE:
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
}
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Create the two files */
|
|
|
|
if ((fid1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
|
|
|
goto error;
|
|
|
|
if ((fid2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
|
|
|
goto error;
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Create two groups in the second file */
|
|
|
|
if ((gid = H5Gcreate2(fid2, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
|
|
|
goto error;
|
|
|
|
if ((H5Gclose(gid)) < 0)
|
|
|
|
goto error;
|
|
|
|
if ((gid = H5Gcreate2(fid2, "group/subgroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
|
|
|
goto error;
|
|
|
|
if ((H5Gclose(gid)) < 0)
|
|
|
|
goto error;
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Create an external link in the first file pointing to the group in the second file */
|
|
|
|
if (H5Lcreate_external(filename2, "group", fid1, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0)
|
|
|
|
goto error;
|
2006-08-03 07:41:53 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((H5Fclose(fid1)) < 0)
|
|
|
|
goto error;
|
|
|
|
if ((H5Fclose(fid2)) < 0)
|
|
|
|
goto error;
|
2006-10-02 18:24:03 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
return 0;
|
2006-08-03 07:41:53 +08:00
|
|
|
|
|
|
|
error:
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
H5Fclose(fid1);
|
|
|
|
H5Fclose(fid2);
|
|
|
|
H5Gclose(gid);
|
|
|
|
}
|
|
|
|
H5E_END_TRY
|
|
|
|
return 1;
|
2006-08-03 07:41:53 +08:00
|
|
|
}
|