FiberBundleHDF5  FiberHDF5 Documentation, Revision 2026
High-Performance Fiber Bundle Data Model for Scientific Visualization
Loading...
Searching...
No Matches
F5Fmeta.c
Go to the documentation of this file.
1#include "F5Fmeta.h"
2#include "F5X.h"
3#include "F5A.h"
4#include "F5private.h"
5#include "F5Bchart.h"
6#include "F5L.h"
7#include "F5coordinates.h"
8/* #if defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__) */
9#include <stdlib.h>
10/* #else */
11/* #include <malloc.h> */
12/* #endif */
13#include <string.h>
14#include <assert.h>
15
16
17#pragma message "This function is conflicting with the F5F API and will fail in common situations. See source comments for details."
18/*
19 This function is problematic. What does it mean to have a group or dataset within
20 a field? This is a highly internal semantics that should not be exposed to the user.
21 In particular, a field can be a dataset itself, this is the default case, so this
22 function will certainly fail in the default case.
23
24 (mr) this was only a clean up of quite some existing copy&paste code. I will rework stuff to have it work as it should.
25 */
26F5_API int F5Fopen_group_or_dataset( F5Path*f, const char* name, hid_t*gid, hid_t*did )
27{
28 if (!f) return 0;
29
30H5E_BEGIN_TRY
31 *gid = H5Gopen2(f->Field_hid, name, H5P_DEFAULT);
32 if (*gid<0)
33 {
34 F5printf(55,"F5Fopen_group_or_dataset() no group, trying for a dataset!");
35 *did = H5Dopen2(f->Field_hid, name, H5P_DEFAULT);
36 if(*did<0)
37 {
38 F5printf(55,"F5Fopen_group_or_dataset() no dataset found");
39 return 0;
40 }
41 else
42 F5printf(55,"F5Fopen_group_or_dataset() Yay dataset found!");
43 }
44 else
45 F5printf(55,"F5Fopen_group_or_dataset() Yay! found group!");
46H5E_END_TRY
47
48 return 1;
49}
50
51#pragma message "This function is contradicting and complicating the F5F API and thus deprecated. See source comments for details."
52/*
53F5F* functions are supposed to operate on F5Path objects only. A field is identified in a F5Path object via its Field identifier.
54It can be either a group or a dataset, being completely transparent to the user.
55Consequently, any operations on the Field identifier such as opening an attribute are generic and can be done on the Field identifier itself.
56When opening an attribute, there is no need to distinguish between group and dataset identifiers.
57Separating between them is just an artificial complication that the F5F API intended to hide from the user.
58 */
59F5_API int F5Fopen_group_or_dataset_attribute( F5Path*f, const char* attribute_name, hid_t gid, hid_t did, hsize_t N, hid_t*attr_id, hid_t*space_id )
60{
61 if( !f ) return 0;
62
63H5E_BEGIN_TRY
64 *attr_id = F5Aopen_name(gid>0?gid:did, attribute_name);
65H5E_END_TRY
66
67 if (*attr_id<0)
68 {
69 F5printf(1,"F5Fget_fragment_attribute() could not find range attribute!");
70// if (gid>0) H5Gclose(gid);
71// if (did>0) H5Dclose(did);
72 return 0;
73 }
74 *space_id = H5Aget_space(*attr_id);
75 assert( *space_id >0);
76 if (H5Sget_simple_extent_npoints(*space_id) != N)
77 {
78// if (gid>0) H5Gclose(gid);
79// if (did>0) H5Dclose(did);
80 H5Aclose(*attr_id);
81 H5Sclose(*space_id);
82 F5printf(1,"F5Fget_fragment_attribute() found range attribute with not N elements!");
83 return 0;
84 }
85
86 return 1;
87}
88
89/*
90F5_API hsize_t F5Fget_attribut_elements( F5Path*f, const char* attribute_name, hid_t gid, hid_t did, hid_t*attr_id, hid_t*space_id )
91{
92 int N;
93 if( !f ) return 0;
94
95H5E_BEGIN_TRY
96 *attr_id = F5Aopen_name(gid>0?gid:did, attribute_name);
97H5E_END_TRY
98
99 if (*attr_id<0)
100 {
101 F5printf(1,"F5Fget_fragment_attribute() could not find range attribute!");
102 return -1;
103 }
104 *space_id = H5Aget_space(*attr_id);
105 assert( *space_id >0);
106
107 N = H5Sget_simple_extent_npoints(*space_id);
108
109 H5Aclose(*attr_id);
110 H5Sclose(*space_id);
111
112 return N;
113}
114*/
115
116#pragma message "This function is conflicting with the F5F API, see comments for F5Fopen_group_or_dataset_attribute()"
117F5_API int F5Fopen_or_create_group_or_dataset_attribute( F5Path*f, const char* attribute_name, hid_t gid, hid_t did, hsize_t N, hid_t type_id, int force, hid_t*space_id, hid_t*attr_id )
118{
119 if( !f ) return 0;
120
121 H5E_BEGIN_TRY
122 *attr_id = H5Acreate2( gid>0? gid : did,
123 attribute_name, type_id, *space_id,
124 H5P_DEFAULT, H5P_DEFAULT );
125 H5E_END_TRY
126
127 if (*attr_id < 0 && force == 0)
128 {
129 F5printf(55,"F5Fopen_or_create_group_or_dataset_attribute() Could not set %s attribute, might already exist.", attribute_name);
130 H5Sclose(*space_id);
131 H5Tclose(type_id);
132// if (gid>0) H5Gclose(gid);
133// if (did>0) H5Dclose(did);
134 return 0;
135 }
136 else if( *attr_id<0 ) // try for existing attribute
137 {
138 F5printf(1,"F5Fopen_or_create_group_or_dataset_attribute() Could not create attribute.");
139 return F5Fopen_group_or_dataset_attribute( f, attribute_name, gid, did, N, attr_id, space_id );
140 }
141
142 return 1;
143}
144
145/*
146 This function does nothing but to allocate and copy data uneccesarily.
147 The caller can just call the HDF5 API directly to achieve the same.
148 This function does not provide any benefits over direct call, only slows down
149 execution by additional memory allocation and copying data.
150 Furthermore it does not operate on F5Path objects and thus does not deserve the F5F prefix.
151 */
152F5_API int F5Fread_attr_data( void*data, hsize_t N, hid_t type_id, hid_t attr_id, const char*attribute_name )
153{
154size_t type_size;
155char *buf;
156
157 type_size = H5Tget_size(type_id);
158 buf = (char*)malloc( N * type_size );
159 F_H5Aread( attr_id, type_id, buf, attribute_name );
160
161 memcpy( data, buf, N * type_size );
162
163 free(buf);
164
165 return 1;
166}
167
168/*
169 Same comment as for F5Fwrite_attr_data()
170*/
171F5_API int F5Fwrite_attr_data( const void*data, hsize_t N, hid_t type_id, hid_t attr_id, const char*attribute_name )
172{
173size_t type_size;
174char *buf;
175
176 type_size = H5Tget_size(type_id) ;
177 buf =(char*)malloc( N * type_size );
178
179 memcpy(buf, data, N * type_size);
180// memcpy(buf , data, type_size);
181// memcpy(buf+type_size, value2, type_size);
182
183 H5Awrite(attr_id, type_id, buf );
184 free(buf);
185
186 return 1;
187}
188
189
190
191F5_API int F5Fget_attribute( F5Path*f, const char*attribute_name,
192 void*data, hsize_t N, hid_t mem_type_id )
193{
194hid_t attr_id, space_id, type_id;
195
196 if (!f) return 0;
197
198 if( !F5Fopen_group_or_dataset_attribute( f, attribute_name, f->Field_hid, 0, N, &attr_id, &space_id ) )
199 return 0;
200
201 if (mem_type_id)
202 type_id = mem_type_id;
203 else
204 type_id = H5Aget_type(attr_id);
205
206 F5Fread_attr_data( data, N, type_id, attr_id, attribute_name );
207
208 H5Aclose(attr_id);
209 H5Sclose(space_id);
210 if (!mem_type_id)
211 H5Tclose(type_id);
212
213 return 1;
214}
215
216F5_API int F5Fset_attribute( F5Path*f, const char*attribute_name,
217 const void*data, hsize_t N, hid_t mem_type_id, int force )
218{
219const hsize_t dims = N;
220hid_t attr_id, type_id, space_id;
221
222 if (!f)
223 {
224 F5printf(5,"F5Fset_attribute() got NULL F5Path, no range written!");
225 return 0;
226 }
227 if (f->Field_hid<1)
228 {
229 F5printf(5,"F5Fset_attribute() F5Path has no field ID, no range written!");
230 return 0;
231 }
232
233 space_id= H5Screate_simple(1, &dims, &dims );
234
235 if (mem_type_id)
236 type_id = mem_type_id;
237 else
238 type_id = H5Aget_type(attr_id); // this code CANNOT work because attr_id has not been initialized!!!
239
240/*
241 This is an extremely complicated workaround due to the wrong design of function F5Fopen_or_create_group_or_dataset_attribute().
242 All what is required here is to use the Field_id in the F5Path object and to write an attribute using this Field_id, regardless
243 what type it is.
244 */
245 if( F5Fis_group( f ) )
246 {
247 if( !F5Fopen_or_create_group_or_dataset_attribute( f, attribute_name, f->Field_hid, 0, N, type_id, force, &space_id, &attr_id ) )
248 return 0;
249 }
250 else
251 {
252 if( !F5Fopen_or_create_group_or_dataset_attribute( f, attribute_name, 0, f->Field_hid, N, type_id, force, &space_id, &attr_id ) )
253 return 0;
254 }
255
256 F5Fwrite_attr_data( data, N, type_id, attr_id, attribute_name );
257
258 H5Aclose(attr_id);
259 H5Sclose(space_id);
260
261 if (!mem_type_id)
262 H5Tclose(type_id);
263
264 return 1;
265}
266
267F5_API int F5Fget_fragment_attribute( F5Path*f, const char*fragment_name, const char*attribute_name,
268 void*data, hsize_t N, hid_t mem_type_id )
269{
270hid_t attr_id,
271 space_id,
272 type_id,
273 gid = -1, did = -1;
274
275 F5Fopen_group_or_dataset( f, fragment_name, &gid, &did );
276
277 if( !F5Fopen_group_or_dataset_attribute(f, attribute_name, gid, did, N, &attr_id, &space_id) )
278 return 0;
279
280 if (mem_type_id)
281 type_id = mem_type_id;
282 else
283 type_id = H5Aget_type(attr_id);
284
285 F5Fread_attr_data( data, N, type_id, attr_id, attribute_name );
286
287 if (gid>0) H5Gclose(gid);
288 if (did>0) H5Dclose(did);
289 H5Aclose(attr_id);
290 H5Sclose(space_id);
291
292 if (!mem_type_id)
293 H5Tclose(type_id);
294
295 F5printf(55,"F5Fget_fragment_attribute() returning normally!");
296
297 return 1;
298}
299
300F5_API int F5Fset_fragment_attribute( F5Path*f, const char*fragment_name, const char*attribute_name,
301 const void*data, const hsize_t N, hid_t mem_type_id, int force )
302{
303const hsize_t dims = N;
304hid_t attr_id,
305 type_id,
306 space_id,
307 gid = -1, did = -1;
308
309 if (!f)
310 {
311 F5printf(5,"F5Fset_fragment_attribute() got NULL F5Path, no range written!");
312 return 0;
313 }
314 if (f->Field_hid<1)
315 {
316 F5printf(5,"F5Fset_fragment_attribute() F5Path has no field ID, no range written!");
317 return 0;
318 }
319
320 space_id= H5Screate_simple(1, &dims, &dims );
321 type_id = mem_type_id;
322
323 if( !F5Fopen_group_or_dataset( f, fragment_name, &gid, &did ) )
324 {
325 F5printf(50,"F5Fset_fragment_attribute() Could not set %s attribute, fragment %s does not exist.",
326 attribute_name, fragment_name);
327 H5Sclose(space_id);
328 H5Tclose(type_id);
329 return 0;
330 }
331
332 if( !F5Fopen_or_create_group_or_dataset_attribute( f, attribute_name, gid, did, N, type_id, force, &space_id, &attr_id ) )
333 return 0;
334
335 F5Fwrite_attr_data( data, N, type_id, attr_id, attribute_name );
336
337 H5Aclose(attr_id);
338 H5Sclose(space_id);
339 if (gid>0) H5Gclose(gid);
340 if (did>0) H5Dclose(did);
341
342 F5printf(55,"F5Fset_fragment_attribute2() returning normally!");
343
344 return 1;
345
346
347 return 1;
348}
349
350F5_API int F5Fset_string_attribute(F5Path*f, const char*fragment_name, const char* attribute_name, const char*text, int force )
351{
352 if (f->Field_hid > 0)
353 {
354 if( fragment_name != NULL )
355 {
356 hid_t type_id = H5Tcopy(H5T_C_S1);
357 hid_t space_id = H5Screate(H5S_SCALAR);
358 hid_t attr_id;
359 size_t size = strlen(text);
360 H5Tset_size(type_id, size);
361 H5Tset_strpad(type_id, H5T_STR_NULLTERM);
362
363 H5E_BEGIN_TRY
364 attr_id = H5Acreate2( f->Field_hid, attribute_name, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT);
365 H5E_END_TRY
366 if (attr_id > 0)
367 {
368 F5printf(50, "F5Fset_string_attribute(): Unit Attribute %s written to %d.",
369 text, (int)f->Field_hid);
370 H5Awrite(attr_id, type_id, text);
371 H5Aclose(attr_id);
372 }
373 else
374 {
375 F5printf(50, "F5Fset_string_attribute(): WARNING Unit Attribute not written to %s/%d.",
376 text, (int)f->Field_hid);
377 }
378
379 H5Sclose(space_id);
380 H5Tclose(type_id);
381 return 1;
382 }
383 else
384 {
385 hid_t type_id = H5Tcopy(H5T_C_S1);
386 hid_t space_id = H5Screate(H5S_SCALAR);
387 hid_t attr_id;
388 size_t size = strlen(text);
389 H5Tset_size(type_id, size);
390 H5Tset_strpad(type_id, H5T_STR_NULLTERM);
391
392 if( F5Fis_group( f ) )
393 {
394 if( !F5Fopen_or_create_group_or_dataset_attribute( f, attribute_name, f->Field_hid, 0, 1, type_id, force, &space_id, &attr_id ) )
395 return 0;
396 }
397 else
398 {
399 if( !F5Fopen_or_create_group_or_dataset_attribute( f, attribute_name, 0, f->Field_hid, 1, type_id, force, &space_id, &attr_id ) )
400 return 0;
401 }
402
403 if (attr_id > 0)
404 {
405 F5printf(50, "F5Fset_string_attribute(): String attribute %s written to %d.", text, (int)f->Field_hid);
406 H5Awrite(attr_id, type_id, text);
407 H5Aclose(attr_id);
408 }
409 else
410 {
411 F5printf(50, "F5Fset_string_attribute(): WARNING Unit Attribute not written to %s/%d.", text, (int)f->Field_hid);
412 return 0;
413 }
414
415 return 1;
416 }
417
418 }
419 else
420 F5printf(50, "F5Fset_string_attribute(): Invalid field ID.");
421
422 return 0;
423}
424
425F5_API int F5Fget_string_attribute(F5Path*f, const char*fragment_name, const char* attribute_name, char**text )
426{
427hid_t attr_id, space_id;
428
429 if (f->Field_hid > 0)
430 {
431 if( fragment_name != NULL )
432 {
433 H5E_BEGIN_TRY
434 attr_id = H5Aopen( f->Field_hid, attribute_name, H5P_DEFAULT);
435 H5E_END_TRY
436 if (attr_id > 0)
437 {
438 F5printf(50, "F5Fset_string_attribute(): txt attribute %s fount at %d.",
439 attribute_name, (int)f->Field_hid);
440 hid_t type_id;
441 type_id = H5Aget_type( attr_id );
442
443 size_t str_len = H5Tget_size( type_id );
444
445 *text = (char*) calloc( str_len, sizeof(char) );
446
447 H5Aread(attr_id, H5T_STRING, *text );
448
449 H5Tclose( type_id );
450 H5Aclose(attr_id);
451 }
452 else
453 {
454 F5printf(50, "F5Fset_string_attribute(): WARNING Unit Attribute not written to %s/%d.",
455 text, (int)f->Field_hid);
456 }
457
458 return 1;
459 }
460 else
461 {
462 if( F5Fis_group( f ) )
463 {
464 puts("isgroup");
465 if( !F5Fopen_group_or_dataset_attribute( f, attribute_name, f->Field_hid, 0, 1, &attr_id, &space_id ) )
466 return 0;
467 }
468 else
469 {
470 puts("isnogroup");
471 if( !F5Fopen_group_or_dataset_attribute( f, attribute_name, 0, f->Field_hid, 1, &attr_id, &space_id ) )
472 return 0;
473 }
474
475 puts("read attr");
476
477 if (attr_id > 0)
478 {
479
480 F5printf(50, "F5Fset_string_attribute(): txt attribute %s fount at %d.",
481 attribute_name, (int)f->Field_hid);
482 hid_t type_id;
483 type_id = H5Aget_type( attr_id );
484
485 size_t str_len = H5Tget_size( type_id );
486
487// printf("str_len: %d\n", str_len);
488
489 *text = (char*) calloc( str_len, sizeof(char) );
490
491 H5Aread(attr_id, type_id, *text );
492
493 H5Tclose( type_id );
494
495 H5Aclose(attr_id);
496 }
497 else
498 {
499 F5printf(50, "F5Fset_string_attribute(): WARNING Unit Attribute not written to %s/%d.", text, (int)f->Field_hid);
500 }
501
502
503 return 1;
504 }
505
506 }
507 else
508 F5printf(50, "F5Fset_string_attribute(): Invalid field ID.");
509
510 return 0;
511}
512
513
514F5_API int F5Fset_fragment_range_ghost2(F5Path*f, const char*fragment_name, const void*minmax, const void*minmax_ghost, unsigned force )
515{
516hid_t type_id;
517int check;
518 type_id = F5Fget_type(f);
519 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_COMPONENT_RANGE, minmax, 2, type_id, force);
520
521 if( check )
522 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_COMPONENT_RANGE_GHOST, minmax_ghost, 2, type_id, force);
523
524 H5Tclose(type_id);
525 return check;
526}
527
528F5_API int F5Fset_fragment_range_ghost(F5Path*f, const char*fragment_name, const void*minmax, const void*minmax_ghost )
529{
530 return F5Fset_fragment_range_ghost2(f, fragment_name, minmax, minmax_ghost, 0 );
531}
532
533F5_API int F5Fget_fragment_range_ghost(F5Path*f, const char*fragment_name, void*minmax, void*minmax_ghost, hid_t mem_type_id )
534{
535 if( F5Fget_fragment_attribute( f, fragment_name, FIBER_FIELD_COMPONENT_RANGE, minmax, 2 ,mem_type_id) )
536 {
538 minmax_ghost, 2, mem_type_id);
539 }
540 else
541 return 0;
542
543}
544
545F5_API int F5Fget_fragment_range_ghost2(F5Path*f, const char*fragment_name, void*minmax_ghost )
546{
547hid_t type_id;
548 type_id = F5Fget_type(f);
549
551 minmax_ghost, 2, type_id);
552}
553
554F5_API int F5Fget_fragment_ghost_size( F5Path*f, const char*fragment_name, unsigned long* size_real,
555 unsigned long* size_ghost)
556{
557unsigned long sizes[2];
558int check;
560 sizes, 2, H5T_NATIVE_ULONG );
561
562 *size_real = sizes[0];
563 *size_ghost = sizes[1];
564
565 return check;
566}
567
568F5_API int F5Fset_fragment_ghost_size(F5Path*f, const char*fragment_name, unsigned long size_real, unsigned long size_ghost, int force)
569{
570unsigned long sizes[2];
571 sizes[0] = size_real;
572 sizes[1] = size_ghost;
574 sizes, 2, H5T_NATIVE_ULONG, force );
575}
576
577F5_API int F5Fis_attribute_of_type(F5Path*f, const char*attribute_name, hid_t HDF5_type)
578{
579hid_t attrib = 0;
580
581 if (!f)
582 {
583 F5printf(50, "F5Fis_attribute_of_type, invalid F5Path");
584 return 0;
585 }
586
587hid_t gettype = F5Aget_type(f->Field_hid, attribute_name, &attrib);
588
589 if (H5Tequal(HDF5_type,gettype))
590 {
591 H5Tclose(gettype);
592 H5Aclose(attrib);
593 return 1;
594 }
595
596 H5Tclose(gettype);
597 H5Aclose(attrib);
598
599 return 0;
600}
601
602F5_API int F5Fis_range_of_type(F5Path*f, const char*fragment_name, hid_t HDF5_type)
603{
604 if( !fragment_name )
606 else
607 return F5Fis_fragment_attribute_of_type(f, fragment_name, FIBER_FIELD_COMPONENT_RANGE, HDF5_type );
608
609}
610
611F5_API int F5Fis_fragment_attribute_of_type(F5Path*f, const char*fragment_name, const char*attribute_name, hid_t HDF5_type)
612{
613hid_t attrib = 0, gid = -1, did = -1;
614
615 if (!f)
616 {
617 F5printf(15, "F5Fis_range_of_type, invalid F5Path");
618 return 0;
619 }
620
621 if( !F5Fopen_group_or_dataset( f, fragment_name, &gid, &did ) )
622 return 0;
623
624 hid_t gettype = F5Aget_type((gid>0)?gid:did, attribute_name, &attrib);
625
626 if (H5Tequal(HDF5_type,gettype))
627 {
628 H5Tclose(gettype);
629 H5Aclose(attrib);
630
631 if (did > 0) H5Dclose(did);
632 if (gid > 0) H5Gclose(gid);
633
634 return 1;
635 }
636
637 H5Tclose(gettype);
638 H5Aclose(attrib);
639
640 if (did > 0) H5Dclose(did);
641 if (gid > 0) H5Gclose(gid);
642
643 return 0;
644}
645
646F5_API int F5Fhas_attribute(F5Path*f, const char*attr_name)
647{
648 if (!f)
649 {
650 F5printf(50, "F5Fhas_attribute, invalid F5Path");
651 return 0;
652 }
653
654htri_t exist = H5Aexists(f->Field_hid, attr_name);
655
656 if (exist > 0)
657 return 1;
658 else if (exist < 0)
659 {
660 puts("F5Fhas_attribute, ERROR H5Aexists failed");
661 return 0;
662 }
663 else
664 return exist;
665}
666
667F5_API hssize_t F5Fget_attribute_nr_elements( F5Path*f, const char*fragment_name, const char*attribute_name )
668{
669hid_t attr_id;
670hid_t space_id;
671hssize_t nr_elements = 0;
672hid_t did = 0 , gid = 0;
673int check;
674
675 if (!f)
676 {
677 F5printf(50, "F5Fget_attribute_nr_elements, invalid F5Path");
678 return 0;
679 }
680
681 if( fragment_name != NULL )
682 {
683 check = F5Fopen_group_or_dataset( f, fragment_name, &gid, &did );
684
685 if( check == 0 ) return 0;
686
687 hid_t open_id = gid>0?gid:did;
688
689 if( open_id > 0 )
690 {
691 attr_id = F5Aopen_name( open_id, attribute_name);
692 if( attr_id < 0 )
693 {
694 F5printf(1,"F5Fget_attribute_nr_elements could not find attribute %s!", attribute_name);
695 return 0;
696 }
697 space_id = H5Aget_space( attr_id );
698 assert(space_id);
699 nr_elements = H5Sget_simple_extent_npoints( space_id );
700
701 H5Sclose( space_id );
702 H5Aclose( attr_id);
703 }
704
705 if( gid > 0 )
706 H5Gclose( gid );
707
708 if( did > 0 )
709 H5Dclose( gid );
710 }
711 else
712 {
713 attr_id = F5Aopen_name( f->Field_hid, attribute_name);
714 if( attr_id < 0 )
715 {
716 F5printf(1,"F5Fget_attribute_nr_elements could not find attribute %s!", attribute_name);
717 return 0;
718 }
719
720 space_id = H5Aget_space( attr_id );
721 assert(space_id);
722 nr_elements = H5Sget_simple_extent_npoints( space_id );
723
724 H5Sclose( space_id );
725 H5Aclose( attr_id);
726
727 }
728
729 return nr_elements;
730}
731
732F5_API int F5Fhas_fragment_attribute(F5Path*f, const char*fragment_name, const char*attr_name)
733{
734 if (!f)
735 {
736 F5printf(50, "F5Fhas_attribute, invalid F5Path");
737 return 0;
738 }
739
740hid_t Gid = -1, Did = -1;
741
742 H5E_BEGIN_TRY
743
744 Gid = H5Gopen2(f->Field_hid, fragment_name, H5P_DEFAULT);
745
746 if (Gid<0)
747 {
748 F5printf(55,"F5Fhas_fragment_attribute() no group, trying for a dataset!");
749 Did = H5Dopen2(f->Field_hid, fragment_name, H5P_DEFAULT);
750 if(Did<0)
751 {
752 F5printf(55,"F5Fhas_fragment_attribute() no dataset found");
753 H5Dclose(Did);
754 H5Gclose(Gid);
755 return 0;
756 }
757 else
758 F5printf(55,"F5Fhas_fragment_attribute() Yay dataset found!");
759 }
760 else
761 F5printf(55,"F5Fhas_fragment_attribute() Yay! found group!");
762
763 H5E_END_TRY
764
765htri_t exist = H5Aexists((Gid>0)?Gid:Did, attr_name);
766
767 if (Did > 0) H5Dclose(Did);
768 if (Gid > 0) H5Gclose(Gid);
769
770 if (exist > 0)
771 return 1;
772 else if (exist < 0)
773 {
774 puts("F5Fhas_attribute, ERROR H5Aexists failed");
775 return 0;
776 }
777 else
778 return exist;
779}
780
781F5_API int F5Fget_average(F5Path*f, const char*fragment_name, void*avg)
782{
783hid_t type_id;
784int check;
785 type_id = F5Fget_type(f);
786 if( !fragment_name )
787 check = F5Fget_attribute( f, FIBER_FIELD_COMPONENT_AVERAGE, avg, 1, type_id );
788 else
789 check = F5Fget_fragment_attribute( f, fragment_name, FIBER_FIELD_COMPONENT_AVERAGE, avg, 1, type_id );
790 H5Tclose(type_id);
791 return check;
792}
793
794F5_API int F5Fset_average2(F5Path*f, const char*fragment_name, const void*avg, int force)
795{
796hid_t type_id;
797int check;
798 type_id = F5Fget_type(f);
799 if(!fragment_name)
800 check = F5Fset_attribute(f, FIBER_FIELD_COMPONENT_AVERAGE, avg, 1, type_id, force);
801 else
802 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_COMPONENT_AVERAGE, avg, 1, type_id, force);
803
804 H5Tclose(type_id);
805 return check;
806}
807
808F5_API int F5Fset_average(F5Path*f, const char*fragment_name, const void*avg)
809{
810 return F5Fset_average2( f, fragment_name, avg, 0 );
811}
812
813F5_API int F5Fget_deviation(F5Path*f, const char*fragment_name, void*dev)
814{
815hid_t type_id;
816int check;
817 type_id = F5Fget_type(f);
818 if(!fragment_name)
819 check = F5Fget_attribute( f, FIBER_FIELD_COMPONENT_DEVIATION, dev, 1, type_id );
820 else
821 check = F5Fget_fragment_attribute( f, fragment_name, FIBER_FIELD_COMPONENT_DEVIATION, dev, 1, type_id );
822 H5Tclose(type_id);
823 return check;
824}
825
826F5_API int F5Fset_deviation2(F5Path*f, const char*fragment_name, const void*dev, int force)
827{
828
829hid_t type_id;
830int check;
831 type_id = F5Fget_type(f);
832 if( !fragment_name )
833 check = F5Fset_attribute(f, FIBER_FIELD_COMPONENT_DEVIATION, dev, 1, type_id, force);
834 else
835 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_COMPONENT_DEVIATION, dev, 1, type_id, force);
836
837 H5Tclose(type_id);
838 return check;
839}
840
841F5_API int F5Fset_deviation(F5Path*f, const char*fragment_name, const void*dev)
842{
843 return F5Fset_deviation2(f, fragment_name, dev, 0);
844}
845
846F5_API int F5Fget_histogram( F5Path*f, const char*fragment_name, unsigned long*histogram, hsize_t size )
847{
848 if( !fragment_name)
849 return F5Fget_attribute( f, FIBER_FIELD_COMPONENT_HISTOGRAM, histogram, size, H5T_NATIVE_ULONG );
850 else
851 return F5Fget_fragment_attribute( f, fragment_name, FIBER_FIELD_COMPONENT_HISTOGRAM, histogram, size, H5T_NATIVE_ULONG );
852}
853
854F5_API int F5Fset_histogram2( F5Path*f, const char*fragment_name, const unsigned long*his, hsize_t size, int force )
855{
856 if(!fragment_name)
857 return F5Fset_attribute(f, FIBER_FIELD_COMPONENT_HISTOGRAM, his, size, H5T_NATIVE_ULONG, force);
858 else
859 return F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_COMPONENT_HISTOGRAM, his, size, H5T_NATIVE_ULONG, force);
860}
861
862F5_API int F5Fset_histogram( F5Path*f,const char*fragment_name, const unsigned long*his, hsize_t size )
863{
864 return F5Fset_histogram2(f, fragment_name, his, size, 0);
865}
866
867F5_API int F5Fset_original_type2(F5Path*f, const char*fragment_name, int force)
868{
869char buf[256];
870 strcpy( buf, "Undefined" );
871hid_t type_id;
872int check;
873 type_id = F5Fget_type(f);
874
875 if( H5Tequal( H5T_NATIVE_USHORT, type_id ) ) // scalars
876 strcpy( buf, "H5T_NATIVE_USHORT" );
877 else if( H5Tequal( H5T_NATIVE_INT, type_id ) )
878 strcpy( buf, "H5T_NATIVE_INT" );
879 else if( H5Tequal( H5T_NATIVE_UCHAR, type_id ) )
880 strcpy( buf, "H5T_NATIVE_UCHAR" );
881 else if( H5Tequal( H5T_NATIVE_FLOAT, type_id ) )
882 strcpy( buf, "H5T_NATIVE_FLOAT" );
883 else if( H5Tequal( H5T_NATIVE_DOUBLE, type_id ) )
884 strcpy( buf, "H5T_NATIVE_DOUBLE" );
885 else if( H5Tequal( F5T_COORD3_FLOAT, type_id ) ) // coords/vecs
886 strcpy( buf, "F5T_COORD3_FLOAT" );
887 else if( H5Tequal( F5T_COORD3_DOUBLE, type_id ) )
888 strcpy( buf, "F5T_COORD3_DOUBLE" );
889 else if( H5Tequal( F5T_VEC3_FLOAT, type_id ) )
890 strcpy( buf, "F5T_VEC3_FLOAT" );
891 else if( H5Tequal( F5T_VEC3_DOUBLE, type_id ) )
892 strcpy( buf, "F5T_VEC3_DOUBLE" );
893 else if( H5Tequal( F5T_BIVEC3_FLOAT, type_id ) ) //bivecs
894 strcpy( buf, "F5T_BIVEC3_FLOAT" );
895 else if( H5Tequal( F5T_BIVEC3_DOUBLE, type_id ) )
896 strcpy( buf, "F5T_BIVEC3_DOUBLE" );
897 else if( H5Tequal( F5T_METRIC33_FLOAT, type_id ) ) // 2nd order tensors
898 strcpy( buf, "F5T_METRIC33_FLOAT" );
899 else if( H5Tequal( F5T_METRIC33_DOUBLE, type_id ) )
900 strcpy( buf, "F5T_METRIC33_DOUBLE" );
901
902
903
904
905
906 if( !fragment_name )
907 check = F5Fset_attribute(f, FIBER_FIELD_ORIGIANL_TYPE, buf, strlen(buf), H5Tcopy(H5T_C_S1), force);
908 else
909 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_ORIGIANL_TYPE, buf, strlen(buf), H5Tcopy(H5T_C_S1), force);
910
911 H5Tclose(type_id);
912 return check;
913}
914
915F5_API int F5Fset_dictionary2(F5Path*f, const char*fragment_name, const char*dictionary, const F5_uint16_t* words, int word_count, int force)
916{
917int check;
918
919 if( !fragment_name )
920 check = F5Fset_string_attribute(f, NULL, FIBER_FIELD_DICTIONARY, dictionary, 1 );
921 else
922 check = F5Fset_string_attribute(f, fragment_name, FIBER_FIELD_DICTIONARY, dictionary, 1 );
923
924 if(!check)
925 {
926 puts("F5Fset_dictionary2() error setting FIBER_FIELD_DICTIONARY attribute!");
927 return check;
928 }
929
930 if( !fragment_name )
931 check = F5Fset_attribute(f, FIBER_FIELD_DICTIONARY_WORDS, words, word_count,
932 H5T_NATIVE_USHORT, force);
933 else
934 check = F5Fset_fragment_attribute(f, fragment_name, FIBER_FIELD_DICTIONARY_WORDS, words, word_count,
935 H5T_NATIVE_USHORT, force);
936
937 return check;
938}
939
940F5_API int F5Fset_dictionary(F5Path*f, const char*fragment_name, const char*dictionary, const F5_uint16_t* words, int word_count, int force)
941{
942 return F5Fset_dictionary2( f, fragment_name, dictionary, words, word_count, 0 );
943}
944
945F5_API int F5Fget_dictionary( F5Path*f, const char*fragment_name, char**dictionary, F5_uint16_t*words, int word_count )
946{
947int check;
948
949 check = F5Fget_string_attribute( f, fragment_name, FIBER_FIELD_DICTIONARY, dictionary );
950
951 if(!check)
952 {
953 puts("F5Fget_dictionary() error getting FIBER_FIELD_DICTIONARY attribute!");
954 return check;
955 }
956
957 if( !fragment_name )
958 check = F5Fget_attribute( f, FIBER_FIELD_DICTIONARY_WORDS, words, word_count, H5T_NATIVE_USHORT );
959 else
960 check = F5Fget_fragment_attribute( f, fragment_name, FIBER_FIELD_DICTIONARY_WORDS, words, word_count, H5T_NATIVE_USHORT );
961
962 return check;
963}
964
965
966
968{
969 return F5Fset_string_attribute(f, NULL, F5_METRIC_UNIT_DESCRIPTION, unit, 1 );
970}
F5_API hid_t F5Aget_type(hid_t loc_id, const char *name, hid_t *attrib)
Definition F5A.c:167
int F5Fis_group(const F5Path *fpath)
Definition F5F.c:126
hid_t F5Fget_type(F5Path *f)
Definition F5F.c:156
F5_API int F5Fopen_or_create_group_or_dataset_attribute(F5Path *f, const char *attribute_name, hid_t gid, hid_t did, hsize_t N, hid_t type_id, int force, hid_t *space_id, hid_t *attr_id)
Definition F5Fmeta.c:117
F5_API int F5Fset_dictionary(F5Path *f, const char *fragment_name, const char *dictionary, const F5_uint16_t *words, int word_count, int force)
Definition F5Fmeta.c:940
F5_API int F5Fopen_group_or_dataset(F5Path *f, const char *name, hid_t *gid, hid_t *did)
Definition F5Fmeta.c:26
F5_API int F5Fis_range_of_type(F5Path *f, const char *fragment_name, hid_t HDF5_type)
Definition F5Fmeta.c:602
F5_API int F5Fset_fragment_attribute(F5Path *f, const char *fragment_name, const char *attribute_name, const void *data, const hsize_t N, hid_t mem_type_id, int force)
Definition F5Fmeta.c:300
F5_API int F5Fset_fragment_range_ghost2(F5Path *f, const char *fragment_name, const void *minmax, const void *minmax_ghost, unsigned force)
Definition F5Fmeta.c:514
F5_API int F5Fget_fragment_range_ghost(F5Path *f, const char *fragment_name, void *minmax, void *minmax_ghost, hid_t mem_type_id)
Definition F5Fmeta.c:533
F5_API int F5Fset_fragment_range_ghost(F5Path *f, const char *fragment_name, const void *minmax, const void *minmax_ghost)
Definition F5Fmeta.c:528
F5_API int F5Fis_fragment_attribute_of_type(F5Path *f, const char *fragment_name, const char *attribute_name, hid_t HDF5_type)
Definition F5Fmeta.c:611
F5_API int F5Fset_dictionary2(F5Path *f, const char *fragment_name, const char *dictionary, const F5_uint16_t *words, int word_count, int force)
Definition F5Fmeta.c:915
F5_API int F5Fset_average2(F5Path *f, const char *fragment_name, const void *avg, int force)
Definition F5Fmeta.c:794
F5_API int F5Fget_dictionary(F5Path *f, const char *fragment_name, char **dictionary, F5_uint16_t *words, int word_count)
Definition F5Fmeta.c:945
F5_API int F5Fget_string_attribute(F5Path *f, const char *fragment_name, const char *attribute_name, char **text)
Definition F5Fmeta.c:425
F5_API int F5Fset_metric_unit_description(F5Path *f, const char *unit)
Definition F5Fmeta.c:967
F5_API int F5Fget_fragment_attribute(F5Path *f, const char *fragment_name, const char *attribute_name, void *data, hsize_t N, hid_t mem_type_id)
Definition F5Fmeta.c:267
F5_API int F5Fset_original_type2(F5Path *f, const char *fragment_name, int force)
Definition F5Fmeta.c:867
F5_API int F5Fopen_group_or_dataset_attribute(F5Path *f, const char *attribute_name, hid_t gid, hid_t did, hsize_t N, hid_t *attr_id, hid_t *space_id)
Definition F5Fmeta.c:59
F5_API int F5Fget_histogram(F5Path *f, const char *fragment_name, unsigned long *histogram, hsize_t size)
Definition F5Fmeta.c:846
F5_API int F5Fset_histogram(F5Path *f, const char *fragment_name, const unsigned long *his, hsize_t size)
Definition F5Fmeta.c:862
F5_API int F5Fset_average(F5Path *f, const char *fragment_name, const void *avg)
Definition F5Fmeta.c:808
F5_API int F5Fset_deviation2(F5Path *f, const char *fragment_name, const void *dev, int force)
Definition F5Fmeta.c:826
F5_API int F5Fhas_fragment_attribute(F5Path *f, const char *fragment_name, const char *attr_name)
Definition F5Fmeta.c:732
F5_API int F5Fset_deviation(F5Path *f, const char *fragment_name, const void *dev)
Definition F5Fmeta.c:841
F5_API int F5Fset_string_attribute(F5Path *f, const char *fragment_name, const char *attribute_name, const char *text, int force)
Definition F5Fmeta.c:350
F5_API int F5Fget_deviation(F5Path *f, const char *fragment_name, void *dev)
Definition F5Fmeta.c:813
F5_API hssize_t F5Fget_attribute_nr_elements(F5Path *f, const char *fragment_name, const char *attribute_name)
Definition F5Fmeta.c:667
F5_API int F5Fget_attribute(F5Path *f, const char *attribute_name, void *data, hsize_t N, hid_t mem_type_id)
Definition F5Fmeta.c:191
F5_API int F5Fset_fragment_ghost_size(F5Path *f, const char *fragment_name, unsigned long size_real, unsigned long size_ghost, int force)
Definition F5Fmeta.c:568
F5_API int F5Fget_average(F5Path *f, const char *fragment_name, void *avg)
Definition F5Fmeta.c:781
F5_API int F5Fis_attribute_of_type(F5Path *f, const char *attribute_name, hid_t HDF5_type)
Definition F5Fmeta.c:577
F5_API int F5Fset_histogram2(F5Path *f, const char *fragment_name, const unsigned long *his, hsize_t size, int force)
Definition F5Fmeta.c:854
F5_API int F5Fget_fragment_ghost_size(F5Path *f, const char *fragment_name, unsigned long *size_real, unsigned long *size_ghost)
Definition F5Fmeta.c:554
F5_API int F5Fwrite_attr_data(const void *data, hsize_t N, hid_t type_id, hid_t attr_id, const char *attribute_name)
Definition F5Fmeta.c:171
F5_API int F5Fget_fragment_range_ghost2(F5Path *f, const char *fragment_name, void *minmax_ghost)
Definition F5Fmeta.c:545
F5_API int F5Fread_attr_data(void *data, hsize_t N, hid_t type_id, hid_t attr_id, const char *attribute_name)
Definition F5Fmeta.c:152
F5_API int F5Fhas_attribute(F5Path *f, const char *attr_name)
Definition F5Fmeta.c:646
F5_API int F5Fset_attribute(F5Path *f, const char *attribute_name, const void *data, hsize_t N, hid_t mem_type_id, int force)
Definition F5Fmeta.c:216
H5Tclose(type_id)
name
Definition F5P.c:82
free(name)
#define F5_API
Definition F5WinDLLApi.h:11
#define F5T_BIVEC3_DOUBLE
#define F5T_COORD3_FLOAT
#define F5T_COORD3_DOUBLE
#define F5T_VEC3_FLOAT
#define F5T_VEC3_DOUBLE
#define F5T_METRIC33_DOUBLE
#define F5T_BIVEC3_FLOAT
#define FIBER_FIELD_DICTIONARY_WORDS
Definition F5defs.h:222
#define FIBER_FIELD_ORIGIANL_TYPE
Definition F5defs.h:219
#define FIBER_FIELD_COMPONENT_AVERAGE
Definition F5defs.h:192
#define FIBER_FIELD_COMPONENT_DEVIATION
Definition F5defs.h:210
#define FIBER_FIELD_COMPONENT_RANGE
Definition F5defs.h:186
#define F5_METRIC_UNIT_DESCRIPTION
Definition F5defs.h:299
#define FIBER_FIELD_COMPONENT_RANGE_GHOST
Definition F5defs.h:187
#define FIBER_FIELD_COMPONENT_HISTOGRAM
Definition F5defs.h:215
#define FIBER_FRAGMENT_ARRAY_SIZE_GHOST_ATTRIBUTE
Definition F5defs.h:168
#define FIBER_FIELD_DICTIONARY
Definition F5defs.h:221
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
F5_int16_t F5_uint16_t
Definition F5types.h:20
hid_t F5Aopen_name(hid_t location, const char *name)
Definition F5A.c:34
#define H5Gclose(x)
Definition F5X.h:144
hid_t Field_hid
Definition F5Path.h:59