-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModuleHDF5.f90
4109 lines (2896 loc) · 166 KB
/
ModuleHDF5.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
!------------------------------------------------------------------------------
! IST/MARETEC, Water Modelling Group, Mohid modelling system
!------------------------------------------------------------------------------
!
! TITLE : Mohid Model
! PROJECT : Mohid Base 1
! MODULE : HDF 5
! URL : http://www.mohid.com
! AFFILIATION : IST/MARETEC, Marine Modelling Group
! DATE : May 2003
! REVISION : Frank Braunschweig - v4.0
! DESCRIPTION : Module to Write/Read HDF 5 Files
!
!------------------------------------------------------------------------------
!
!This program is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public License
!version 2, as published by the Free Software Foundation.
!
!This program is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU General Public License for more details.
!
!You should have received a copy of the GNU General Public License
!along with this program; if not, write to the Free Software
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
!
!------------------------------------------------------------------------------
Module ModuleHDF5
use ModuleGlobalData
use HDF5
#ifdef _GUI_
use dfwin
use comctl32
#endif
implicit none
private
!Subroutines---------------------------------------------------------------
!Constructor
public :: ConstructHDF5
private :: AllocateInstance
!Modifier
public :: HDF5CreateGroup
private :: CreateMinMaxAttribute
private :: CheckGroupExistence
public :: HDF5SetLimits
public :: HDF5WriteData
private :: PrepareWrite
private :: FinishWrite
private :: UpdateMinMaxAttribute
private :: ConstructDSName
public :: HDF5WriteGlobalAttribute
public :: HDF5ReadData
public :: HDF5ReadHyperSlab
public :: HDF5FlushMemory
!Destructor
public :: KillHDF5
private :: DeallocateInstance
!Selector
public :: GetHDF5FileID
public :: GetHDF5FileAccess
public :: GetHDF5GroupID
public :: GetHDF5GroupNumberOfItems
public :: GetHDF5GroupExist
public :: GetHDF5DataSetExist
public :: GetHDF5ObjectInfo
#ifdef _GUI_
public :: HDF5InquireFile
private :: InquireSubGroup
private :: AddItemToHDFTree
public :: ConstructTreeViewImageLists
public :: HDF5ReadAttributes
public :: HDF5GetDimensions
#endif
!Management
private :: Ready
private :: LocateObjHDF5
interface HDF5WriteData
module procedure HDF5WriteDataR4_1D
module procedure HDF5WriteDataR4_2D
module procedure HDF5WriteDataR4_3D
module procedure HDF5WriteDataR8_1D
module procedure HDF5WriteDataR8_2D
module procedure HDF5WriteDataR8_3D
module procedure HDF5WriteDataI4_1D
module procedure HDF5WriteDataI4_2D
module procedure HDF5WriteDataI4_3D
end interface
interface HDF5ReadData
module procedure HDF5ReadDataR4_1D
module procedure HDF5ReadDataR4_2D
module procedure HDF5ReadDataR4_3D
module procedure HDF5ReadDataR8_1D
module procedure HDF5ReadDataR8_2D
module procedure HDF5ReadDataR8_3D
module procedure HDF5ReadDataI4_1D
module procedure HDF5ReadDataI4_2D
module procedure HDF5ReadDataI4_3D
end interface
!Parameter
integer, parameter :: HDF5_CREATE_ = 1
integer, parameter :: HDF5_READ_ = 2
integer, parameter :: HDF5_READWRITE_ = 3
!Type definition
type T_Limits
integer :: ILB, IUB
integer :: JLB, JUB
integer :: KLB, KUB
end type T_Limits
!GUI
type T_HDF5_DATA_ITEM
sequence
integer :: ItemType
character(Pathlength) :: FileName
character(StringLength) :: GroupName
character(StringLength) :: ItemName
integer :: Rank
integer :: NumType
integer, dimension(7) :: Dims
end type T_HDF5_DATA_ITEM
type T_AuxMatrixes
real(4), dimension(: ), pointer :: DataR4_1D
real(4), dimension(:,: ), pointer :: DataR4_2D
real(4), dimension(:,:,:), pointer :: DataR4_3D
real(8), dimension(: ), pointer :: DataR8_1D
real(8), dimension(:,: ), pointer :: DataR8_2D
real(8), dimension(:,:,:), pointer :: DataR8_3D
integer, dimension(: ), pointer :: DataI4_1D
integer, dimension(:,: ), pointer :: DataI4_2D
integer, dimension(:,:,:), pointer :: DataI4_3D
integer, dimension(7) :: dims_R4_1D
integer, dimension(7) :: dims_R4_2D
integer, dimension(7) :: dims_R4_3D
integer, dimension(7) :: dims_R8_1D
integer, dimension(7) :: dims_R8_2D
integer, dimension(7) :: dims_R8_3D
integer, dimension(7) :: dims_I4_1D
integer, dimension(7) :: dims_I4_2D
integer, dimension(7) :: dims_I4_3D
end type T_AuxMatrixes
type T_HDF5
integer :: InstanceID
integer (HID_T) :: FileID
character(Pathlength) :: FileName
type (T_Limits) :: Limits
type (T_AuxMatrixes) :: AuxMatrixes
type (T_HDF5), pointer :: Next
end type T_HDF5
!Global Module Variables
type (T_HDF5), pointer :: FirstHDF5
logical :: FirstPassage = .true.
type (T_HDF5), pointer :: Me
!GUI
integer, parameter :: TypeFile = 1
integer, parameter :: TypeVG = 2
integer, parameter :: TypeSDS = 3
integer, parameter :: TypeAttr = 4
integer :: IconFile
integer :: IconVG
integer :: IconSDS
integer :: IconSDS1
integer :: IconAttr
integer :: IconVG1
contains
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
subroutine ConstructHDF5 (HDF5ID, FileName, Access, STAT)
#ifdef _GUI_
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, REFERENCE, ALIAS : '_ConstructHDF5@16' :: ConstructHDF5
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, REFERENCE, ALIAS : 'ConstructHDF5' :: ConstructHDF5
!DEC$ ENDIF
#endif
!Arguments-------------------------------------------------------------
integer :: HDF5ID
character(len=*) :: FileName
integer :: Access
integer(4), optional :: STAT
!Local-----------------------------------------------------------------
integer(4) :: STAT_CALL
integer :: STAT_, ready_
!Begin-----------------------------------------------------------------
STAT_ = UNKNOWN_
!Assures nullification of the global variable
if (FirstPassage) then
nullify (FirstHDF5)
FirstPassage = .false.
endif
call Ready (HDF5ID, ready_)
if (ready_ .EQ. OFF_ERR_) then
!Allocates a new Instance
call AllocateInstance
!Initializes predefined datatypes
call h5open_f (STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'ConstructHDF5 - ModuleHDF5 - ERR00'
!Open the file
if (Access == HDF5_CREATE_) then
call h5fcreate_f(FileName, ACCESS_FLAGS = H5F_ACC_TRUNC_F, &
FILE_ID = Me%FileID, HDFERR = STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'ConstructHDF5 - ModuleHDF5 - ERR01'
elseif (Access == HDF5_READ_) then
call h5fopen_f (FileName, ACCESS_FLAGS = H5F_ACC_RDONLY_F, &
FILE_ID = Me%FileID, HDFERR = STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'ConstructHDF5 - ModuleHDF5 - ERR02'
elseif (Access == HDF5_READWRITE_) then
call h5fopen_f (FileName, ACCESS_FLAGS = H5F_ACC_RDWR_F, &
FILE_ID = Me%FileID, HDFERR = STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'ConstructHDF5 - ModuleHDF5 - ERR03'
else
if (STAT_CALL /= SUCCESS_) stop 'ConstructHDF5 - ModuleHDF5 - ERR04'
endif
nullify(Me%AuxMatrixes%DataR4_1D, Me%AuxMatrixes%DataR4_2D, Me%AuxMatrixes%DataR4_3D, &
Me%AuxMatrixes%DataR8_1D, Me%AuxMatrixes%DataR8_2D, Me%AuxMatrixes%DataR8_3D, &
Me%AuxMatrixes%DataI4_1D, Me%AuxMatrixes%DataI4_2D, Me%AuxMatrixes%DataI4_3D)
!Stores FileName
Me%FileName = FileName
!Returns ID
HDF5ID = Me%InstanceID
else
stop 'ModuleHDF5 - ConstructHDF5 - ERR99'
endif
STAT_ = SUCCESS_
if (present(STAT)) STAT = STAT_
end subroutine ConstructHDF5
!--------------------------------------------------------------------------
subroutine AllocateInstance
!Arguments-------------------------------------------------------------
!Local-----------------------------------------------------------------
type (T_HDF5), pointer :: NewHDF5
type (T_HDF5), pointer :: PreviousHDF5
!Allocates new instance
allocate (NewHDF5)
nullify (NewHDF5%Next)
!Insert New Instance into list and makes Current point to it
if (.not. associated(FirstHDF5)) then
FirstHDF5 => NewHDF5
Me => NewHDF5
else
PreviousHDF5 => FirstHDF5
Me => FirstHDF5%Next
do while (associated(Me))
PreviousHDF5 => Me
Me => Me%Next
enddo
Me => NewHDF5
PreviousHDF5%Next => NewHDF5
endif
Me%InstanceID = RegisterNewInstance (mHDF5_)
end subroutine AllocateInstance
!--------------------------------------------------------------------------
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!MODIFIER MODIFIER MODIFIER MODIFIER MODIFIER MODIFIER MODIFIER MODIFIER MO
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
subroutine HDF5CreateGroup (HDF5ID, GroupName, STAT)
!Arguments-------------------------------------------------------------
integer :: HDF5ID
character(len=*) :: GroupName
integer, optional :: STAT
!Local-----------------------------------------------------------------
integer :: STAT_, ready_
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
!Recursivly creates all Groups
call CheckGroupExistence (Me%FileID, GroupName)
STAT_ = SUCCESS_
else
STAT_ = ready_
endif
if (present(STAT)) STAT = STAT_
end subroutine HDF5CreateGroup
!--------------------------------------------------------------------------
subroutine HDF5SetLimits (HDF5ID, ILB, IUB, JLB, JUB, KLB, KUB, STAT)
!Arguments-------------------------------------------------------------
integer :: HDF5ID
integer, optional :: ILB, IUB
integer, optional :: JLB, JUB
integer, optional :: KLB, KUB
integer, optional :: STAT
!Local-----------------------------------------------------------------
integer :: STAT_, ready_
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
if (present(ILB)) Me%Limits%ILB = ILB
if (present(IUB)) Me%Limits%IUB = IUB
if (present(JLB)) Me%Limits%JLB = JLB
if (present(JUB)) Me%Limits%JUB = JUB
if (present(KLB)) Me%Limits%KLB = KLB
if (present(KUB)) Me%Limits%KUB = KUB
STAT_ = SUCCESS_
else
STAT_ = ready_
endif
if (present(STAT)) STAT = STAT_
end subroutine HDF5SetLimits
!--------------------------------------------------------------------------
subroutine CreateMinMaxAttribute (ID, Units, Minimum, Maximum)
!Arguments-------------------------------------------------------------
integer(HID_T) :: ID
character(len=*), optional :: Units
real(4), optional :: Minimum, Maximum
!Local-----------------------------------------------------------------
integer(HID_T) :: space_id
integer(HID_T) :: attr_id1, attr_id2, attr_id3
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: STAT_CALL
INTEGER(HID_T) :: new_type_id
!Creates data space for Minimum and Maximum attributes
call h5screate_f (H5S_SCALAR_F, space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR01'
!Creates attribute Minimum
call h5acreate_f(ID, "Minimum", H5T_NATIVE_REAL, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR02'
!Creates attribute Maximum
call h5acreate_f(ID, "Maximum", H5T_NATIVE_REAL, space_id, attr_id2, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR03'
!Writes Miniumum
if (present(Minimum)) then
call h5awrite_f (attr_id1, H5T_NATIVE_REAL, Minimum, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR04'
else
call h5awrite_f (attr_id1, H5T_NATIVE_REAL, -FillValueReal, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR05'
endif
!Writes Maximum
if (present(Maximum)) then
call h5awrite_f (attr_id2, H5T_NATIVE_REAL, Maximum, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR06'
else
call h5awrite_f (attr_id2, H5T_NATIVE_REAL, FillValueReal, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR07'
endif
!Closes Minimum
call h5aclose_f (attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR08'
!Closes Maximum
call h5aclose_f (attr_id2, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR09'
!Closes dataspaces
call h5sclose_f (space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR10'
if (present(Units)) then
!Creates data space for Units
call h5screate_f (H5S_SCALAR_F, space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR11'
!Copies Type
call h5Tcopy_f (H5T_NATIVE_CHARACTER, new_type_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR12'
!Sets Size
call h5Tset_size_f (new_type_id, len_trim(Units), STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR13'
!Creates attribute
call h5acreate_f (ID, "Units", new_type_id, space_id, attr_id3, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR14'
!Writes attribute
call h5awrite_f (attr_id3, new_type_id, Units, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR15'
!Close type id
call h5Tclose_f (new_type_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR16'
!Closes attribute
call h5aclose_f (attr_id3, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR17'
!Closes dataspaces
call h5sclose_f (space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateMinMaxAttribute - ModuleHDF5 - ERR18'
endif
end subroutine CreateMinMaxAttribute
!--------------------------------------------------------------------------
!--------------------------------------------------------------------------
subroutine CreateAverageRadiusAttribute (ID, Average, Radius)
!Arguments-------------------------------------------------------------
integer(HID_T) :: ID
real(4) :: Average, Radius
!Local-----------------------------------------------------------------
integer(HID_T) :: space_id
integer(HID_T) :: attr_id1, attr_id2
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: STAT_CALL
!Creates data space for Average and Radius attributes
call h5screate_f (H5S_SCALAR_F, space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR10'
!Creates attribute Average
call h5acreate_f(ID, "Average", H5T_NATIVE_REAL, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR20'
!Creates attribute Radius
call h5acreate_f(ID, "Radius" , H5T_NATIVE_REAL, space_id, attr_id2, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR30'
!Write Average
call h5awrite_f (attr_id1, H5T_NATIVE_REAL, Average, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR40'
!Writes Radius
call h5awrite_f (attr_id2, H5T_NATIVE_REAL, Radius, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR50'
!Closes Average
call h5aclose_f (attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR60'
!Closes Radius
call h5aclose_f (attr_id2, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR70'
!Closes dataspaces
call h5sclose_f (space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'CreateAverageRadiusAttribute - ModuleHDF5 - ERR80'
end subroutine CreateAverageRadiusAttribute
!--------------------------------------------------------------------------
subroutine UpdateMinMaxAttribute (ID, Minimum, Maximum)
!Arguments-------------------------------------------------------------
integer(HID_T) :: ID
real(4) :: Minimum, Maximum
!Local-----------------------------------------------------------------
integer(HID_T) :: attr_id
integer(HID_T) :: STAT_CALL
integer(HSIZE_T), dimension(7) :: dims
real :: OldValue = 0
!Opens Minimum attribute
call h5aopen_name_f (ID, "Minimum", attr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR01'
!Reads Value
call h5aread_f (attr_id, H5T_NATIVE_REAL, OldValue, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR02'
if (Minimum < OldValue) then
call h5awrite_f (attr_id, H5T_NATIVE_REAL, Minimum, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR03'
endif
!Closes attribute
call h5aclose_f (attr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR04'
!Opens Maximum attribute
call h5aopen_name_f (ID, "Maximum", attr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR05'
!Reads Value
call h5aread_f (attr_id, H5T_NATIVE_REAL, OldValue, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR06'
if (Maximum > OldValue) then
call h5awrite_f (attr_id, H5T_NATIVE_REAL, Maximum, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR07'
endif
!Closes attribute
call h5aclose_f (attr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'UpdateMinMaxAttribute - ModuleHDF5 - ERR08'
end subroutine UpdateMinMaxAttribute
!--------------------------------------------------------------------------
subroutine HDF5WriteGlobalAttribute(HDF5ID, GroupName, AttributeName, Att_Char, &
Att_Int, Att_Real, Att_Dble, STAT)
!Arguments-------------------------------------------------------------
integer , intent(in) :: HDF5ID
character(len=*) , intent(in) :: GroupName
character(len=*) , intent(in) :: AttributeName
character(len=*), optional, intent(in) :: Att_Char
integer , optional, intent(in) :: Att_Int
real(4) , optional, intent(in) :: Att_Real
real(8) , optional, intent(in) :: Att_Dble
integer , optional, intent(out) :: STAT
!Local-----------------------------------------------------------------
integer(HID_T) :: space_id
integer(HID_T) :: attr_id1
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: new_type_id, gr_id
integer :: STAT_, ready_, STAT_CALL
!Begin-----------------------------------------------------------------
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
call CheckGroupExistence(Me%FileID, GroupName, .false.)
!Opens the group
call h5gopen_f (Me%FileID, GroupName, gr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR00'
!Creates data space for attribute
call h5screate_f (H5S_SCALAR_F, space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR01'
if(present(Att_Char))then
!Copies Type
call h5Tcopy_f (H5T_NATIVE_CHARACTER, new_type_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR02'
!Sets Size
call h5Tset_size_f (new_type_id, len_trim(Att_Char), STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR03'
!Creates attribute
call h5acreate_f (gr_id, trim(AttributeName), new_type_id, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR04'
!Writes attribute
call h5awrite_f (attr_id1, new_type_id, Att_Char, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR05'
elseif(present(Att_Int))then
!Creates attribute
call h5acreate_f (gr_id, trim(AttributeName), H5T_NATIVE_INTEGER, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR06'
!Writes attribute
call h5awrite_f (attr_id1, H5T_NATIVE_INTEGER, Att_Int, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR07'
elseif(present(Att_Real))then
!Creates attribute
call h5acreate_f (gr_id, trim(AttributeName), H5T_NATIVE_REAL, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR08'
!Writes attribute
call h5awrite_f (attr_id1, H5T_NATIVE_REAL, Att_Real, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR09'
elseif(present(Att_Dble))then
!Creates attribute
call h5acreate_f (gr_id, trim(AttributeName), H5T_NATIVE_DOUBLE, space_id, attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR10'
!Writes attribute
call h5awrite_f (attr_id1, H5T_NATIVE_DOUBLE, Att_Dble, dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR11'
else
write(*,*)"No attribute value given"
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR12'
endif
!Closes attribute
call h5aclose_f (attr_id1, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR13'
!Closes dataspaces
call h5sclose_f (space_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR14'
!Closes group
call h5gclose_f(gr_id, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteGlobalAttribute - ModuleHDF5 - ERR14'
STAT_ = SUCCESS_
else
STAT_ = ready_
endif
if (present(STAT)) STAT = STAT_
end subroutine HDF5WriteGlobalAttribute
!--------------------------------------------------------------------------
subroutine HDF5WriteDataR4_1D (HDF5ID, GroupName, Name, Units, &
Array1D, Average, Radius, OutputNumber, STAT)
!Arguments-------------------------------------------------------------
integer :: HDF5ID
character(len=*) :: GroupName
character(len=*) :: Name
character(len=*) :: Units
real(4), dimension(:) , pointer :: Array1D
real(4), optional :: Average
real(4), optional :: Radius
integer, optional :: OutputNumber
integer, optional :: STAT
!Local-----------------------------------------------------------------
integer :: STAT_, ready_
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: Rank
integer(HID_T) :: NumType
integer(HID_T) :: space_id
integer(HID_T) :: STAT_CALL
integer(HID_T) :: dset_id, prp_id, gr_id
character(StringLength) :: AuxChar
real(4) :: Minimum, Maximum
logical :: AllocateMatrix
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
NumType = H5T_NATIVE_REAL
Rank = 1
Minimum = minval(Array1D(Me%Limits%ILB:Me%Limits%IUB))
Maximum = maxval(Array1D(Me%Limits%ILB:Me%Limits%IUB))
dims(1) = Me%Limits%IUB - Me%Limits%ILB + 1
!Creates the dataset with default properties
if (present(OutputNumber)) then
call ConstructDSName (Name, OutputNumber, AuxChar)
else
AuxChar = Name
endif
!Opens Group, Creates Dset, etc
call PrepareWrite (Me%FileID, Rank, dims, space_id, prp_id, gr_id, &
dset_id, NumType, GroupName, trim(adjustl(AuxChar)))
AllocateMatrix = .false.
if (.not.Associated(Me%AuxMatrixes%DataR4_1D)) then
AllocateMatrix = .true.
else if (Me%AuxMatrixes%dims_R4_1D(1) /= dims(1)) then
deallocate(Me%AuxMatrixes%DataR4_1D)
nullify (Me%AuxMatrixes%DataR4_1D)
AllocateMatrix = .true.
endif
if (AllocateMatrix) then
allocate(Me%AuxMatrixes%DataR4_1D(1:dims(1)))
Me%AuxMatrixes%dims_R4_1D(1) = dims(1)
endif
Me%AuxMatrixes%DataR4_1D(1:dims(1)) = Array1D(Me%Limits%ILB:Me%Limits%IUB)
!Writes the data to the file
call h5dwrite_f (dset_id, NumType, &
Me%AuxMatrixes%DataR4_1D, &
dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteDataR4 - ModuleHDF5 - ERR08'
!Creates attributes
call CreateMinMaxAttribute (dset_id, Units, Minimum, Maximum)
if (present(Average) .and. present(Radius)) &
call CreateAverageRadiusAttribute (dset_id, Average, Radius)
!Updates attributes of Group
call UpdateMinMaxAttribute (gr_id, Minimum, Maximum)
!Closes Group, Releases Dset, etc
call FinishWrite (space_id, prp_id, gr_id, dset_id)
STAT_ = SUCCESS_
else
STAT_ = ready_
endif
if (present(STAT)) STAT = STAT_
end subroutine HDF5WriteDataR4_1D
!--------------------------------------------------------------------------
subroutine HDF5WriteDataR4_2D (HDF5ID, GroupName, Name, Units, &
Array2D, OutputNumber, STAT)
!Arguments-------------------------------------------------------------
integer :: HDF5ID
character(len=*) :: GroupName
character(len=*) :: Name
character(len=*) :: Units
real(4), dimension(:, :) , pointer :: Array2D
integer, optional :: OutputNumber
integer, optional :: STAT
!Local-----------------------------------------------------------------
integer :: STAT_, ready_
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: Rank
integer(HID_T) :: NumType
integer(HID_T) :: space_id
integer(HID_T) :: STAT_CALL
integer(HID_T) :: dset_id, prp_id, gr_id
character(StringLength) :: AuxChar
real(4) :: Minimum, Maximum
logical :: AllocateMatrix
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
NumType = H5T_NATIVE_REAL
Rank = 2
Minimum = minval(Array2D(Me%Limits%ILB:Me%Limits%IUB, &
Me%Limits%JLB:Me%Limits%JUB))
Maximum = maxval(Array2D(Me%Limits%ILB:Me%Limits%IUB, &
Me%Limits%JLB:Me%Limits%JUB))
dims(1) = Me%Limits%IUB - Me%Limits%ILB + 1
dims(2) = Me%Limits%JUB - Me%Limits%JLB + 1
!Creates the dataset with default properties
if (present(OutputNumber)) then
call ConstructDSName (Name, OutputNumber, AuxChar)
else
AuxChar = Name
endif
!Opens Group, Creates Dset, etc
call PrepareWrite (Me%FileID, Rank, dims, space_id, prp_id, gr_id, &
dset_id, NumType, GroupName, trim(adjustl(AuxChar)))
AllocateMatrix = .false.
if (.not.Associated(Me%AuxMatrixes%DataR4_2D)) then
AllocateMatrix = .true.
else if (Me%AuxMatrixes%dims_R4_2D(1) /= dims (1) .or. &
Me%AuxMatrixes%dims_R4_2D(2) /= dims (2)) then
deallocate(Me%AuxMatrixes%DataR4_2D)
nullify (Me%AuxMatrixes%DataR4_2D)
AllocateMatrix = .true.
endif
if (AllocateMatrix) then
allocate(Me%AuxMatrixes%DataR4_2D(dims (1), dims (2)))
Me%AuxMatrixes%dims_R4_2D(1:2) = dims(1:2)
endif
Me%AuxMatrixes%DataR4_2D(1:dims(1), 1:dims(2)) = &
Array2D(Me%Limits%ILB:Me%Limits%IUB, &
Me%Limits%JLB:Me%Limits%JUB)
!Writes the data to the file
call h5dwrite_f (dset_id, NumType, &
Me%AuxMatrixes%DataR4_2D, &
dims, STAT_CALL)
if (STAT_CALL /= SUCCESS_) stop 'HDF5WriteDataR4 - ModuleHDF5 - ERR08a'
!Creates attributes
call CreateMinMaxAttribute (dset_id, Units, Minimum, Maximum)
!Updates attributes of Group
call UpdateMinMaxAttribute (gr_id, Minimum, Maximum)
!Closes Group, Releases Dset, etc
call FinishWrite (space_id, prp_id, gr_id, dset_id)
STAT_ = SUCCESS_
else
STAT_ = ready_
endif
if (present(STAT)) STAT = STAT_
end subroutine HDF5WriteDataR4_2D
!--------------------------------------------------------------------------
subroutine HDF5WriteDataR4_3D (HDF5ID, GroupName, Name, Units, &
Array3D, OutputNumber, STAT)
!Arguments-------------------------------------------------------------
integer :: HDF5ID
character(len=*) :: GroupName
character(len=*) :: Name
character(len=*) :: Units
real(4), dimension(:, :, :), pointer :: Array3D
integer, optional :: OutputNumber
integer, optional :: STAT
!Local-----------------------------------------------------------------
integer :: STAT_, ready_
integer(HSIZE_T), dimension(7) :: dims
integer(HID_T) :: Rank
integer(HID_T) :: NumType
integer(HID_T) :: space_id
integer(HID_T) :: STAT_CALL
integer(HID_T) :: dset_id, prp_id, gr_id
character(StringLength) :: AuxChar
real(4) :: Minimum, Maximum
logical :: AllocateMatrix
STAT_ = UNKNOWN_
call Ready (HDF5ID, ready_)
if (ready_ .EQ. IDLE_ERR_) then
NumType = H5T_NATIVE_REAL
Rank = 3
Minimum = minval(Array3D(Me%Limits%ILB:Me%Limits%IUB, &
Me%Limits%JLB:Me%Limits%JUB, &
Me%Limits%KLB:Me%Limits%KUB))
Maximum = maxval(Array3D(Me%Limits%ILB:Me%Limits%IUB, &
Me%Limits%JLB:Me%Limits%JUB, &
Me%Limits%KLB:Me%Limits%KUB))
dims(1) = Me%Limits%IUB - Me%Limits%ILB + 1
dims(2) = Me%Limits%JUB - Me%Limits%JLB + 1
dims(3) = Me%Limits%KUB - Me%Limits%KLB + 1
!Creates the dataset with default properties
if (present(OutputNumber)) then
call ConstructDSName (Name, OutputNumber, AuxChar)
else
AuxChar = Name
endif
!Opens Group, Creates Dset, etc
call PrepareWrite (Me%FileID, Rank, dims, space_id, prp_id, gr_id, &
dset_id, NumType, GroupName, trim(adjustl(AuxChar)))
AllocateMatrix = .false.
if (.not.Associated(Me%AuxMatrixes%DataR4_3D)) then
AllocateMatrix = .true.
else if (Me%AuxMatrixes%dims_R4_3D(1) /= dims (1) .or. &
Me%AuxMatrixes%dims_R4_3D(2) /= dims (2) .or. &
Me%AuxMatrixes%dims_R4_3D(3) /= dims (3)) then
deallocate(Me%AuxMatrixes%DataR4_3D)
nullify (Me%AuxMatrixes%DataR4_3D)