2003-04-01 01:59:04 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* 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. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2000-11-10 05:47:59 +08:00
|
|
|
/*
|
|
|
|
* Purpose: Create a two datasets, one with a compound datatypes with array
|
|
|
|
* fields (which should be stored in the newer version (version 2)) and
|
|
|
|
* one with an array datatype.
|
|
|
|
* This program is used to create the test file `tarrnew.h5' which has a
|
|
|
|
* datatypes stored in the newer (version 2) style in the object headers.
|
|
|
|
* To build the test file, this program MUST be compiled and linked with
|
|
|
|
* the hdf5-1.3+ series of libraries and the generated test file must be
|
|
|
|
* put into the 'test' directory in the 1.2.x branch of the library.
|
|
|
|
* The test file should be generated on a little-endian machine with
|
|
|
|
* 16-bit shorts, 32-bit floats, 32-bit ints and 64-bit doubles.
|
|
|
|
*/
|
2001-04-04 02:09:16 +08:00
|
|
|
#include "hdf5.h"
|
2000-11-10 05:47:59 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define TESTFILE "tarrnew.h5"
|
2000-11-10 05:47:59 +08:00
|
|
|
|
|
|
|
/* 1-D array datatype */
|
2020-09-30 22:27:10 +08:00
|
|
|
#define ARRAY1_RANK 1
|
2000-11-10 05:47:59 +08:00
|
|
|
#define ARRAY1_DIM1 4
|
|
|
|
|
|
|
|
/* 2-D dataset with fixed dimensions */
|
2020-09-30 22:27:10 +08:00
|
|
|
#define SPACE1_RANK 2
|
|
|
|
#define SPACE1_DIM1 8
|
|
|
|
#define SPACE1_DIM2 9
|
2000-11-10 05:47:59 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: main
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose:
|
2000-11-10 05:47:59 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Return: Success:
|
2000-11-10 05:47:59 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Failure:
|
2000-11-10 05:47:59 +08:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
typedef struct { /* Typedef for compound datatype */
|
|
|
|
short i;
|
|
|
|
float f[ARRAY1_DIM1];
|
|
|
|
long l[ARRAY1_DIM1];
|
2000-11-10 05:47:59 +08:00
|
|
|
double d;
|
|
|
|
} s3_t;
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t file, space, type, arr_type, dset;
|
|
|
|
hsize_t tdims1[] = {ARRAY1_DIM1};
|
|
|
|
hsize_t cur_dim[SPACE1_RANK] = {SPACE1_DIM1, SPACE1_DIM2};
|
|
|
|
herr_t ret; /* Generic return value */
|
2000-11-10 05:47:59 +08:00
|
|
|
|
|
|
|
/* Create the file */
|
|
|
|
file = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (file < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("file<0!\n");
|
|
|
|
|
|
|
|
/* Create the dataspace (for both datasets) */
|
|
|
|
space = H5Screate_simple(SPACE1_RANK, cur_dim, NULL);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (space < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("space<0!\n");
|
|
|
|
|
|
|
|
/* Create the compound datatype with array fields */
|
|
|
|
type = H5Tcreate(H5T_COMPOUND, sizeof(s3_t));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (type < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("type<0!\n");
|
|
|
|
|
|
|
|
/* Insert integer field */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tinsert(type, "i", HOFFSET(s3_t, i), H5T_NATIVE_SHORT);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 1 insert<0!\n");
|
|
|
|
|
2021-12-07 22:27:29 +08:00
|
|
|
/* Create the array datatype */
|
[svn-r14212] Description:
Make H5Tarray_create() and H5Tget_array_dims() versioned, and drop the
"perm" parameter from the '2' versions.
Shift internal library usage to '2' versions.
Add simple regression tests for '1' versions.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-19 06:02:19 +08:00
|
|
|
arr_type = H5Tarray_create2(H5T_NATIVE_FLOAT, ARRAY1_RANK, tdims1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (arr_type < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("arr_type<0!\n");
|
|
|
|
|
|
|
|
/* Insert float array field */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tinsert(type, "f", HOFFSET(s3_t, f), arr_type);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 3 insert<0!\n");
|
|
|
|
|
|
|
|
/* Close array datatype */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tclose(arr_type);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 3 array close<0!\n");
|
|
|
|
|
2021-12-07 22:27:29 +08:00
|
|
|
/* Create the array datatype */
|
[svn-r14212] Description:
Make H5Tarray_create() and H5Tget_array_dims() versioned, and drop the
"perm" parameter from the '2' versions.
Shift internal library usage to '2' versions.
Add simple regression tests for '1' versions.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-19 06:02:19 +08:00
|
|
|
arr_type = H5Tarray_create2(H5T_NATIVE_LONG, ARRAY1_RANK, tdims1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (arr_type < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("arr_type<0!\n");
|
|
|
|
|
|
|
|
/* Insert long array field */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tinsert(type, "l", HOFFSET(s3_t, l), arr_type);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 3 insert<0!\n");
|
|
|
|
|
|
|
|
/* Close array datatype */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tclose(arr_type);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 3 array close<0!\n");
|
|
|
|
|
|
|
|
/* Insert double field */
|
2020-09-30 22:27:10 +08:00
|
|
|
ret = H5Tinsert(type, "d", HOFFSET(s3_t, d), H5T_NATIVE_DOUBLE);
|
|
|
|
if (ret < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("field 4 insert<0!\n");
|
|
|
|
|
|
|
|
/* Create the dataset with compound array fields */
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
dset = H5Dcreate2(file, "Dataset1", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (dset < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("dset<0!\n");
|
|
|
|
H5Dclose(dset);
|
|
|
|
|
|
|
|
/* Close compound datatype */
|
|
|
|
H5Tclose(type);
|
|
|
|
|
|
|
|
/* Create the compound datatype with array fields */
|
[svn-r14212] Description:
Make H5Tarray_create() and H5Tget_array_dims() versioned, and drop the
"perm" parameter from the '2' versions.
Shift internal library usage to '2' versions.
Add simple regression tests for '1' versions.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-19 06:02:19 +08:00
|
|
|
type = H5Tarray_create2(H5T_NATIVE_INT, ARRAY1_RANK, tdims1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (type < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("type<0!\n");
|
|
|
|
|
|
|
|
/* Create the dataset with array datatype */
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
dset = H5Dcreate2(file, "Dataset2", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (dset < 0)
|
2000-11-10 05:47:59 +08:00
|
|
|
printf("dset<0!\n");
|
|
|
|
H5Dclose(dset);
|
|
|
|
|
|
|
|
/* Close array datatype */
|
|
|
|
H5Tclose(type);
|
|
|
|
|
|
|
|
H5Sclose(space);
|
|
|
|
H5Fclose(file);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|