1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 #include "hdf5.h"
15 #include "hdf5_hl.h"
16
17
18 #define RANK 2
19 #define DIM_DATA 12
20 #define DIM1_SIZE 3
21 #define DIM2_SIZE 4
22 #define DIM0 0
23 #define DIM1 1
24
25 #define DSET_NAME "Mydata"
26 #define DS_1_NAME "Yaxis"
27 #define DS_2_NAME "Xaxis"
28
main(void)29 int main(void)
30 {
31
32 hid_t fid; /* file ID */
33 hid_t did; /* dataset ID */
34 hid_t dsid; /* DS dataset ID */
35 int rank = RANK; /* rank of data dataset */
36 int rankds = 1; /* rank of DS dataset */
37 hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
38 int buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; /* data of data dataset */
39 hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */
40 hsize_t s2_dim[1] = {DIM2_SIZE}; /* size of DS 2 dataset */
41 float s1_wbuf[DIM1_SIZE] = {10,20,30}; /* data of DS 1 dataset */
42 int s2_wbuf[DIM2_SIZE] = {10,20,50,100}; /* data of DS 2 dataset */
43
44
45 /* create a file using default properties */
46 if ((fid=H5Fcreate("ex_ds1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
47 goto out;
48
49 /* make a dataset */
50 if (H5LTmake_dataset_int(fid,DSET_NAME,rank,dims,buf)<0)
51 goto out;
52
53 /* make a DS dataset for the first dimension */
54 if (H5LTmake_dataset_float(fid,DS_1_NAME,rankds,s1_dim,s1_wbuf)<0)
55 goto out;
56
57 /* make a DS dataset for the second dimension */
58 if (H5LTmake_dataset_int(fid,DS_2_NAME,rankds,s2_dim,s2_wbuf)<0)
59 goto out;
60
61
62 /*-------------------------------------------------------------------------
63 * attach the DS_1_NAME dimension scale to DSET_NAME at dimension 0
64 *-------------------------------------------------------------------------
65 */
66
67 /* get the dataset id for DSET_NAME */
68 if ((did = H5Dopen2(fid,DSET_NAME, H5P_DEFAULT))<0)
69 goto out;
70
71 /* get the DS dataset id */
72 if ((dsid = H5Dopen2(fid,DS_1_NAME, H5P_DEFAULT))<0)
73 goto out;
74
75 /* attach the DS_1_NAME dimension scale to DSET_NAME at dimension index 0 */
76 if (H5DSattach_scale(did,dsid,DIM0)<0)
77 goto out;
78
79 /* close DS id */
80 if (H5Dclose(dsid)<0)
81 goto out;
82
83 /*-------------------------------------------------------------------------
84 * attach the DS_2_NAME dimension scale to DSET_NAME
85 *-------------------------------------------------------------------------
86 */
87
88 /* get the DS dataset id */
89 if ((dsid = H5Dopen2(fid,DS_2_NAME, H5P_DEFAULT))<0)
90 goto out;
91
92 /* attach the DS_2_NAME dimension scale to DSET_NAME as the 2nd dimension (index 1) */
93 if (H5DSattach_scale(did,dsid,DIM1)<0)
94 goto out;
95
96 /* close DS id */
97 if (H5Dclose(dsid)<0)
98 goto out;
99
100 /* close file */
101 H5Fclose(fid);
102
103 return 0;
104
105 out:
106 printf("Error on return function...Exiting\n");
107 return 1;
108
109 }
110
111
112
113