FiberBundleHDF5  FiberHDF5 Documentation, Revision 2026
High-Performance Fiber Bundle Data Model for Scientific Visualization
Loading...
Searching...
No Matches
F5Bslice.c
Go to the documentation of this file.
1#include "hdf5inc.h"
2#include <string.h>
3
4#include "F5B.h"
5#include "F5A.h"
6#include "F5defs.h"
7#include "F5X.h"
8#include "F5private.h"
9
11{ "time", "Time", "TIME", 0 };
12
14{
15 const char**time_attribs;
16 hid_t what;
17 double*t, nearest_t;
18};
19
20static herr_t slice_iter (hid_t loc_id, const char *name, void *opdata)
21{
22struct slice_info*si = (struct slice_info*)opdata;
23hid_t gid = H5Gopen2(loc_id, name, H5P_DEFAULT );
24const char**s;
25
26 for(s=si->time_attribs; *s; s++)
27 {
28 hid_t attr_id;
29 double t = 0;
30
31 attr_id = F5Atry_to_open(gid, *s);
32 if (attr_id<0)
33 continue;
34
35 if (F_H5Aread(attr_id, H5T_NATIVE_DOUBLE, &t, *s)<0)
36 {
37 H5Aclose(attr_id);
38 continue;
39 }
40 H5Aclose(attr_id);
41/* printf("SLICE: Have T=%lg, Query: T=%lg\n", t, *si->t);*/
42 if (t>(*si->t) )
43 {
44 return 1;
45 }
46 si->nearest_t = t;
47 break;
48 }
49 if (si->what>0)
50 H5Gclose(si->what);
51 si->what = gid;
52 return 0;
53}
54
55hid_t F5BgetMostRecentSlice(double*t, hid_t loc_id, const char**time_attribs)
56{
57struct slice_info si = { 0, -1, 0 };
59 si.t = t;
60
61 H5Giterate(loc_id, ".", 0, slice_iter, &si);
62
63 if (si.what>0)
64 *t = si.nearest_t;
65
66 return si.what;
67}
68
69
70hid_t F5BgetMostRecentFileSlice(double t, const char*filename)
71{
72hid_t fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
73
74 if (fid<0)
75 return -1;
76
78
79 H5Fclose(fid);
80
81 if (slice_id>0)
82 {
83 printf("F5Bslice: got data slice for T=%lg\n", t);
84 }
85
86 return slice_id;
87}
88}
89
90char*F5I_timegroup(const double*time, char*destbuf, size_t len)
91{
92int precision = 10;
93char *result = destbuf;
94 if (!time)
95 {
96 return strncpy(destbuf, FIBER_STATIC_DATA, len);
97 }
98
99#ifdef _MSC_VER
100 _snprintf
101#else
102 snprintf
103#endif
104 (destbuf,len,"t=%0*.*f", 2*precision, precision, *time);
105
106/*
107 (destbuf,len,"t=%0*.*lf", 2*precision, precision, *time);
108*/
109
110
111/* printf("TIME %lg -->\n", time); */
112 return result;
113}
114
115int F5setTimeUnit(hid_t file_id, const F5_TimeParameter*TP)
116{
117/* TODO:
118 Create a type which is convertible to "double",
119 Open group FIBER_HDF5_GLOBAL_CHARTS
120 Commit the type to this group
121 Add attributes to this group which describe the type's
122 unit
123 Close it
124
125 And do all that with checking whether such an type
126 already exists before.
127
128 Only the offset, TimeSemantics and comment members from
129 the F5_TimeParameter structure are used.
130 */
131 return 0;
132}
133
134hid_t F5Bappend_timeslice(hid_t file_id, const F5_TimeParameter*time)
135{
136 /* ...TODO: Coding....... */
137 return F5Bappend_slice(file_id, &time->value);
138}
139
140hid_t F5Bappend_slice(hid_t file_id, const double*time)
141{
142char timename[128];
143hid_t Slice_hid = F5Gappend(file_id, F5I_timegroup(time, timename, sizeof(timename) ));
144
145 if (time)
146 F5printf(30," -- F5Bappend_slice(%lg)", *time);
147 else
148 F5printf(30," -- F5Bappend_slice( <static> )");
149
150 if (time)
151 {
152 /* TODO: add time slice attribute ONLY if it is not yet
153 // there. Think about: what if it is there, but is
154 // not consistent?
155 */
156 hid_t space_hid = H5Screate(H5S_SCALAR);
157 hid_t attr_hid = F5Aappend(Slice_hid, FIBER_HDF5_TIME_ATTRIB , H5T_NATIVE_DOUBLE, space_hid, H5P_DEFAULT);
158 H5Awrite(attr_hid, H5T_NATIVE_DOUBLE, time);
159 H5Sclose(space_hid);
160 H5Aclose(attr_hid);
161 }
162 return Slice_hid;
163}
164
165/*********** TIMETABLE FUNCTIONS *************/
166
168{
169hid_t dtype_id = H5Tcreate( H5T_COMPOUND, sizeof(TimeTableEntry) );
170 {
171 hid_t string_dtype_id = H5Tcreate( H5T_STRING, F5_TIMESLICE_NAME_LENGTH );
172 H5Tinsert( dtype_id, FIBER_HDF5_TIME_ATTRIB, 0, H5T_NATIVE_DOUBLE);
173 H5Tinsert( dtype_id, "F5::SliceGroup", sizeof(double), string_dtype_id );
174 H5Tclose( string_dtype_id );
175 }
176 return dtype_id;
177}
178
179static int F5check_timetable_Type(hid_t type_id)
180{
181 if (type_id<0)
182 return 0;
183
184 if (H5Tget_class(type_id) == H5T_COMPOUND)
185 {
186 if (H5Tget_nmembers( type_id) == 2)
187 return 1;
188 }
189 return 0;
190}
191
192hid_t F5Bget_file_timetable_type(hid_t loc_id)
193{
194hid_t timetable_type_id;
195
196 H5E_BEGIN_TRY
197 timetable_type_id = H5Topen2( loc_id, F5_TIMETABLE_NAME, H5P_DEFAULT );
198 H5E_END_TRY
199 if (F5check_timetable_Type(timetable_type_id) )
200 {
201 return timetable_type_id;
202 }
203
204 timetable_type_id = F5Bcreate_timetable_type();
205
206 H5Tcommit2( loc_id, F5_TIMETABLE_NAME, timetable_type_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
207
208 return timetable_type_id;
209}
210
211static hid_t F5Bcreate_timetable_dataset(hid_t loc_id, hid_t dtype_location_id, hsize_t init_dims)
212{
213hsize_t maximum_dims = H5S_UNLIMITED;
214hid_t space_id = H5Screate_simple( 1, &init_dims, &maximum_dims );
215
216hid_t dset_creation_property_id = H5Pcreate( H5P_DATASET_CREATE );
217
218hid_t dataset_id;
219
220hsize_t chunk_length = 1024;
221
222hid_t dtype_id = F5Bget_file_timetable_type( dtype_location_id );
223
224 if (dtype_id<0)
225 {
226 return -1;
227 }
228
229 H5Pset_chunk(dset_creation_property_id, 1, &chunk_length);
230 H5E_BEGIN_TRY
231 dataset_id = H5Dcreate2( loc_id, F5_TIMETABLE_NAME,
232 dtype_id,
233 space_id,
234 H5P_DEFAULT,
235 dset_creation_property_id,
236 H5P_DEFAULT);
237 H5E_END_TRY
238
239 H5Pclose( dset_creation_property_id );
240 H5Sclose( space_id );
241 H5Tclose( dtype_id );
242
243 return dataset_id;
244}
245
246/*
247int F5Binit_timetable(hid_t loc_id, hid_t dtype_id)
248{
249hid_t timetable_dataset_id
250 =
251 F5Bcreate_timetable_dataset(loc_id, dtype_id, 0);
252
253 if (timetable_dataset_id<0)
254 return 0;
255
256 H5Dclose(timetable_dataset_id);
257 return 1;
258}
259*/
260
261hsize_t F5Bappend_timetable(hid_t loc_id, hid_t dtype_location_id,
262 const TimeTableEntry*TTE,
263 hsize_t append_dims)
264{
265hid_t mem_space_id;
266hid_t dataset_id;
267hsize_t size = 0;
268hsize_t current_dim = 0;
269
270 if (!TTE) return 0;
271
272 mem_space_id = H5Screate_simple( 1, &append_dims, NULL);
273
274 H5E_BEGIN_TRY
275 dataset_id = H5Dopen2( loc_id, F5_TIMETABLE_NAME, H5P_DEFAULT);
276 H5E_END_TRY
277
278/* printf("F5Bappend_timetable(,,TimeTableEntry={%g,%s},%d)\n",
279 TTE->TimeValue, TTE->TimesliceName,
280 (int)append_dims );
281 fflush(stdout);
282*/
283 if (dataset_id<=0)
284 {
285 dataset_id =
286 F5Bcreate_timetable_dataset(loc_id, dtype_location_id, append_dims);
287
288 if (dataset_id<=0)
289 return 0;
290
291 {
292 hid_t timetable_type_id = F5Bcreate_timetable_type();
293 H5Dwrite( dataset_id, timetable_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, TTE);
294 H5Tclose( timetable_type_id );
295 }
296 H5Dclose( dataset_id );
297 return append_dims;
298 }
299
300 {
301 hid_t current_file_space_id = H5Dget_space(dataset_id );
302 H5Sget_simple_extent_dims( current_file_space_id, &current_dim, NULL);
303 H5Sclose( current_file_space_id );
304 }
305
306 size = append_dims + current_dim;
307 H5Dset_extent( dataset_id, &size);
308
309 {
310 hid_t file_space_id = H5Dget_space(dataset_id );
311 H5Sselect_hyperslab(file_space_id, H5S_SELECT_SET, &current_dim, NULL, &append_dims, NULL);
312
313/* printf("F5Bappend_timetable(): New extent %d, insert at %d, count = %d\n",
314 (int)size, (int)current_dim, (int)append_dims);
315*/
316 hid_t timetable_type_id = F5Bcreate_timetable_type();
317 H5Dwrite( dataset_id, timetable_type_id, mem_space_id, file_space_id, H5P_DEFAULT, TTE);
318 H5Tclose( timetable_type_id );
319 H5Sclose( file_space_id );
320 }
321
322 H5Dclose( dataset_id );
323
324 return size;
325}
326
327
328hsize_t F5Bget_timetable_size(hid_t loc_id)
329{
330hid_t dataset_id;
331hsize_t current_dim = 0;
332
333 H5E_BEGIN_TRY
334 dataset_id = H5Dopen2( loc_id, F5_TIMETABLE_NAME, H5P_DEFAULT);
335 H5E_END_TRY
336
337 if (dataset_id<=0)
338 return 0;
339
340 {
341 hid_t timetable_type_id = H5Dget_type( dataset_id );
342 int type_is_ok = F5check_timetable_Type(timetable_type_id);
343 H5Tclose( timetable_type_id );
344 if (!type_is_ok)
345 {
346 H5Dclose( dataset_id );
347 F5printf(-1, "WARNING: Invalid Time Table time detected!");
348 return 0;
349 }
350 }
351
352
353 {
354 hid_t current_file_space_id = H5Dget_space(dataset_id );
355 H5Sget_simple_extent_dims( current_file_space_id, &current_dim, NULL);
356 H5Sclose( current_file_space_id );
357 }
358
359
360 H5Dclose( dataset_id );
361
362 return current_dim;
363}
364
365
366hsize_t F5Bread_timetable(hid_t loc_id,
367 TimeTableEntry*TTE,
368 hsize_t table_size)
369{
370hid_t dataset_id;
371
372 H5E_BEGIN_TRY
373 dataset_id = H5Dopen2( loc_id, F5_TIMETABLE_NAME, H5P_DEFAULT);
374 H5E_END_TRY
375
376 if (dataset_id<=0)
377 return 0;
378
379
380 {
381 hid_t space_id = H5Dget_space(dataset_id );
382 hsize_t current_dim = 0;
383 H5Sget_simple_extent_dims( space_id, &current_dim, NULL);
384 H5Sclose( space_id );
385
386 if (table_size<current_dim)
387 {
388 H5Dclose( dataset_id );
389 return 0;
390 }
391
392 {
393 hid_t dtype_id = F5Bcreate_timetable_type();
394
395 H5Dread( dataset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, TTE);
396 H5Tclose( dtype_id );
397 }
398
399 H5Dclose( dataset_id );
400 return current_dim;
401 }
402}
hid_t F5Atry_to_open(hid_t location, const char *name)
Definition F5A.c:23
hid_t F5Aappend(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t create_plist)
Definition F5A.c:9
struct _F5_TimeParameter F5_TimeParameter
Definition F5B.h:65
F5_API const char * F5_default_time_attrib_names[]
Definition F5Bslice.c:10
#define F5_TIMESLICE_NAME_LENGTH
Definition F5B.h:67
hid_t F5Bget_file_timetable_type(hid_t loc_id)
Definition F5Bslice.c:192
H5Tclose(type_id)
name
Definition F5P.c:82
#define FIBER_STATIC_DATA
Definition F5defs.h:42
#define F5_TIMETABLE_NAME
Definition F5defs.h:150
#define FIBER_HDF5_TIME_ATTRIB
Definition F5defs.h:45
herr_t F_H5Aread(hid_t attr_id, hid_t mem_type_id, void *buf, const char *name)
Definition F5private.c:332
#define F5printf(verbosity,...)
Definition F5private.h:60
hid_t F5Bcreate_timetable_type()
Definition F5Bslice.c:167
hsize_t F5Bget_timetable_size(hid_t loc_id)
Definition F5Bslice.c:328
hid_t F5Bappend_slice(hid_t file_id, const double *time)
Definition F5Bslice.c:140
hsize_t F5Bappend_timetable(hid_t loc_id, hid_t dtype_location_id, const TimeTableEntry *TTE, hsize_t append_dims)
Definition F5Bslice.c:261
int F5setTimeUnit(hid_t file_id, const F5_TimeParameter *TP)
Definition F5Bslice.c:115
hid_t F5BgetMostRecentSlice(double *t, hid_t loc_id, const char **time_attribs)
Definition F5Bslice.c:55
hsize_t F5Bread_timetable(hid_t loc_id, TimeTableEntry *TTE, hsize_t table_size)
Definition F5Bslice.c:366
hid_t F5BgetMostRecentFileSlice(double t, const char *filename)
Definition F5Bslice.c:70
struct _TimeTableEntry TimeTableEntry
hid_t F5Bappend_timeslice(hid_t file_id, const F5_TimeParameter *time)
Definition F5Bslice.c:134
char * F5I_timegroup(const double *time, char *destbuf, size_t len)
Definition F5Bslice.c:90
#define H5Gclose(x)
Definition F5X.h:144
hid_t F5Gappend(hid_t loc_id, const char *name)
Definition F5X.c:59
double value
Definition F5B.h:47
hid_t what
Definition F5Bslice.c:16
double * t
Definition F5Bslice.c:17
const char ** time_attribs
Definition F5Bslice.c:15
double nearest_t
Definition F5Bslice.c:17