-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
test_table.c
1578 lines (1358 loc) · 55.4 KB
/
test_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "h5hltest.h"
#include "H5srcdir.h"
#include "H5TBpublic.h"
#define TEST_FILE_BE "test_table_be.h5"
#define TEST_FILE_LE "test_table_le.h5"
#define TEST_FILE_CRAY "test_table_cray.h5"
/*-------------------------------------------------------------------------
* Table API test
*
* Functions tested:
*
* H5TBmake_table
* H5TBread_table
* H5TBwrite_records
* H5TBread_records
* H5TBappend_records
* H5TBinsert_record
* H5TBdelete_record
* H5TBcombine_tables
* H5TBwrite_fields_name
* H5TBread_fields_name
* H5TBwrite_fields_index
* H5TBinsert_field
* H5TBdelete_field
* H5TBget_table_info
* H5TBget_field_info
*
*-------------------------------------------------------------------------
*/
#define TITLE "Title"
#define NFIELDS 5
#define NRECORDS 8
#define NRECORDS_ADD 3
/*-------------------------------------------------------------------------
* structure used for all tests, a particle with properties
*-------------------------------------------------------------------------
*/
typedef struct particle_t {
char name[16];
long longi;
float pressure;
double temperature;
int lati;
} particle_t;
/*-------------------------------------------------------------------------
* a subset of particle_t, with latitude and longitude fields
*-------------------------------------------------------------------------
*/
typedef struct position_t {
long longi;
int lati;
} position_t;
/*-------------------------------------------------------------------------
* a subset of particle_t, with name and pressure fields
*-------------------------------------------------------------------------
*/
typedef struct namepressure_t {
char name[16];
float pressure;
} namepressure_t;
/*-------------------------------------------------------------------------
* an extended particle, used in the insert field test
*-------------------------------------------------------------------------
*/
typedef struct particle2_t {
char name[16];
long longi;
float pressure;
double temperature;
int lati;
int new_field;
} particle2_t;
/*-------------------------------------------------------------------------
* a particle with one field less, used in the delete field test
*-------------------------------------------------------------------------
*/
typedef struct particle3_t {
char name[16];
long longi;
double temperature;
int lati;
} particle3_t;
/*-------------------------------------------------------------------------
* a particle, used in the delete field test differing memory layout
*-------------------------------------------------------------------------
*/
/* Push current alignment rule forcing 4-byte alignment boundary
* to the internal stack ...
*/
#pragma pack(push, 4)
typedef struct particle4_t {
uint32_t state;
double posx;
double posy;
float atx[3];
float aty[3];
float rro[2];
} particle4_t;
/*
* ... and restore original alignment rules from stack
*/
#pragma pack(pop)
/*-------------------------------------------------------------------------
* function to open an HDF5 file and return its file identifier
*-------------------------------------------------------------------------
*/
static hid_t
h5file_open(const char *fname, unsigned flags)
{
hid_t fid; /* identifier for the file */
const char *data_file = H5_get_srcdir_filename(fname);
/* open */
if ((fid = H5Fopen(data_file, flags, H5P_DEFAULT)) < 0) {
fprintf(stderr, "Error: Cannot open file <%s>\n", data_file);
exit(1);
}
return fid;
}
/*-------------------------------------------------------------------------
* function that compares one particle
*-------------------------------------------------------------------------
*/
static int
cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf)
{
if ((strcmp(rbuf[i].name, wbuf[j].name) != 0) || rbuf[i].lati != wbuf[j].lati ||
rbuf[i].longi != wbuf[j].longi || !H5_FLT_ABS_EQUAL(rbuf[i].pressure, wbuf[j].pressure) ||
!H5_DBL_ABS_EQUAL(rbuf[i].temperature, wbuf[j].temperature)) {
fprintf(stderr, "read and write buffers have differences\n");
fprintf(stderr, "%s %ld %f %f %d\n", rbuf[i].name, rbuf[i].longi, (double)rbuf[i].pressure,
rbuf[i].temperature, rbuf[i].lati);
fprintf(stderr, "%s %ld %f %f %d\n", wbuf[j].name, wbuf[j].longi, (double)wbuf[j].pressure,
wbuf[j].temperature, wbuf[j].lati);
return -1;
}
return 0;
}
/*-------------------------------------------------------------------------
* function to compare deleted records
*-------------------------------------------------------------------------
*/
static int
compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords, particle_t *rbuf, particle_t *wbuf)
{
hsize_t i, j;
for (i = 0; i < rrecords; i++) {
if (i < dstart) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
return -1;
}
else {
j = i + drecords;
if (cmp_par(i, j, rbuf, wbuf) < 0)
return -1;
}
}
return 0;
}
/*-------------------------------------------------------------------------
* the test program
*-------------------------------------------------------------------------
*/
static int
test_table(hid_t fid, int do_write)
{
hid_t fid1;
hid_t fid2;
hsize_t chunk_size = 10;
int compress = 0;
int *fill = NULL;
particle_t fill1[1] = {{"no data", -1, -99.0F, -99.0, -1}};
int fill1_new[1] = {-100};
hsize_t position;
char tname[20];
hsize_t i, j;
/* write, read, append, delete, insert some records and fields */
hsize_t FIELDS = NFIELDS;
hsize_t RECORDS = NRECORDS;
hsize_t start;
hsize_t wstart;
hsize_t rstart;
hsize_t istart;
hsize_t dstart;
hsize_t nrecords;
hsize_t rrecords;
hsize_t wrecords;
hsize_t arecords;
hsize_t irecords;
hsize_t drecords;
hsize_t nfields;
hsize_t rfields;
hsize_t start1; /* record to start reading from 1st table */
hsize_t start2; /* record to start writing in 2nd table */
/* read, write, insert, append buffers */
particle_t rbuf[NRECORDS + 4];
particle2_t rbuf2[NRECORDS];
particle3_t rbuf3[NRECORDS];
particle_t rbufc[NRECORDS * 2];
particle_t abuf[2] = {{"eight", 80, 8.0F, 80.0, 80}, {"nine", 90, 9.0F, 90.0, 90}};
particle_t ibuf[2] = {{"zero", 0, 0.0F, 0.0, 0}, {"zero", 0, 0.0F, 0.0, 0}};
particle_t wbufd[NRECORDS];
particle_t wbuf[NRECORDS] = {{
"zero",
0,
0.0F,
0.0,
0,
},
{"one", 10, 1.0F, 10.0, 10},
{"two", 20, 2.0F, 20.0, 20},
{"three", 30, 3.0F, 30.0, 30},
{"four", 40, 4.0F, 40.0, 40},
{"five", 50, 5.0F, 50.0, 50},
{"six", 60, 6.0F, 60.0, 60},
{"seven", 70, 7.0F, 70.0, 70}};
/* buffers for the field "Pressure" and "New_field" */
float pressure_in[NRECORDS] = {0.0F, 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F};
float pressure_out[NRECORDS];
int buf_new[NRECORDS] = {0, 1, 2, 3, 4, 5, 6, 7};
/* buffers for the fields "Latitude,Longitude" */
position_t position_out[NRECORDS_ADD];
position_t position_in[NRECORDS_ADD] = {{0, 0}, {10, 10}, {20, 20}};
/* buffers for the fields "Name,Pressure" */
namepressure_t namepre_out[NRECORDS];
namepressure_t namepre_in[NRECORDS] = {
{"zero", 0.0F}, {"one", 1.0F}, {"two", 2.0F}, {"three", 3.0F},
{"four", 4.0F}, {"five", 5.0F}, {"six", 6.0F}, {"seven", 7.0F},
};
/*-------------------------------------------------------------------------
* initialize table parameters
* field offsets and sizes used in the fields functions
*-------------------------------------------------------------------------
*/
size_t field_offset_pos[2] = {HOFFSET(position_t, longi), HOFFSET(position_t, lati)};
size_t field_offset_namepre[2] = {HOFFSET(namepressure_t, name), HOFFSET(namepressure_t, pressure)};
size_t field_sizes_pos[2] = {sizeof(position_in[0].longi), sizeof(position_in[0].lati)};
size_t field_sizes_namepre[2] = {sizeof(namepre_in[0].name), sizeof(namepre_in[0].pressure)};
size_t field_sizes_pre[1] = {sizeof(namepre_in[0].pressure)};
/*-------------------------------------------------------------------------
* query table test
*-------------------------------------------------------------------------
*/
char **names_out;
size_t sizes_out[NFIELDS];
size_t offset_out[NFIELDS];
size_t size_out;
/*-------------------------------------------------------------------------
* initialize table parameters
* field indexes (zero based) used in the fields functions
* "Name 0","Longitude 1","Pressure 2","Temperature 3","Latitude 4"
*-------------------------------------------------------------------------
*/
int field_index_pre[1] = {2};
int field_index_pos[2] = {1, 4};
int field_index_namepre[2] = {0, 2};
int field_index[NFIELDS] = {0, 1, 2, 3, 4};
/*-------------------------------------------------------------------------
* initialize table parameters
* size and the offsets of struct members in memory
* define the inserted field HDF5 type and buffers
* these are used for the insert field test
*-------------------------------------------------------------------------
*/
hid_t field_type_new = H5T_NATIVE_INT;
size_t dst_size2 = sizeof(particle2_t);
size_t dst_offset2[NFIELDS + 1] = {HOFFSET(particle2_t, name), HOFFSET(particle2_t, longi),
HOFFSET(particle2_t, pressure), HOFFSET(particle2_t, temperature),
HOFFSET(particle2_t, lati), HOFFSET(particle2_t, new_field)};
size_t dst_sizes2[NFIELDS + 1] = {sizeof(rbuf2[0].name), sizeof(rbuf2[0].longi),
sizeof(rbuf2[0].pressure), sizeof(rbuf2[0].temperature),
sizeof(rbuf2[0].lati), sizeof(rbuf2[0].new_field)};
/*-------------------------------------------------------------------------
* initialize table parameters
* size and the offsets of struct members in memory
* these are used for the delete field test
*-------------------------------------------------------------------------
*/
size_t dst_size3 = sizeof(particle3_t);
size_t dst_offset3[NFIELDS - 1] = {HOFFSET(particle3_t, name), HOFFSET(particle3_t, longi),
HOFFSET(particle3_t, temperature), HOFFSET(particle3_t, lati)};
size_t dst_sizes3[NFIELDS - 1] = {sizeof(rbuf3[0].name), sizeof(rbuf3[0].longi),
sizeof(rbuf3[0].temperature), sizeof(rbuf3[0].lati)};
/*-------------------------------------------------------------------------
* initialize table parameters
* size and the offsets of struct members in memory
* these are used for the delete field test with differing memory layout
*-------------------------------------------------------------------------
*/
/* Calculate the size and the offsets of our struct members in memory */
size_t tbl_size = sizeof(particle4_t);
size_t tbl_offset[NFIELDS + 1] = {HOFFSET(particle4_t, state), HOFFSET(particle4_t, posx),
HOFFSET(particle4_t, posy), HOFFSET(particle4_t, atx),
HOFFSET(particle4_t, aty), HOFFSET(particle4_t, rro)};
/* Define an array of Particles */
particle4_t p_data[NRECORDS] = {{12112, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12113, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12114, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12115, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12116, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12117, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12118, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}},
{12119, 1.4, 2.5, {1, 2, 3}, {4, 5, 6}, {99, 100}}};
/*-------------------------------------------------------------------------
* initialize table parameters
* 1) size and the offsets of struct members in memory
* 2) field names
* 3) define a HDF5 type for the fields
*-------------------------------------------------------------------------
*/
size_t type_size_mem = sizeof(particle_t);
size_t field_offset[NFIELDS] = {HOFFSET(particle_t, name), HOFFSET(particle_t, longi),
HOFFSET(particle_t, pressure), HOFFSET(particle_t, temperature),
HOFFSET(particle_t, lati)};
size_t field_size[NFIELDS] = {sizeof(rbuf[0].name), sizeof(rbuf[0].longi), sizeof(rbuf[0].pressure),
sizeof(rbuf[0].temperature), sizeof(rbuf[0].lati)};
const char *field_names4[NFIELDS + 1] = {"F1", "F2", "F3", "F4", "F5", "F6"};
hid_t field_type4[NFIELDS + 1];
particle4_t fill_data[1] = {{9999999, -9999999, 999999, {999, 999, 999}, {999, 999, 999}, {999, 999}}};
hsize_t nfields_out;
hsize_t nrecords_out;
hid_t arry3_32f;
hid_t arry2_32f;
hsize_t dims;
const char *field_names[NFIELDS] = {"Name", "Longitude", "Pressure", "Temperature", "Latitude"};
hid_t field_type[NFIELDS];
hid_t string_type = H5Tcopy(H5T_C_S1);
H5Tset_size(string_type, 16);
field_type[0] = string_type;
field_type[1] = H5T_NATIVE_LONG;
field_type[2] = H5T_NATIVE_FLOAT;
field_type[3] = H5T_NATIVE_DOUBLE;
field_type[4] = H5T_NATIVE_INT;
memset(wbufd, 0, NRECORDS * sizeof(particle_t));
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBmake_table
* H5TBread_table
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("making table");
if (H5TBmake_table(TITLE, fid, "table1", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
PASSED();
}
HL_TESTING2("reading table");
/*-------------------------------------------------------------------------
* read the table
*-------------------------------------------------------------------------
*/
if (H5TBread_table(fid, "table1", type_size_mem, field_offset, field_size, rbuf) < 0)
goto out;
/* compare the extracted table with the original array */
for (i = 0; i < NRECORDS; i++) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
PASSED();
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBwrite_records
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("writing records");
/* create an empty table */
if (H5TBmake_table(TITLE, fid, "table2", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, 0) < 0)
goto out;
/*-------------------------------------------------------------------------
* write records, start at 0, write 8
* pos = 0 1 2 3 4 5 6 7
* data= 0 1 2 3 4 5 6 7
*-------------------------------------------------------------------------
*/
wstart = 0;
wrecords = 8;
if (H5TBwrite_records(fid, "table2", wstart, wrecords, type_size_mem, field_offset, field_size,
wbuf) < 0)
goto out;
/* read it back */
if (H5TBread_table(fid, "table2", type_size_mem, field_offset, field_size, rbuf) < 0)
goto out;
/* compare */
for (i = 0; i < NRECORDS; i++) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBread_records
*
*-------------------------------------------------------------------------
*/
HL_TESTING2("reading records");
/*-------------------------------------------------------------------------
* read records, start at 0, read 8
* pos = 0 1 2 3 4 5 6 7
* data= 0 1 2 3 4 5 6 7
*-------------------------------------------------------------------------
*/
/*-------------------------------------------------------------------------
* for the read test we cannot use "table2" because it has been appended
* we use the original "table1" instead
*-------------------------------------------------------------------------
*/
if (do_write)
strcpy(tname, "table2");
else
strcpy(tname, "table1");
rstart = 0;
rrecords = 8;
if (H5TBread_records(fid, tname, rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) < 0)
goto out;
/* compare */
for (i = rstart; i < rrecords; i++) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
PASSED();
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBappend_records
* H5TBread_records
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("appending records");
/*-------------------------------------------------------------------------
* append 2 records
* pos = 0 1 2 3 4 5 6 7 8 9
* data= 0 1 2 3 4 5 6 7 8 9
*-------------------------------------------------------------------------
*/
arecords = 2;
if (H5TBappend_records(fid, "table2", arecords, type_size_mem, field_offset, field_size, abuf) < 0)
return 1;
if (H5TBget_table_info(fid, "table2", &rfields, &rrecords) < 0)
return 1;
rstart = 0;
rrecords = NRECORDS + arecords;
if (H5TBread_records(fid, "table2", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
return 1;
/* compare */
wrecords = 8;
for (i = rstart; i < wrecords; i++) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
for (i = wrecords, j = 0; i < rrecords; i++, j++) {
if (cmp_par(i, j, rbuf, abuf) < 0)
goto out;
}
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBinsert_record
* H5TBread_records
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("inserting records");
/*-------------------------------------------------------------------------
* insert 2 records
* pos = 0 1 2 3 4 5 6 7 8 9 10 11
* data= 0 0 0 1 2 3 4 5 6 7 8 9
*-------------------------------------------------------------------------
*/
istart = 1;
irecords = 2;
if (H5TBinsert_record(fid, "table2", istart, irecords, type_size_mem, field_offset, field_size,
ibuf) < 0)
return 1;
if (H5TBget_table_info(fid, "table2", &rfields, &rrecords) < 0)
return 1;
if (H5TBread_records(fid, "table2", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
return 1;
/* compare */
for (i = 0; i < 12; i++) {
if (i < istart) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
else if (i >= istart && i < istart + irecords) {
j = i - istart;
if (cmp_par(i, j, rbuf, ibuf) < 0)
goto out;
}
else if (i >= istart + irecords && i < 10) {
j = i - irecords;
if (cmp_par(i, j, rbuf, wbuf) < 0)
goto out;
}
else {
j = i - 10;
if (cmp_par(i, j, rbuf, abuf) < 0)
goto out;
}
}
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBdelete_record
* H5TBread_records
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("deleting records");
/*-------------------------------------------------------------------------
* Create a table
* pos = 0 1 2 3 4 5 6 7
* data= 0 1 2 3 4 5 6 7
*-------------------------------------------------------------------------
*/
for (i = 0; i < NRECORDS; i++) {
wbufd[i].lati = wbuf[i].lati;
wbufd[i].longi = wbuf[i].longi;
wbufd[i].pressure = wbuf[i].pressure;
wbufd[i].temperature = wbuf[i].temperature;
strcpy(wbufd[i].name, wbuf[i].name);
}
if (H5TBmake_table(TITLE, fid, "table3", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbufd) < 0)
goto out;
/*-------------------------------------------------------------------------
* Delete records, start at 2, delete 3
* pos = 0 1 2 3 4
* data= 0 1 5 6 7
*-------------------------------------------------------------------------
*/
dstart = 2;
drecords = 3;
if (H5TBdelete_record(fid, "table3", dstart, drecords) < 0)
goto out;
if (H5TBget_table_info(fid, "table3", &rfields, &rrecords) < 0)
goto out;
rstart = 0;
if (H5TBread_records(fid, "table3", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
goto out;
/* compare */
nrecords = NRECORDS;
assert(rrecords == nrecords - drecords);
if (compare_deleted(rrecords, dstart, drecords, rbuf, wbufd) < 0)
goto out;
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
*/
nrecords = rrecords;
for (i = 0; i < nrecords; i++) {
wbufd[i] = rbuf[i];
}
/*-------------------------------------------------------------------------
* Delete records, start at 0, delete 2
* pos = 0 1 2
* data= 5 6 7
*-------------------------------------------------------------------------
*/
dstart = 0;
drecords = 2;
if (H5TBdelete_record(fid, "table3", dstart, drecords) < 0)
goto out;
if (H5TBget_table_info(fid, "table3", &rfields, &rrecords) < 0)
goto out;
rstart = 0;
if (H5TBread_records(fid, "table3", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
goto out;
/* Compare */
assert(rrecords == nrecords - drecords);
if (compare_deleted(rrecords, dstart, drecords, rbuf, wbufd) < 0)
goto out;
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
*/
nrecords = rrecords;
for (i = 0; i < nrecords; i++) {
wbufd[i] = rbuf[i];
}
/*-------------------------------------------------------------------------
* Delete records, start at 1, delete 1
* pos = 0 1
* data= 5 7
*-------------------------------------------------------------------------
*/
dstart = 1;
drecords = 1;
if (H5TBdelete_record(fid, "table3", dstart, drecords) < 0)
goto out;
if (H5TBget_table_info(fid, "table3", &rfields, &rrecords) < 0)
goto out;
rstart = 0;
if (H5TBread_records(fid, "table3", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
goto out;
/* Compare */
assert(rrecords == nrecords - drecords);
if (compare_deleted(rrecords, dstart, drecords, rbuf, wbufd) < 0)
goto out;
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
*/
nrecords = rrecords;
for (i = 0; i < nrecords; i++) {
wbufd[i] = rbuf[i];
}
/*-------------------------------------------------------------------------
* Delete records, start at 0, delete 1
* pos = 0
* data= 7
*-------------------------------------------------------------------------
*/
dstart = 0;
drecords = 1;
if (H5TBdelete_record(fid, "table3", dstart, drecords) < 0)
goto out;
if (H5TBget_table_info(fid, "table3", &rfields, &rrecords) < 0)
goto out;
rstart = 0;
if (H5TBread_records(fid, "table3", rstart, rrecords, type_size_mem, field_offset, field_size, rbuf) <
0)
goto out;
/* Compare */
assert(rrecords == nrecords - drecords);
if (compare_deleted(rrecords, dstart, drecords, rbuf, wbufd) < 0)
goto out;
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
*/
nrecords = rrecords;
for (i = 0; i < nrecords; i++) {
wbufd[i] = rbuf[i];
}
/* Read complete table */
if (H5TBread_table(fid, "table3", type_size_mem, field_offset, field_size, rbuf) < 0)
goto out;
/* Compare */
for (i = 0; i < rrecords; i++) {
if (cmp_par(i, i, rbuf, wbufd) < 0) {
goto out;
}
}
/*-------------------------------------------------------------------------
* Delete records, start at 0, delete 1
* pos = 0
* data= empty
*-------------------------------------------------------------------------
*/
dstart = 0;
drecords = 1;
if (H5TBdelete_record(fid, "table3", dstart, drecords) < 0)
goto out;
if (H5TBget_table_info(fid, "table3", &rfields, &rrecords) < 0)
goto out;
if (rrecords)
goto out;
PASSED();
}
/*------------------------------------------------------------------------
* Functions tested:
*
* H5TBdelete_record -- With differing memory layout from machine memory
* layout. HDFFV-8055
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("deleting records (differing memory layout)");
dims = 3;
arry3_32f = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, &dims);
dims = 2;
arry2_32f = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, &dims);
/* Initialize the field field_type */
field_type4[0] = H5T_NATIVE_UINT32;
field_type4[1] = H5T_NATIVE_DOUBLE;
field_type4[2] = H5T_NATIVE_DOUBLE;
field_type4[3] = arry3_32f;
field_type4[4] = arry3_32f;
field_type4[5] = arry2_32f;
/* Make the table */
if (H5TBmake_table("Table Title", fid, "table", NFIELDS + 1, (hsize_t)NRECORDS, tbl_size,
field_names4, tbl_offset, field_type4, chunk_size, fill_data, compress,
p_data) < 0)
goto out;
/* Delete records */
start = 3;
nrecords = 3;
if (H5TBdelete_record(fid, "table", start, nrecords) < 0)
goto out;
/* Get table info */
if (H5TBget_table_info(fid, "table", &nfields_out, &nrecords_out) < 0)
goto out;
/* check */
if ((int)nfields_out != (int)NFIELDS + 1)
goto out;
if ((int)nrecords_out != (int)NRECORDS - 3)
goto out;
/* close type */
H5Tclose(arry3_32f);
H5Tclose(arry2_32f);
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBadd_records_from
* H5TBread_records
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("adding records");
/* create 2 tables */
if (H5TBmake_table(TITLE, fid, "table4", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
if (H5TBmake_table(TITLE, fid, "table5", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
/* add the records from "table4" to "table5" */
start1 = 3;
nrecords = 2;
start2 = 6;
if (H5TBadd_records_from(fid, "table4", start1, nrecords, "table5", start2) < 0)
goto out;
/* read final table */
if (H5TBread_table(fid, "table5", type_size_mem, field_offset, field_size, rbuf) < 0)
goto out;
/* compare */
for (i = 0; i < NRECORDS + 2; i++) {
if (i < start2) {
if (cmp_par(i, i, rbuf, wbuf) < 0)
goto out;
}
else if (i < start2 + nrecords) {
j = i - start1;
if (cmp_par(i, j, rbuf, wbuf) < 0)
goto out;
}
else {
j = i - nrecords;
if (cmp_par(i, j, rbuf, wbuf) < 0)
goto out;
}
}
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBcombine_tables
* H5TBread_table
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("combining tables");
/* create 2 tables */
if (H5TBmake_table(TITLE, fid, "table6", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
if (H5TBmake_table(TITLE, fid, "table7", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
/* combine the two tables into a third */
if (H5TBcombine_tables(fid, "table6", fid, "table7", "table8") < 0)
goto out;
/* read merged table */
if (H5TBread_table(fid, "table8", type_size_mem, field_offset, field_size, rbufc) < 0)
goto out;
/* compare */
for (i = 0; i < NRECORDS * 2; i++) {
if (i < NRECORDS) {
if (cmp_par(i, i, rbufc, wbuf) < 0)
goto out;
}
else {
if (cmp_par(i, i - NRECORDS, rbufc, wbuf) < 0)
goto out;
}
}
/*-------------------------------------------------------------------------
* multi file test
*-------------------------------------------------------------------------
*/
/* create 2 files using default properties. */
fid1 = H5Fcreate("combine_tables1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
fid2 = H5Fcreate("combine_tables2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* create 2 tables, one in each file */
if (H5TBmake_table(TITLE, fid1, "table1", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
if (H5TBmake_table(TITLE, fid2, "table2", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill, compress, wbuf) < 0)
goto out;
/* combine the two tables into a third */
if (H5TBcombine_tables(fid1, "table1", fid2, "table2", "table3") < 0)
goto out;
/* read merged table */
if (H5TBread_table(fid1, "table3", type_size_mem, field_offset, field_size, rbufc) < 0)
goto out;
/* compare */
for (i = 0; i < NRECORDS * 2; i++) {
if (i < NRECORDS) {
if (cmp_par(i, i, rbufc, wbuf) < 0)
goto out;
}
else {
if (cmp_par(i, i - NRECORDS, rbufc, wbuf) < 0)
goto out;
}
}
/* close files */
H5Fclose(fid1);
H5Fclose(fid2);
PASSED();
}
/*-------------------------------------------------------------------------
*
* Functions tested:
*
* H5TBwrite_fields_name
*
*-------------------------------------------------------------------------
*/
if (do_write) {
HL_TESTING2("writing fields by name");
/* make an empty table with fill values */
if (H5TBmake_table(TITLE, fid, "table9", FIELDS, RECORDS, type_size_mem, field_names, field_offset,
field_type, chunk_size, fill1, compress, 0) < 0)
goto out;
/* write the pressure field starting at record 2 */