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 /***********************************************************
15 *
16 * Test program: ttime
17 *
18 * Test the Time Datatype functionality
19 *
20 *************************************************************/
21
22 #include "testhdf5.h"
23
24 #define DATAFILE "ttime.h5"
25 #ifdef NOT_YET
26 #define DATASETNAME "Dataset"
27 #endif /* NOT_YET */
28
29 /****************************************************************
30 **
31 ** test_time_commit(): Test committing time datatypes to a file
32 **
33 ****************************************************************/
34 static void
test_time_commit(void)35 test_time_commit(void)
36 {
37 hid_t file_id, tid; /* identifiers */
38 herr_t status;
39
40 /* Output message about test being performed */
41 MESSAGE(5, ("Testing Committing Time Datatypes\n"));
42
43 /* Create a new file using default properties. */
44 file_id = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
45 CHECK(file_id, FAIL, "H5Fcreate");
46
47 tid = H5Tcopy (H5T_UNIX_D32LE);
48 CHECK(tid, FAIL, "H5Tcopy");
49 status = H5Tcommit2(file_id, "Committed D32LE type", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
50 CHECK(status, FAIL, "H5Tcommit2");
51 status = H5Tclose (tid);
52 CHECK(status, FAIL, "H5Tclose");
53
54 tid = H5Tcopy (H5T_UNIX_D32BE);
55 CHECK(tid, FAIL, "H5Tcopy");
56 status = H5Tcommit2(file_id, "Committed D32BE type", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
57 CHECK(status, FAIL, "H5Tcommit2");
58 status = H5Tclose (tid);
59 CHECK(status, FAIL, "H5Tclose");
60
61 tid = H5Tcopy (H5T_UNIX_D64LE);
62 CHECK(tid, FAIL, "H5Tcopy");
63 status = H5Tcommit2(file_id, "Committed D64LE type", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
64 CHECK(status, FAIL, "H5Tcommit2");
65 status = H5Tclose (tid);
66 CHECK(status, FAIL, "H5Tclose");
67
68 tid = H5Tcopy (H5T_UNIX_D64BE);
69 CHECK(tid, FAIL, "H5Tcopy");
70 status = H5Tcommit2(file_id, "Committed D64BE type", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
71 CHECK(status, FAIL, "H5Tcommit2");
72 status = H5Tclose (tid);
73 CHECK(status, FAIL, "H5Tclose");
74
75 /* Close the file. */
76 status = H5Fclose(file_id);
77 CHECK(status, FAIL, "H5Fclose");
78
79 file_id = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT);
80 CHECK(file_id, FAIL, "H5Fopen");
81
82 tid = H5Topen2(file_id, "Committed D32LE type", H5P_DEFAULT);
83 CHECK(tid, FAIL, "H5Topen2");
84
85 if(!H5Tequal(tid, H5T_UNIX_D32LE))
86 TestErrPrintf("H5T_UNIX_D32LE datatype not found\n");
87
88 status = H5Tclose (tid);
89 CHECK(status, FAIL, "H5Tclose");
90
91 tid = H5Topen2(file_id, "Committed D32BE type", H5P_DEFAULT);
92 CHECK(tid, FAIL, "H5Topen2");
93
94 if(!H5Tequal(tid, H5T_UNIX_D32BE))
95 TestErrPrintf("H5T_UNIX_D32BE datatype not found\n");
96
97 status = H5Tclose (tid);
98 CHECK(status, FAIL, "H5Tclose");
99
100 tid = H5Topen2(file_id, "Committed D64LE type", H5P_DEFAULT);
101 CHECK(tid, FAIL, "H5Topen2");
102
103 if(!H5Tequal(tid, H5T_UNIX_D64LE))
104 TestErrPrintf("H5T_UNIX_D64LE datatype not found");
105
106 status = H5Tclose (tid);
107 CHECK(status, FAIL, "H5Tclose");
108
109 tid = H5Topen2(file_id, "Committed D64BE type", H5P_DEFAULT);
110 CHECK(tid, FAIL, "H5Topen2");
111
112 if(!H5Tequal(tid, H5T_UNIX_D64BE))
113 TestErrPrintf("H5T_UNIX_D64BE datatype not found");
114
115 status = H5Tclose (tid);
116 CHECK(status, FAIL, "H5Tclose");
117
118 status = H5Fclose(file_id);
119 CHECK(status, FAIL, "H5Fclose");
120
121 }
122
123 #ifdef NOT_YET
124 /****************************************************************
125 **
126 ** test_time_io(): Test writing time data to a dataset
127 **
128 ****************************************************************/
129 static void
test_time_io(void)130 test_time_io(void)
131 {
132 hid_t fid; /* File identifier */
133 hid_t dsid; /* Dataset identifier */
134 hid_t tid; /* Datatype identifier */
135 hid_t sid; /* Dataspace identifier */
136 time_t timenow, timethen; /* Times */
137 herr_t status;
138
139 /* Output message about test being performed */
140 MESSAGE(5, ("Testing Committing Time Datatypes\n"));
141
142 /* Create a new file using default properties. */
143 fid = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
144 CHECK(fid, FAIL, "H5Fcreate");
145
146 /* Create a scalar dataspace */
147 sid = H5Screate(H5S_SCALAR);
148 CHECK(sid, FAIL, "H5Screate");
149
150 /* Create a dataset with a time datatype */
151 dsid = H5Dcreate2(fid, DATASETNAME, H5T_UNIX_D32LE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
152 CHECK(dsid, FAIL, "H5Dcreate2");
153
154 /* Initialize time data value */
155 timenow = HDtime(NULL);
156
157 /* Write time to dataset */
158 status = H5Dwrite (dsid, H5T_UNIX_D32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &timenow);
159 CHECK(status, FAIL, "H5Dwrite");
160
161 /* Close objects */
162 status = H5Dclose(dsid);
163 CHECK(status, FAIL, "H5Dclose");
164
165 status = H5Sclose(sid);
166 CHECK(status, FAIL, "H5Sclose");
167
168 status = H5Fclose (fid);
169 CHECK(status, FAIL, "H5Fclose");
170
171 /* Open file and dataset, read time back and print it in calendar format */
172 fid = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT);
173 CHECK(fid, FAIL, "H5Fopen");
174
175 dsid = H5Dopen2(fid, DATASETNAME, H5P_DEFAULT);
176 CHECK(dsid, FAIL, "H5Dopen2");
177
178 tid = H5Dget_type(dsid);
179 CHECK(tid, FAIL, "H5Dget_type");
180 if( H5Tget_class (tid) == H5T_TIME)
181 HDfprintf(stderr,"datatype class is H5T_TIME\n");
182 status = H5Tclose (tid);
183 CHECK(status, FAIL, "H5Tclose");
184
185 status = H5Dread (dsid, H5T_UNIX_D32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &timethen);
186 CHECK(status, FAIL, "H5Dread");
187 HDfprintf(stderr,"time written was: %s\n", HDctime(&timethen));
188
189 status = H5Dclose(dsid);
190 CHECK(status, FAIL, "H5Dclose");
191
192 status = H5Fclose(fid);
193 CHECK(status, FAIL, "H5Fclose");
194
195 }
196 #endif /* NOT_YET */
197
198 /****************************************************************
199 **
200 ** test_time(): Main time datatype testing routine.
201 **
202 ****************************************************************/
203 void
test_time(void)204 test_time(void)
205 {
206 /* Output message about test being performed */
207 MESSAGE(5, ("Testing Time Datatypes\n"));
208
209 test_time_commit(); /* Test committing time datatypes to a file */
210 #ifdef NOT_YET
211 test_time_io(); /* Test writing time data to a dataset */
212 #endif /* NOT_YET */
213
214 } /* test_time() */
215
216
217 /*-------------------------------------------------------------------------
218 * Function: cleanup_time
219 *
220 * Purpose: Cleanup temporary test files
221 *
222 * Return: none
223 *
224 * Programmer: Quincey Koziol
225 * October 19, 2000
226 *
227 * Modifications:
228 *
229 *-------------------------------------------------------------------------
230 */
231 void
cleanup_time(void)232 cleanup_time(void)
233 {
234 HDremove(DATAFILE);
235 }
236
237