-
Notifications
You must be signed in to change notification settings - Fork 5
/
hdf5_wrapper.F90
3804 lines (3216 loc) · 145 KB
/
hdf5_wrapper.F90
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
! MIT License
! https://github.com/mpickem/hdf5_wrapper
! Copyright (c) 2018,2019,2021,2022 Matthias Pickem
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
! in the Software without restriction, including without limitation the rights
! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
! copies of the Software, and to permit persons to whom the Software is
! furnished to do so, subject to the following conditions:
module hdf5_wrapper
use hdf5
implicit none
integer :: hdf_err
integer(hid_t) :: complex_id_dp, complex_id_sp
integer(hid_t) :: complex_id_r_dp, complex_id_i_dp, complex_id_r_sp, complex_id_i_sp
integer(hid_t) :: logical_id
integer, parameter :: logical_size = 1
interface hdf5_read_data
module procedure hdf5_read_data_0d_logical, &
hdf5_read_data_1d_logical, &
hdf5_read_data_2d_logical, &
hdf5_read_data_3d_logical, &
hdf5_read_data_4d_logical, &
hdf5_read_data_5d_logical, &
hdf5_read_data_6d_logical, &
hdf5_read_data_7d_logical, &
hdf5_read_data_0d_int4, &
hdf5_read_data_1d_int4, &
hdf5_read_data_2d_int4, &
hdf5_read_data_3d_int4, &
hdf5_read_data_4d_int4, &
hdf5_read_data_5d_int4, &
hdf5_read_data_6d_int4, &
hdf5_read_data_7d_int4, &
hdf5_read_data_0d_real4, &
hdf5_read_data_1d_real4, &
hdf5_read_data_2d_real4, &
hdf5_read_data_3d_real4, &
hdf5_read_data_4d_real4, &
hdf5_read_data_5d_real4, &
hdf5_read_data_6d_real4, &
hdf5_read_data_7d_real4, &
hdf5_read_data_0d_complex4,&
hdf5_read_data_1d_complex4,&
hdf5_read_data_2d_complex4,&
hdf5_read_data_3d_complex4,&
hdf5_read_data_4d_complex4,&
hdf5_read_data_5d_complex4,&
hdf5_read_data_6d_complex4,&
hdf5_read_data_7d_complex4,&
hdf5_read_data_0d_real8, &
hdf5_read_data_1d_real8, &
hdf5_read_data_2d_real8, &
hdf5_read_data_3d_real8, &
hdf5_read_data_4d_real8, &
hdf5_read_data_5d_real8, &
hdf5_read_data_6d_real8, &
hdf5_read_data_7d_real8, &
hdf5_read_data_0d_complex8,&
hdf5_read_data_1d_complex8,&
hdf5_read_data_2d_complex8,&
hdf5_read_data_3d_complex8,&
hdf5_read_data_4d_complex8,&
hdf5_read_data_5d_complex8,&
hdf5_read_data_6d_complex8,&
hdf5_read_data_7d_complex8
end interface hdf5_read_data
interface hdf5_write_data
module procedure hdf5_write_data_0d_logical, &
hdf5_write_data_1d_logical, &
hdf5_write_data_2d_logical, &
hdf5_write_data_3d_logical, &
hdf5_write_data_4d_logical, &
hdf5_write_data_5d_logical, &
hdf5_write_data_6d_logical, &
hdf5_write_data_7d_logical, &
hdf5_write_data_0d_int4, &
hdf5_write_data_1d_int4, &
hdf5_write_data_2d_int4, &
hdf5_write_data_3d_int4, &
hdf5_write_data_4d_int4, &
hdf5_write_data_5d_int4, &
hdf5_write_data_6d_int4, &
hdf5_write_data_7d_int4, &
hdf5_write_data_0d_real4, &
hdf5_write_data_1d_real4, &
hdf5_write_data_2d_real4, &
hdf5_write_data_3d_real4, &
hdf5_write_data_4d_real4, &
hdf5_write_data_5d_real4, &
hdf5_write_data_6d_real4, &
hdf5_write_data_7d_real4, &
hdf5_write_data_0d_complex4,&
hdf5_write_data_1d_complex4,&
hdf5_write_data_2d_complex4,&
hdf5_write_data_3d_complex4,&
hdf5_write_data_4d_complex4,&
hdf5_write_data_5d_complex4,&
hdf5_write_data_6d_complex4,&
hdf5_write_data_7d_complex4,&
hdf5_write_data_0d_real8, &
hdf5_write_data_1d_real8, &
hdf5_write_data_2d_real8, &
hdf5_write_data_3d_real8, &
hdf5_write_data_4d_real8, &
hdf5_write_data_5d_real8, &
hdf5_write_data_6d_real8, &
hdf5_write_data_7d_real8, &
hdf5_write_data_0d_complex8,&
hdf5_write_data_1d_complex8,&
hdf5_write_data_2d_complex8,&
hdf5_write_data_3d_complex8,&
hdf5_write_data_4d_complex8,&
hdf5_write_data_5d_complex8,&
hdf5_write_data_6d_complex8,&
hdf5_write_data_7d_complex8
end interface hdf5_write_data
interface hdf5_write_attribute
module procedure hdf5_write_attribute_logical, &
hdf5_write_attribute_int4, &
hdf5_write_attribute_real4, &
hdf5_write_attribute_real8, &
hdf5_write_attribute_complex4,&
hdf5_write_attribute_complex8,&
hdf5_write_attribute_string
end interface hdf5_write_attribute
interface hdf5_read_attribute
module procedure hdf5_read_attribute_logical, &
hdf5_read_attribute_int4, &
hdf5_read_attribute_real4, &
hdf5_read_attribute_real8, &
hdf5_read_attribute_complex4,&
hdf5_read_attribute_complex8,&
hdf5_read_attribute_string
end interface hdf5_read_attribute
contains
subroutine hdf5_init()
call h5open_f(hdf_err)
call hdf5_create_complex_datatype()
call hdf5_create_logical_datatype()
end subroutine hdf5_init
subroutine hdf5_finalize()
call h5close_f(hdf_err)
end subroutine hdf5_finalize
subroutine hdf5_create_file(fname)
character(len=*), intent(in) :: fname
integer(hid_t) :: ifile
! truncate -> if it already exists, erase all data
! other possibility: h5f_acc_excl_f -> fail if already exists
call h5fcreate_f(trim(adjustl(fname)), h5f_acc_trunc_f, ifile, hdf_err)
! we only create here
call h5fclose_f(ifile, hdf_err)
end subroutine hdf5_create_file
subroutine hdf5_open_file(fname, ifile, rdonly)
character(len=*), intent(in) :: fname
integer(hid_t), intent(out) :: ifile
logical, optional :: rdonly
if (present(rdonly)) then
if (rdonly) then
call h5fopen_f(trim(adjustl(fname)), h5f_acc_rdonly_f, ifile, hdf_err)
else
call h5fopen_f(trim(adjustl(fname)), h5f_acc_rdwr_f, ifile, hdf_err)
endif
else
call h5fopen_f(trim(adjustl(fname)), h5f_acc_rdwr_f, ifile, hdf_err)
endif
end subroutine hdf5_open_file
subroutine hdf5_close_file(ifile)
integer(hid_t), intent(in) :: ifile
call h5fclose_f(ifile, hdf_err)
end subroutine hdf5_close_file
subroutine hdf5_create_group(ifile, gname, iforce_error)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: gname
logical, intent(in), optional :: iforce_error
integer(hid_t) :: file_id
integer(hid_t) :: grp_parent_id, grp_id
integer :: grpcnt
integer :: pos,i
logical :: force_error
character(len=50), allocatable :: ngroup(:)
character(len=150) :: strim
! adjusting string and removing possible leading and trailing '/'
strim = adjustl(trim(gname))
if (index(strim, '/', back=.true.) .eq. len_trim(strim)) then
strim = strim(:(len_trim(strim)-1))
endif
if (index(strim, '/') .eq. 1) then
strim = strim(2:)
endif
! now we have a string with looks like 'group1/group2/group3'
if (len_trim(strim) .eq. 0) return
allocate(ngroup(30))
grpcnt = 1
do
pos = index(strim, '/')
if (pos .eq. 0) then
ngroup(grpcnt) = strim(:len_trim(strim)) ! until the end
exit
else
ngroup(grpcnt) = strim(:(pos-1)) ! without the '/'
strim = strim((pos+1):) ! truncating the left
grpcnt = grpcnt + 1
endif
enddo
! if we call create_group from the outside we call errors if we stumble upon
! existing groups
if (present(iforce_error)) then
if (iforce_error) then
force_error = .true.
else
force_error = .false.
endif
else
force_error = .true.
endif
! now we have the number of groups (grpcnt)
! the according group names are stored in the array ngroup(1...grpcnt)
call h5eset_auto_f(0,hdf_err) ! deactivate error printing
grp_parent_id = ifile ! for the first entry into the file
! the last group creating is outside of the error supression.
if (force_error) then
do i=1,grpcnt-1
! check for existance
! this check causes all the unecessary error messages
! I tried doing it with h5oexists_by_name_f, but there one
! cannot specifically check for group ... so
! I will stick to this 'hack'
call h5gopen_f(grp_parent_id, trim(ngroup(i)), grp_id, hdf_err)
if (hdf_err .ne. 0) then ! failed
call h5gcreate_f(grp_parent_id, trim(ngroup(i)), grp_id, hdf_err)
endif
if (grp_parent_id .ne. ifile) then
call h5gclose_f(grp_parent_id, hdf_err)
endif
grp_parent_id = grp_id
enddo
call h5eclear_f(hdf_err) ! clear the error
call h5eset_auto_f(1,hdf_err) ! acitvate it again
! this will cause the error message if the group already exists
call h5gcreate_f(grp_parent_id, trim(ngroup(grpcnt)), grp_id, hdf_err)
if (grp_parent_id .ne. ifile) then
call h5gclose_f(grp_parent_id, hdf_err)
endif
! here everything is inside the error supression.
else
do i=1,grpcnt
call h5gopen_f(grp_parent_id, trim(ngroup(i)), grp_id, hdf_err)
if (hdf_err .ne. 0) then ! failed
call h5gcreate_f(grp_parent_id, trim(ngroup(i)), grp_id, hdf_err)
endif
if (grp_parent_id .ne. ifile) then
call h5gclose_f(grp_parent_id, hdf_err)
endif
grp_parent_id = grp_id
enddo
call h5eclear_f(hdf_err) ! clear the error
call h5eset_auto_f(1,hdf_err) ! acitvate it again
endif
call h5gclose_f(grp_id, hdf_err)
deallocate(ngroup)
end subroutine hdf5_create_group
! this code part is from ADGA
! github.com/abinitiodga/adga
! GPLv3
subroutine hdf5_create_complex_datatype()
integer(size_t), parameter :: zero = 0
integer(hid_t) :: plist_id
integer(size_t) :: compound_size, type_sized
! double precision
call h5pcreate_f(h5p_dataset_xfer_f, plist_id, hdf_err)
call h5pset_preserve_f(plist_id, .true., hdf_err)
! compound
call h5tget_size_f(h5t_native_double, type_sized, hdf_err)
compound_size = 2*type_sized
call h5tcreate_f(h5t_compound_f, compound_size, complex_id_dp, hdf_err)
call h5tinsert_f(complex_id_dp, "r", zero, h5t_native_double, hdf_err)
call h5tinsert_f(complex_id_dp, "i", type_sized, h5t_native_double, hdf_err)
! separate
call h5tcreate_f(h5t_compound_f, type_sized, complex_id_r_dp, hdf_err)
call h5tinsert_f(complex_id_r_dp, "r", zero, h5t_native_double, hdf_err)
call h5tcreate_f(h5t_compound_f, type_sized, complex_id_i_dp, hdf_err)
call h5tinsert_f(complex_id_i_dp, "i", zero, h5t_native_double, hdf_err)
call h5pclose_f(plist_id, hdf_err)
! single precision
call h5pcreate_f(h5p_dataset_xfer_f, plist_id, hdf_err)
call h5pset_preserve_f(plist_id, .true., hdf_err)
! compound
call h5tget_size_f(h5t_native_real, type_sized, hdf_err)
compound_size = 2*type_sized
call h5tcreate_f(h5t_compound_f, compound_size, complex_id_sp, hdf_err)
call h5tinsert_f(complex_id_sp, "r", zero, h5t_native_real, hdf_err)
call h5tinsert_f(complex_id_sp, "i", type_sized, h5t_native_real, hdf_err)
! separate
call h5tcreate_f(h5t_compound_f, type_sized, complex_id_r_sp, hdf_err)
call h5tinsert_f(complex_id_r_sp, "r", zero, h5t_native_real, hdf_err)
call h5tcreate_f(h5t_compound_f, type_sized, complex_id_i_sp, hdf_err)
call h5tinsert_f(complex_id_i_sp, "i", zero, h5t_native_real, hdf_err)
call h5pclose_f(plist_id, hdf_err)
end subroutine hdf5_create_complex_datatype
subroutine hdf5_create_logical_datatype()
integer, parameter :: zero = 0
integer, parameter :: one = 1
integer(size_t) :: type_sized
call h5tget_size_f(h5t_native_b8, type_sized, hdf_err) ! h5py uses numpy 1-byte bool
call h5tcreate_f(h5t_enum_f, type_sized, logical_id, hdf_err)
call h5tenum_insert_f(logical_id, "FALSE", zero, hdf_err)
call h5tenum_insert_f(logical_id, "TRUE", one, hdf_err)
end subroutine hdf5_create_logical_datatype
integer function hdf5_get_dimensions(ifile, dset)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer :: rank
integer(hid_t) :: dset_id, dset_space_id
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_ndims_f(dset_space_id, rank, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
hdf5_get_dimensions = rank
end function hdf5_get_dimensions
subroutine hdf5_get_shape(ifile, dset, dshape)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer, allocatable :: dshape(:)
integer(hsize_t), allocatable :: dshape5(:)
integer(hsize_t), allocatable :: dmaxshape5(:)
integer :: rank
integer(hid_t) :: dset_id, dset_space_id
rank = hdf5_get_dimensions(ifile, dset)
allocate(dshape(rank), dshape5(rank), dmaxshape5(rank))
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dshape5, dmaxshape5, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dshape = int(dshape5)
deallocate(dshape5, dmaxshape5)
end subroutine hdf5_get_shape
subroutine hdf5_read_data_0d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical :: darray
integer(logical_size) :: darrayi
integer(hid_t) :: dset_id
integer(hsize_t), dimension(0) :: dset_dims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5dclose_f(dset_id, hdf_err)
if (darrayi == 0) then
darray = .false.
else
darray = .true.
endif
end subroutine hdf5_read_data_0d_logical
subroutine hdf5_read_data_1d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:) :: darray
integer(logical_size), allocatable :: darrayi(:)
integer(8), dimension(1) :: dims
integer :: a
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(1) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
allocate(darray(dims(1)))
do a=1,dims(1)
if (darrayi(a) == 0) then
darray(a) = .false.
else
darray(a) = .true.
endif
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_1d_logical
subroutine hdf5_read_data_2d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:)
integer(8), dimension(2) :: dims
integer :: a,b
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(2) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
allocate(darray(dims(1),dims(2)))
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b) == 0) then
darray(a,b) = .false.
else
darray(a,b) = .true.
endif
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_2d_logical
subroutine hdf5_read_data_3d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:,:)
integer(8), dimension(3) :: dims
integer :: a,b,c
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(3) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2), dset_dims(3)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
dims(3) = size(darrayi,3)
allocate(darray(dims(1),dims(2),dims(3)))
do c=1,dims(3)
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b,c) == 0) then
darray(a,b,c) = .false.
else
darray(a,b,c) = .true.
endif
enddo
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_3d_logical
subroutine hdf5_read_data_4d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:,:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:,:,:)
integer(8), dimension(4) :: dims
integer :: a,b,c,d
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(4) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
dims(3) = size(darrayi,3)
dims(4) = size(darrayi,4)
allocate(darray(dims(1),dims(2),dims(3),dims(4)))
do d=1,dims(4)
do c=1,dims(3)
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b,c,d) == 0) then
darray(a,b,c,d) = .false.
else
darray(a,b,c,d) = .true.
endif
enddo
enddo
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_4d_logical
subroutine hdf5_read_data_5d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:,:,:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:,:,:,:)
integer(8), dimension(5) :: dims
integer :: a,b,c,d,e
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(5) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
dims(3) = size(darrayi,3)
dims(4) = size(darrayi,4)
dims(5) = size(darrayi,5)
allocate(darray(dims(1),dims(2),dims(3),dims(4),dims(5)))
do e=1,dims(5)
do d=1,dims(4)
do c=1,dims(3)
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b,c,d,e) == 0) then
darray(a,b,c,d,e) = .false.
else
darray(a,b,c,d,e) = .true.
endif
enddo
enddo
enddo
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_5d_logical
subroutine hdf5_read_data_6d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:,:,:,:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:,:,:,:,:)
integer(8), dimension(6) :: dims
integer :: a,b,c,d,e,f
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(6) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
dims(3) = size(darrayi,3)
dims(4) = size(darrayi,4)
dims(5) = size(darrayi,5)
dims(6) = size(darrayi,6)
allocate(darray(dims(1),dims(2),dims(3),dims(4),dims(5),dims(6)))
do f=1,dims(6)
do e=1,dims(5)
do d=1,dims(4)
do c=1,dims(3)
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b,c,d,e,f) == 0) then
darray(a,b,c,d,e,f) = .false.
else
darray(a,b,c,d,e,f) = .true.
endif
enddo
enddo
enddo
enddo
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_6d_logical
subroutine hdf5_read_data_7d_logical(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
logical, allocatable, dimension(:,:,:,:,:,:,:) :: darray
integer(logical_size), allocatable :: darrayi(:,:,:,:,:,:,:)
integer(8), dimension(7) :: dims
integer :: a,b,c,d,e,f,g
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(7) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darrayi(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6), dset_dims(7)))
call h5dread_f(dset_id, logical_id, darrayi, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
dims(1) = size(darrayi,1)
dims(2) = size(darrayi,2)
dims(3) = size(darrayi,3)
dims(4) = size(darrayi,4)
dims(5) = size(darrayi,5)
dims(6) = size(darrayi,6)
dims(7) = size(darrayi,7)
allocate(darray(dims(1),dims(2),dims(3),dims(4),dims(5),dims(6),dims(7)))
do g=1,dims(7)
do f=1,dims(6)
do e=1,dims(5)
do d=1,dims(4)
do c=1,dims(3)
do b=1,dims(2)
do a=1,dims(1)
if (darrayi(a,b,c,d,e,f,g) == 0) then
darray(a,b,c,d,e,f,g) = .false.
else
darray(a,b,c,d,e,f,g) = .true.
endif
enddo
enddo
enddo
enddo
enddo
enddo
enddo
deallocate(darrayi)
end subroutine hdf5_read_data_7d_logical
subroutine hdf5_read_data_0d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4) :: darray
integer(hid_t) :: dset_id
integer(hsize_t), dimension(0) :: dset_dims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_0d_int4
subroutine hdf5_read_data_1d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(1) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_1d_int4
subroutine hdf5_read_data_2d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(2) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_2d_int4
subroutine hdf5_read_data_3d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(3) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_3d_int4
subroutine hdf5_read_data_4d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(4) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_4d_int4
subroutine hdf5_read_data_5d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(5) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_5d_int4
subroutine hdf5_read_data_6d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(6) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_6d_int4
subroutine hdf5_read_data_7d_int4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
integer(4), allocatable, dimension(:,:,:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(7) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6), dset_dims(7)))
call h5dread_f(dset_id, h5t_native_integer, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_7d_int4
subroutine hdf5_read_data_0d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4) :: darray
integer(hid_t) :: dset_id
integer(hsize_t), dimension(0) :: dset_dims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_0d_real4
subroutine hdf5_read_data_1d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(1) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_1d_real4
subroutine hdf5_read_data_2d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(2) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_2d_real4
subroutine hdf5_read_data_3d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(3) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_3d_real4
subroutine hdf5_read_data_4d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(4) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_4d_real4
subroutine hdf5_read_data_5d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(5) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_5d_real4
subroutine hdf5_read_data_6d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(6) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_6d_real4
subroutine hdf5_read_data_7d_real4(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(4), allocatable, dimension(:,:,:,:,:,:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(7) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2), dset_dims(3), dset_dims(4), dset_dims(5), dset_dims(6), dset_dims(7)))
call h5dread_f(dset_id, h5t_native_real, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_7d_real4
subroutine hdf5_read_data_0d_real8(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(8) :: darray
integer(hid_t) :: dset_id
integer(hsize_t), dimension(0) :: dset_dims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dread_f(dset_id, h5t_native_double, darray, dset_dims, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_0d_real8
subroutine hdf5_read_data_1d_real8(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(8), allocatable, dimension(:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(1) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1)))
call h5dread_f(dset_id, h5t_native_double, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_1d_real8
subroutine hdf5_read_data_2d_real8(ifile, dset, darray)
integer(hid_t), intent(in) :: ifile
character(len=*), intent(in) :: dset
real(8), allocatable, dimension(:,:) :: darray
integer(hid_t) :: dset_id, dset_space_id
integer(hsize_t), dimension(2) :: dset_dims, dset_maxdims
call h5dopen_f(ifile, trim(adjustl(dset)), dset_id, hdf_err)
call h5dget_space_f(dset_id, dset_space_id, hdf_err)
call h5sget_simple_extent_dims_f(dset_space_id, dset_dims, dset_maxdims, hdf_err)
allocate(darray(dset_dims(1), dset_dims(2)))
call h5dread_f(dset_id, h5t_native_double, darray, dset_dims, hdf_err)
call h5sclose_f(dset_space_id, hdf_err)
call h5dclose_f(dset_id, hdf_err)
end subroutine hdf5_read_data_2d_real8
subroutine hdf5_read_data_3d_real8(ifile, dset, darray)