-
Notifications
You must be signed in to change notification settings - Fork 0
/
Triple_decomposition_analysis_binary_input_file.f90
3517 lines (2849 loc) · 114 KB
/
Triple_decomposition_analysis_binary_input_file.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
! dataanalysis.f90
!****************************************************************************
!
! PROGRAM: dataanalysis
!
! Version 2
! by Stefan Felder - August 2009 -
!
! in this version, the triple decomposition analyses are conducted with a factor! please note, that the mean calculations (i.e. low) are
! standing for the calculations of correlations of slow+fast velocity fluctuations
!
!****************************************************************************
program dataanalysis
implicit none
!Parameters
INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=15) !Precision of the Real(kind=DBL)
!variables
integer, parameter :: short = SELECTED_INT_KIND(3)
!General variables
!parameters to be loaded from file
REAL :: delta_x
INTEGER :: frequency
INTEGER :: Correlation_steps
INTEGER :: sample_duration
INTEGER :: Number_devices
INTEGER :: segment_numbers
REAL :: PDF_V_segment_size
INTEGER :: max_no_bubbles
REAL :: threshold_C
REAL :: PDF_Court_length_segment_size
REAL :: PDF_Court_time_segment_size
REAL :: PDF_Court_min_length
REAL :: PDF_Court_max_length
REAL :: PDF_Court_min_time
REAL :: PDF_Court_max_time
INTEGER :: cluster_or_not
REAL :: cluster_factor
REAL :: cluster_factor_1
REAL :: lower_frequency
REAL :: upper_frequency ! threshold in frequency)
INTEGER :: FFT_number ! integer for FFT analysis (2^n)
INTEGER :: Correlation_steps_mid
INTEGER :: Correlation_steps_low
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Data_array
CHARACTER(len=9) :: name_parameters !name of file with parameters to be opened
CHARACTER(len=9) :: name !name of file with positions to be opened
CHARACTER(len=6) :: name_binary
CHARACTER(len=8) :: location_binary
CHARACTER(len=4) :: position
CHARACTER(len=8) :: position_binary
CHARACTER(len=4) :: ending = '.txt'
CHARACTER(len=1) :: sample = '_'
INTEGER :: number_rows = 0 !number of rows to read
INTEGER :: status = 0 !I/O status
REAL(kind=DBL) :: value = 0
INTEGER :: number_positions = 0
CHARACTER(len=8), ALLOCATABLE, DIMENSION(:) :: Position_array_binary
CHARACTER(len=4), ALLOCATABLE, DIMENSION(:) :: Position_array
INTEGER :: number_positions_binary =0
CHARACTER(len=4) :: location
INTEGER :: number_columns = 0
INTEGER :: i,j,k
INTEGER (KIND=short) :: x, y
character(len=8) :: header
!data arrays for annalyses
! Variables for correlation-analyses
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_raw !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_raw !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_high !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_high !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_mid !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_mid !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_low !results_file
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_low !results_file
! for cross-products
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_fast_low
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_fast_low
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Autocorrelation_low_fast
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Crosscorrelation_low_fast
!Variables for Propability density distribution of Voltage signal for both probe tips
REAL(kind=DBL) :: PDF_segments = 0 !Number of segments for PDF
REAL(kind=DBL), ALLOCATABLE, DIMENSION (: , :) :: PDF_V
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:) :: threshold !results_file
!Variables for Correlation-scale analyses
REAL(kind=DBL), DIMENSION(15) :: CorScale_results_raw !summary file with Correlation properties (raw)
REAL(kind=DBL), DIMENSION(18) :: CorScale_results_high !summary file with Correlation properties (high)
REAL(kind=DBL), DIMENSION(18) :: CorScale_results_mid !summary file with Correlation properties (mid)
REAL(kind=DBL), DIMENSION(16) :: CorScale_results_low !summary file with Correlation properties (mid)
REAL(kind=DBL) :: velocity = 3 !default value
!Variables for basic property analyses (air-water-interfaces, void fraction, frequency)
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: interfaces !interfaces
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: basic_results !C and F
!Variables for chord time and size distributions
REAL(kind=DBL) :: PDF_number_chord = 0
REAL(kind=DBL) :: PDF_number_time = 0
!variables for low and high pass filtering
INTEGER :: Int_spectral_analys ! Integer for spectral analyses
REAL(kind=DBL) :: sample_step ! time step between data points
REAL(kind=DBL) :: total_FFT_duration
REAL(kind=DBL) :: frequency_FFT
INTEGER :: Cutoff_time_low_lower
INTEGER :: Cutoff_time_low_upper
INTEGER :: Cutoff_time_mid_lower
INTEGER :: Cutoff_time_mid_upper
INTEGER :: Cutoff_time_high_upper
INTEGER :: Cutoff_time_high_lower
REAL(kind=DBL) :: helper_time
REAL(kind=DBL) :: last_point_2
REAL(kind=DBL) :: last_point_3
REAL(kind=DBL) :: Total
REAL(kind=DBL) :: Mean(3)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: FFT_array
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_low !(0-0.33Hz)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_low_out !(0-0.33Hz)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_mid !(0.33-10Hz)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_high !(10-10000Hz)
! data for correlation analyses of cut off data (3 seconds at each end cut off, e.g. 900000points- 2*60000 = 780000)
INTEGER :: number_rows_cut = 0
REAL(kind=DBL) :: Auto_fac
REAL(kind=DBL) :: Cross_fac
REAL(kind=DBL) :: Factors_crossproduct(3)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Data_array_cut !(cut_array_for_correlation_analyses (3 sec at both ends cut off)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_low_out_cut !(cut_array_for_correlation_analyses (3 sec at both ends cut off)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_mid_cut !(cut_array_for_correlation_analyses (3 sec at both ends cut off)
REAL(kind=DBL), ALLOCATABLE, DIMENSION(:,:) :: Filtered_array_high_cut !(cut_array_for_correlation_analyses (3 sec at both ends cut off)
!Open file to get parameters from parameter file
!Get the filename of the list of parameters for the analyses
WRITE (*,*) 'Please input file name with parameters:'
READ (*,*) name_parameters
WRITE (*,501) name_parameters
501 format (' ', 'The filename is: ', A '.txt')
OPEN (UNIT = 21, FILE = name_parameters // ending, STATUS = 'OLD', ACTION ='READ', IOSTAT=status)
IF (status == 0) THEN
READ (21, 100) delta_x
100 FORMAT (//, 1F5.2)
READ(21, 101) frequency
101 FORMAT (/, 1I7)
READ(21, 102) Correlation_steps
102 FORMAT (/, 1I5)
READ(21, 103) sample_duration
103 FORMAT (//, 1I5)
READ(21, 104) Number_devices
104 FORMAT (//, 1I1)
READ(21, 105) segment_numbers
105 FORMAT (/, 1I4)
READ(21, 106) PDF_V_segment_size
106 FORMAT (//, 1F5.2)
READ(21, 107) max_no_bubbles
107 FORMAT (/, 1I6)
READ(21, 108) threshold_C
108 FORMAT (//, 1F5.2)
READ(21, 109) PDF_Court_length_segment_size
109 FORMAT (/, 1F5.2)
READ(21, 110) PDF_Court_time_segment_size
110 FORMAT (/, 1F5.2)
READ(21, 111) PDF_Court_min_length
111 FORMAT (/, 1F5.2)
READ(21, 112) PDF_Court_max_length
112 FORMAT (/, 1F5.2)
READ(21, 113) PDF_Court_min_time
113 FORMAT (/, 1F5.2)
READ(21, 114) PDF_Court_max_time
114 FORMAT (/, 1F5.2)
READ(21, 115) cluster_or_not
115 FORMAT (/, 1I1)
READ(21, 116) cluster_factor
116 FORMAT (//, 1F5.2)
READ(21, 117) cluster_factor_1
117 FORMAT (/, 1F5.2)
READ(21, 118) lower_frequency
118 FORMAT (/, 1F5.2)
READ (21,119) upper_frequency
119 FORMAT (/, 1F5.2)
READ (21,120) FFT_number
120 FORMAT (/, 1I8)
READ (21,121) Correlation_steps_mid
121 FORMAT (/, 1I5)
READ (21,122) Correlation_steps_low
122 FORMAT (/, 1I5)
END IF
CLOSE ( UNIT=21)
!Allocate arrays for results with parameters
ALLOCATE (basic_results(Number_devices*2, 1), STAT =status)
!Write Headings to result-files. Note: This needs to be done before the main loops-starts because the
!heading should just appear once in the sumary result files (Tu_V, basics and chordlength/-times
OPEN (UNIT = 50, FILE = 'Tu_V_summary_raw' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (50, 150) 'Position', ' T0.5 ', ' T(Rxx=0) ', ' T(Min(Rxx)) ', ' Min(Rxx) ', ' Txx ', ' (Rxz)max ' , ' T(Rxz)max ', ' T(Rxz=0)&
' , ' T(Min(Rxz)) ', ' Min(Rxz) ', ' T(0.5(Rxz)max) ' , ' Txz ' , ' Tu ' , ' V ', '(Tu*V)'
150 FORMAT (A9, T11, A5, T21, A9, T31, A12, T43, A9, T52, A4, T62, A9, T72, A10, T83, A9, T94,&
A12, T106, A9, T115, A15, T131, A4, T141, A3, T151, A2, T161, A6)
OPEN (UNIT = 94, FILE = 'Tu_V_summary_high' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (94, 1050) 'Position', ' T0.5 ', ' T(Rxx=0) ', ' T(Min(Rxx)) ', ' Min(Rxx) ', ' Txx ', ' (Rxz)max ' , ' T(Rxz)max ', ' T(Rxz=0)&
' , ' T(Min(Rxz)) ', ' Min(Rxz) ', ' T(0.5(Rxz)max) ' , ' Txz ' , ' Tu ' , ' V ', '(Tu*V)', ' Rxx_max ', 'Rxx_fact', 'Rxz_fact'
1050 FORMAT (A9, T11, A5, T21, A9, T31, A12, T43, A9, T52, A4, T62, A9, T72, A10, T83, A9, T94,&
A12, T106, A9, T115, A15, T131, A4, T141, A3, T151, A2, T161, A6, T172, A8, T182, A8, T192, A8)
OPEN (UNIT = 95, FILE = 'Tu_V_summary_mid' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (95, 1051) 'Position', ' T0.5 ', ' T(Rxx=0) ', ' T(Min(Rxx)) ', ' Min(Rxx) ', ' Txx ', ' (Rxz)max ' , ' T(Rxz)max ', ' T(Rxz=0)&
' , ' T(Min(Rxz)) ', ' Min(Rxz) ', ' T(0.5(Rxz)max) ' , ' Txz ' , ' Tu ' , ' V ', '(Tu*V)', ' Rxx_max ', 'Rxx_fact', 'Rxz_fact'
1051 FORMAT (A9, T11, A5, T21, A9, T31, A12, T43, A9, T52, A4, T62, A9, T72, A10, T83, A9, T94,&
A12, T106, A9, T115, A15, T131, A4, T141, A3, T151, A2, T161, A6, T172, A8, T182, A8, T192, A8)
OPEN (UNIT = 96, FILE = 'Tu_V_summary_sum_fast_slow_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (96, 1052) 'Position', ' T0.5 ', ' T(Rxx=0) ', ' T(Min(Rxx)) ', ' Min(Rxx) ', ' Txx ', ' (Rxz)max ' , ' T(Rxz)max ', ' T(Rxz=0)&
' , ' T(Min(Rxz)) ', ' Min(Rxz) ', ' T(0.5(Rxz)max) ' , ' Txz ' , ' Tu ' , ' V ', '(Tu*V)', ' Rxx_max '
1052 FORMAT (A9, T11, A5, T21, A9, T31, A12, T43, A9, T52, A4, T62, A9, T72, A10, T83, A9, T94,&
A12, T106, A9, T115, A15, T131, A4, T141, A3, T151, A2, T161, A6, T172, A8)
OPEN (UNIT = 52, FILE = 'basics_summary' // ending , STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (52, 152) 'Position', 'C-leading', 'F-leading', 'C-trailing', 'F-trailing'
152 FORMAT (A9, T11, A10, T22, A10, T33, A11, T45, A11, T57)
! factor for crossproduct correlations for slow and fast fluctuations
OPEN (UNIT = 520, FILE = 'factors_crossproduct_fast_slow' // ending , STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (520, 252) 'Position', 'Auto_factor', 'Cross_slow_fast', 'Cross_fast_slow'
252 FORMAT (A9, T11, A11, T23, A15, T39, A15, T54)
number_columns = Number_devices + 1 !Columns to be allocated in the arrays
!depending on the number of devices used
number_rows = frequency * sample_duration !Rows to be allocated in the data array
PDF_segments = REAL(6.0)/PDF_V_segment_size !Number of segments for PDF (segments between 0 and 10V)
PDF_number_chord = 1+(PDF_Court_max_length-PDF_Court_min_length)/PDF_Court_length_segment_size
PDF_number_time = 1+(PDF_Court_max_time-PDF_Court_min_time)/PDF_Court_time_segment_size
!get the list with the binary file list
WRITE (*,*) 'Please input file name with the binary file names:'
READ (*,*) name_binary
WRITE (*,510) name_binary
510 format (' ', 'The name with the binary file names is ', A '.txt')
!Get the filename of the list of positions for the analyses
WRITE (*,*) 'Please input file name with locations:'
READ (*,*) name
WRITE (*,500) name
500 format (' ', 'The filename is: ', A '.txt')
OPEN (UNIT = 20, FILE = name_binary // ending, STATUS = 'OLD', ACTION ='READ', IOSTAT=status)
IF (status == 0) THEN
!open was ok. Read values to find out how many lines are in the file.
DO
READ (20, *, IOSTAT=status) location_binary !Get next value
IF (status /=0) EXIT !EXIT if not valid
number_positions_binary = number_positions_binary + 1 !Valid: increase count
END DO
END IF
OPEN (UNIT = 22, FILE = name // ending, STATUS = 'OLD', ACTION ='READ', IOSTAT=status)
IF (status == 0) THEN
!open was ok. Read values to find out how many lines are in the file.
DO
READ (22, *, IOSTAT=status) location !Get next value
IF (status /=0) EXIT !EXIT if not valid
number_positions = number_positions + 1 !Valid: increase count
END DO
END IF
IF (number_positions_binary == number_positions) THEN
WRITE (*,520) number_positions
520 format (' ', 'The file contains: ', I ' vertical locations in the cross section')
ALLOCATE ( Position_array_binary(number_positions), STAT=status) !allocate memory
ALLOCATE ( Position_array(number_positions), STAT=status)
! if the allocation was successful, rewind the file and read in the data!
allocate_ok: IF ( status == 0) THEN
REWIND ( UNIT=20) !Rewind file
READ (20,*) (Position_array_binary(i), i=1, number_positions)
CLOSE ( UNIT=20)! Close File
END IF allocate_ok
allocate_ok2:IF ( status == 0) THEN
REWIND ( UNIT=22) !Rewind file
READ (22,*) (Position_array(i), i=1, number_positions)
CLOSE ( UNIT=22)! Close File
END IF allocate_ok2
CLOSE ( UNIT=22)
ELSE
WRITE (*,*) 'The number of positions in the two input files is different - please restart the program!'
END IF
DO i = 1, number_positions !start of main loop in program!!!!
position = Position_array(i)
position_binary = Position_array_binary(i) !Get the filename and echo it back to the user
WRITE (*,10000) i, position
10000 format (' ', 'The position ' I ' is: ' , A)
! Open the position file, and check for errors on open.
OPEN (UNIT = 30, FILE = position_binary // '.dat', form='binary', STATUS = 'OLD', ACTION ='READ', IOSTAT=status)
IF (status == 0) THEN
! ALLOCATE MEMORY
ALLOCATE ( Data_array(number_columns, number_rows), STAT=status) !allocate memory
Data_array = 0
! if the allocation was successful, rewind the file and read in the data!
allocate_ok3: IF ( status == 0) THEN
READ (30) header
Do j = 1, number_rows
READ (30) x, y
Data_array (1,j) = (j-1)/real(frequency)
Data_array (2,j) = x*5./32768.
Data_array (3,j) = y*5./32768.
END DO
END IF allocate_ok3
END IF
! Close File
CLOSE ( UNIT=30)
!Calculate basic data using the full raw signal
! allocata arrays for analyses
ALLOCATE (threshold(Number_devices),STAT=status)
ALLOCATE (interfaces(Number_devices*2, max_no_bubbles), STAT =status)
!Calculate the Probability distribution function of the voltage signals and store to array PDF_V
ALLOCATE (PDF_V(number_columns, Int(PDF_segments)), STAT=status) !allocate memory for PDF_V
PDF_V = 0
CALL Probability_V (Data_array, number_columns, number_rows, PDF_V_segment_size, &
PDF_segments, PDF_V, threshold, threshold_C)
CALL Basic_properties (Data_array, number_columns, number_rows, threshold,&
Interfaces, basic_results, max_no_bubbles, frequency)
!Write PDF_V distribution data to file: PDF_V-results
OPEN (UNIT = 64, FILE = position // sample //'PDF_V' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (64,164) 'Bin-size', 'V-leading', 'V-trailing'
WRITE (64, 165) ((PDF_V (j,k), j=1,3), k=1, INT(PDF_segments))
164 FORMAT (A8, T13, A9, T25, A10)
165 FORMAT (F10.5, T13, F10.7, T25, F10.7)
DEALLOCATE (PDF_V, STAT = status)
OPEN (UNIT = 66, FILE = position //sample // 'interfaces' // ending , STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (66,166) 'W->A leading', 'A->W leading', 'W->A trailing', 'A->W trailing'
WRITE (66, 167) ((interfaces (j,k), j=1,((number_columns-1)*2)), k=1, 10000)
166 FORMAT (A12, T15, A12, T36, A13, T52, A13)
167 FORMAT (I, T15, I, T36, I, T52, I)
DEALLOCATE (interfaces, STAT =status)
DEALLOCATE (threshold,STAT=status)
!Write to file basic_summary
WRITE (52, 153) position, ((basic_results (j,k), j=1,(number_columns-1)*2), k=1,1)
153 FORMAT (A4, T9, F10.5, T20, F10.5, T31, F10.5, T44, F10.5, T55)
! Analyses of filtered signals for triple decomposition approach
! Filtering of the raw data for tripledecomposition
ALLOCATE (Filtered_array_low(number_columns, number_rows), STAT =status)
ALLOCATE (Filtered_array_low_out(number_columns, number_rows), STAT =status)
ALLOCATE (Filtered_array_mid(number_columns, number_rows), STAT =status)
ALLOCATE (Filtered_array_high(number_columns, number_rows), STAT =status)
Filtered_array_low = 0
Filtered_array_low_out = 0
Filtered_array_mid = 0
Filtered_array_high = 0
helper_time = 0
Do j = 1, number_rows
Filtered_array_low (1, j) = helper_time
Filtered_array_low_out (1, j) = helper_time
Filtered_array_mid (1, j) = helper_time
Filtered_array_high (1, j) = helper_time
helper_time = helper_time + 1.0/REAL(frequency)
END DO
Total = 0.0
Mean = 0.0
Do k =2, number_columns
Do j = 1, number_rows
Total = Total + Data_array (k,j)
END DO
Mean(k) = Total/REAL(number_rows)
Total = 0.0
END DO
! add zeroes so that data points=2^n before filterinG and subtract Mean values
ALLOCATE (FFT_array (number_columns, FFT_number), STAT=status)
FFT_array = 0
Do k = 2, number_columns
Do j = 1, number_rows
FFT_array (k,j) = Data_array (k,j) - Mean(k)
END DO
END DO
! Do k = 2, number_columns
Do j = number_rows + 1, FFT_number
FFT_array (2,j) = 0
FFT_array (3,j) = 0
END DO
! END DO
! === Numerical filtering and Spectral analysis ===
sample_step = 1/REAL(frequency)
Int_spectral_analys = FFT_number/2
total_FFT_duration = sample_step * REAL(FFT_number)
frequency_FFT = 1./total_FFT_duration
Cutoff_time_low_lower = INT((0.0 + frequency_FFT/2.)/frequency_FFT)+1
Cutoff_time_low_upper = Int((lower_frequency - frequency_FFT/2.)/frequency_FFT)+1
Cutoff_time_mid_lower = Int((lower_frequency + frequency_FFT/2.)/frequency_FFT)+1
Cutoff_time_mid_upper = Int((upper_frequency - frequency_FFT/2.)/frequency_FFT)+1
Cutoff_time_high_lower = Int((upper_frequency + frequency_FFT/2.)/frequency_FFT)+1
Cutoff_time_high_upper = Int((frequency/2 - frequency_FFT/2.)/frequency_FFT)+1
CALL Filter (number_rows, number_columns, FFT_number, Int_spectral_analys, FFT_array, Cutoff_time_low_lower, &
Cutoff_time_low_upper, Cutoff_time_mid_lower, Cutoff_time_mid_upper, Cutoff_time_high_lower, &
Cutoff_time_high_upper, Filtered_array_low, Filtered_array_mid, Filtered_array_high)
Do k = 2, number_columns
Do j = 1, number_rows
Filtered_array_low_out (k,j) = Filtered_array_low (k,j) + Mean(k)
END DO
END DO
DEALLOCATE (Filtered_array_low, STAT =status)
DEALLOCATE (FFT_array, STAT =status)
!Write low filtered data to file: filter-results
OPEN (UNIT = 6000, FILE = position // sample // 'filtered_low' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (6000, 1600) 'time', 'lead', 'trai'
WRITE (6000, 1610) ((Filtered_array_low_out (j,k), j=1,3), k=1, number_rows)
1600 FORMAT (A4, T10, A4, T22, A4)
1610 FORMAT (F10.6,T10, F10.5, T22, F10.7)
CLOSE (UNIT=6000)
!Write mid filtered data to file: filter-results
OPEN (UNIT = 6001, FILE = position // sample // 'filtered_mid' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (6001, 1601) 'time', 'lead', 'trai'
WRITE (6001, 1611) ((Filtered_array_mid (j,k), j=1,3), k=1, number_rows)
1601 FORMAT (A4, T10, A4, T22, A4)
1611 FORMAT (F10.6,T10, F10.5, T22, F10.7)
CLOSE (UNIT=6001)
!Write high filtered data to file: filter-results
OPEN (UNIT = 6002, FILE = position // sample // 'filtered_high' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (6002, 1602) 'time', 'lead', 'trai'
WRITE (6002, 1612) ((Filtered_array_high (j,k), j=1,3), k=1, number_rows)
1602 FORMAT (A4, T10, A4, T22, A4)
1612 FORMAT (F10.6,T10, F10.5, T22, F10.7)
CLOSE (UNIT=6002)
number_rows_cut = number_rows - (6 * 20000)
!Cut_off of data for correlation analyses
ALLOCATE (Data_array_cut(number_columns, number_rows_cut), STAT =status)
ALLOCATE (Filtered_array_low_out_cut(number_columns, number_rows_cut), STAT =status)
ALLOCATE (Filtered_array_mid_cut(number_columns, number_rows_cut), STAT =status)
ALLOCATE (Filtered_array_high_cut(number_columns, number_rows_cut), STAT =status)
Data_array_cut = 0
Filtered_array_low_out_cut = 0
Filtered_array_mid_cut = 0
Filtered_array_high_cut = 0
Do k = 1, number_columns
Do j = 1, number_rows_cut
Data_array_cut (k, j) = Data_array (k, j + (60000))
Filtered_array_low_out_cut (k, j) = Filtered_array_low_out (k, j + (60000))
Filtered_array_mid_cut (k, j) = Filtered_array_mid (k, j + (60000))
Filtered_array_high_cut (k, j) = Filtered_array_high (k, j + (60000))
End Do
END DO
DEALLOCATE (Data_array, STAT = status)
DEALLOCATE (Filtered_array_low_out, STAT =status)
DEALLOCATE (Filtered_array_mid, STAT =status)
DEALLOCATE (Filtered_array_high, STAT =status)
! perform correlation analyses for raw data part
!Allocate arrays for correlation analyses
ALLOCATE (Autocorrelation_raw(2, Correlation_steps), STAT =status)
ALLOCATE (Crosscorrelation_raw(2, Correlation_steps), STAT =status)
!use the data arry and do auto- and cross -correlation analyses
CALL Correlation_raw(Data_array_cut, number_columns, number_rows_cut, Correlation_steps, &
Autocorrelation_raw, Crosscorrelation_raw, frequency, segment_numbers)
!calculate the characteristic scales, Tu and Interfacial Velocity
CALL Correlation_scales_raw (Autocorrelation_raw, Crosscorrelation_raw, Correlation_steps, &
CorScale_results_raw, frequency, delta_x, velocity)
!Write autocorrelation data to file: Autocorrelation-results
OPEN (UNIT = 60, FILE = position // sample // 'autocor_raw' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (60, 160) 'Time', 'Rxx'
WRITE (60, 161) ((Autocorrelation_raw (j,k), j=1,2), k=1, Correlation_steps)
160 FORMAT (A4, T15, A3)
161 FORMAT (F10.5,T15, F10.7)
!Write crosscorrelation data to file: Crosscorrelation-results
OPEN (UNIT = 62, FILE = position //sample //'crosscor_raw' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (62, 162) 'Time', 'Rxy'
WRITE (62, 163) ((Crosscorrelation_raw (j,k), j=1,2), k=1, Correlation_steps)
162 FORMAT (A4, T18, A3)
163 FORMAT (F14.9, T16, F14.9)
CLOSE (UNIT=60)
CLOSE (UNIT=62)
DEALLOCATE (Autocorrelation_raw, STAT =status)
DEALLOCATE (Crosscorrelation_raw, STAT =status)
!Write data to file: Turbulence and velocity results
WRITE (50, 151) Position, (CorScale_results_raw )
151 FORMAT (A4, T11, F9.6, T21, F9.6, T31, F9.6, T43, F9.6, T52, F9.6, T62, F9.6, T72, &
F9.6, T83, F9.6, T94, F9.6, T106, F9.6, T115, F9.6, T131, F9.6, T141, F9.6, T151, F9.6, T161, F9.6)
DEALLOCATE (Data_array_cut, STAT = status)
!--------------------------------------------------------------
! perform correlation analyses for high fluctuating data part
!Allocate arrays for correlation analyses
ALLOCATE (Autocorrelation_high(2, Correlation_steps), STAT =status)
ALLOCATE (Crosscorrelation_high(2, Correlation_steps), STAT =status)
!use the data arry and do auto- and cross -correlation analyses
CALL Correlation_high(Filtered_array_high_cut, Filtered_array_mid_cut, number_columns, number_rows_cut, Correlation_steps, &
Autocorrelation_high, Crosscorrelation_high, frequency, segment_numbers, Auto_fac, Cross_fac)
velocity = 3
!calculate the characteristic scales, Tu and Interfacial Velocity
CALL Correlation_scales_high (Autocorrelation_high, Crosscorrelation_high, Correlation_steps, &
CorScale_results_high, frequency, delta_x, velocity, Auto_fac, Cross_fac)
!Write autocorrelation data to file: Autocorrelation-results
OPEN (UNIT = 90, FILE = position // sample // 'autocor_high' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (90, 190) 'Time', 'Rxx'
WRITE (90, 191) ((Autocorrelation_high (j,k), j=1,2), k=1, Correlation_steps)
190 FORMAT (A4, T15, A3)
191 FORMAT (F10.5,T15, F10.7)
!Write crosscorrelation data to file: Crosscorrelation-results
OPEN (UNIT = 92, FILE = position //sample //'crosscor_high' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (92, 192) 'Time', 'Rxy'
WRITE (92, 193) ((Crosscorrelation_high (j,k), j=1,2), k=1, Correlation_steps)
192 FORMAT (A4, T18, A3)
193 FORMAT (F14.9, T16, F14.9)
CLOSE (UNIT=90)
CLOSE (UNIT=92)
!Write data to file: Turbulence and velocity results
WRITE (94, 194) Position, (CorScale_results_high )
194 FORMAT (A4, T11, F9.6, T21, F9.6, T31, F9.6, T43, F9.6, T52, F9.6, T62, F9.6, T72, &
F9.6, T83, F9.6, T94, F9.6, T106, F9.6, T115, F9.6, T131, F9.6, T141, F9.6, &
T151, F9.6, T161, F9.6, T172, F9.6, T181, F9.6, T191, F9.6)
Auto_fac = 0
Cross_fac = 0
!--------------------------------------------------------------
! perform correlation analyses for slow fluctuating data part
!Allocate arrays for correlation analyses
ALLOCATE (Autocorrelation_mid(2, Correlation_steps), STAT =status)
ALLOCATE (Crosscorrelation_mid(2, Correlation_steps), STAT =status)
!use the data arry and do auto- and cross -correlation analyses
CALL Correlation_mid(Filtered_array_mid_cut, Filtered_array_high_cut, number_columns, number_rows_cut, Correlation_steps, &
Autocorrelation_mid, Crosscorrelation_mid, frequency, segment_numbers, Auto_fac, Cross_fac)
velocity = 3
!calculate the characteristic scales, Tu and Interfacial Velocity
CALL Correlation_scales_mid (Autocorrelation_mid, Crosscorrelation_mid, Correlation_steps, &
CorScale_results_mid, frequency, delta_x, velocity, Auto_fac, Cross_fac)
!Write autocorrelation data to file: Autocorrelation-results
OPEN (UNIT = 100, FILE = position // sample // 'autocor_mid' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (100, 290) 'Time', 'Rxx'
WRITE (100, 291) ((Autocorrelation_mid (j,k), j=1,2), k=1, Correlation_steps)
290 FORMAT (A4, T15, A3)
291 FORMAT (F10.5,T15, F10.7)
!Write crosscorrelation data to file: Crosscorrelation-results
OPEN (UNIT = 102, FILE = position //sample //'crosscor_mid' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (102, 292) 'Time', 'Rxy'
WRITE (102, 293) ((Crosscorrelation_mid (j,k), j=1,2), k=1, Correlation_steps)
292 FORMAT (A4, T18, A3)
293 FORMAT (F14.9, T16, F14.9)
CLOSE (UNIT=100)
CLOSE (UNIT=102)
!Write data to file: Turbulence and velocity results
WRITE (95, 294) Position, (CorScale_results_mid )
294 FORMAT (A4, T11, F9.6, T21, F9.6, T31, F9.6, T43, F9.6, T52, F9.6, T62, F9.6, T72, &
F9.6, T83, F9.6, T94, F9.6, T106, F9.6, T115, F9.6, T131, F9.6, T141, F9.6, &
T151, F9.6, T161, F9.6, T172, F9.6, T181, F9.6, T191, F9.6)
!--------------------------------------------------------------
!--------------------------------------------------------------
! add slow and fast fluctuating correlation function and perform analyses
!Allocate arrays
ALLOCATE (Autocorrelation_low(2, Correlation_steps), STAT =status)
ALLOCATE (Crosscorrelation_low(2, Correlation_steps), STAT =status)
DO j = 1, Correlation_steps
Autocorrelation_low (1, j) = Autocorrelation_high (1, j)
Autocorrelation_low (2, j) = Autocorrelation_high (2, j) + Autocorrelation_mid (2, j)
Crosscorrelation_low (1, j) = Crosscorrelation_high (1, j)
Crosscorrelation_low (2, j) = Crosscorrelation_high (2, j) + Crosscorrelation_mid (2, j)
END DO
velocity = 3
!calculate the characteristic scales, Tu and Interfacial Velocity
CALL Correlation_scales_low (Autocorrelation_low, Crosscorrelation_low, Correlation_steps, &
CorScale_results_low, frequency, delta_x, velocity)
!Write autocorrelation data to file: Autocorrelation-results
OPEN (UNIT = 103, FILE = position // sample // 'autocor_sum_slow_fast_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (103, 390) 'Time', 'Rxx'
WRITE (103, 391) ((Autocorrelation_low (j,k), j=1,2), k=1, Correlation_steps)
390 FORMAT (A4, T15, A3)
391 FORMAT (F10.5,T15, F10.7)
!Write crosscorrelation data to file: Crosscorrelation-results
OPEN (UNIT = 104, FILE = position //sample //'crosscor_sum_slow_fast_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (104, 396) 'Time', 'Rxy'
WRITE (104, 397) ((Crosscorrelation_low (j,k), j=1,2), k=1, Correlation_steps)
396 FORMAT (A4, T18, A3)
397 FORMAT (F14.9, T16, F14.9)
CLOSE (UNIT=104)
CLOSE (UNIT=103)
!Write data to file: Turbulence and velocity results
WRITE (96, 295) Position, (CorScale_results_low )
295 FORMAT (A4, T11, F9.6, T21, F9.6, T31, F9.6, T43, F9.6, T52, F9.6, T62, F9.6, T72, &
F9.6, T83, F9.6, T94, F9.6, T106, F9.6, T115, F9.6, T131, F9.6, T141, F9.6, T151, F9.6, T161, F9.6, T172, F9.6)
DEALLOCATE (Autocorrelation_low, STAT =status)
DEALLOCATE (Crosscorrelation_low, STAT =status)
DEALLOCATE (Autocorrelation_mid, STAT =status)
DEALLOCATE (Crosscorrelation_mid, STAT =status)
DEALLOCATE (Autocorrelation_high, STAT =status)
DEALLOCATE (Crosscorrelation_high, STAT =status)
!-----------------------------------------------------------------
! calculate auto-and cross correlation function for crossproduct of fast and slow fluctuating components Rx'y'' and Rx''y'
ALLOCATE (Autocorrelation_fast_low(2, Correlation_steps_low), STAT =status)
ALLOCATE (Crosscorrelation_fast_low(2, Correlation_steps_low), STAT =status)
ALLOCATE (Autocorrelation_low_fast(2, Correlation_steps_low), STAT =status)
ALLOCATE (Crosscorrelation_low_fast(2, Correlation_steps_low), STAT =status)
!use the data arry and do auto- and cross -correlation analyses
CALL Correlation_low(Filtered_array_mid_cut, Filtered_array_high_cut, number_columns, number_rows_cut, Correlation_steps_low, &
Autocorrelation_fast_low, Crosscorrelation_fast_low, Autocorrelation_low_fast, Crosscorrelation_low_fast, &
frequency, segment_numbers, Factors_crossproduct)
!Write autocorrelation data to file: Autocorrelation-results
OPEN (UNIT = 113, FILE = position // sample // 'autocor_crossproduct_fast_slow_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (113, 310) 'Time', 'Rxx'
WRITE (113, 311) ((Autocorrelation_fast_low (j,k), j=1,2), k=1, Correlation_steps_low)
310 FORMAT (A4, T15, A3)
311 FORMAT (F10.5,T15, F10.7)
OPEN (UNIT = 123, FILE = position // sample // 'autocor_crossproduct_slow_fast_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (123, 320) 'Time', 'Rxx'
WRITE (123, 321) ((Autocorrelation_low_fast (j,k), j=1,2), k=1, Correlation_steps_low)
320 FORMAT (A4, T15, A3)
321 FORMAT (F10.5,T15, F10.7)
!Write crosscorrelation data to file: Crosscorrelation-results
OPEN (UNIT = 114, FILE = position //sample //'crosscor_crossproduct_fast_slow_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (114, 316) 'Time', 'Rxy'
WRITE (114, 317) ((Crosscorrelation_fast_low (j,k), j=1,2), k=1, Correlation_steps_low)
316 FORMAT (A4, T18, A3)
317 FORMAT (F14.9, T16, F14.9)
OPEN (UNIT = 124, FILE = position //sample //'crosscor_sum_crossproduct_slow_fast_fluctuations' // ending, STATUS = 'REPLACE', &
ACTION ='WRITE', IOSTAT=status)
WRITE (124, 326) 'Time', 'Rxy'
WRITE (124, 327) ((Crosscorrelation_low_fast (j,k), j=1,2), k=1, Correlation_steps_low)
326 FORMAT (A4, T18, A3)
327 FORMAT (F14.9, T16, F14.9)
WRITE (520, 253) Position, (Factors_crossproduct)
253 FORMAT (A4, T10, F9.6, T22, F9.6, T38, F9.6, T53)
CLOSE (UNIT=113)
CLOSE (UNIT=114)
CLOSE (UNIT=123)
CLOSE (UNIT=124)
DEALLOCATE (Autocorrelation_fast_low, STAT =status)
DEALLOCATE (Crosscorrelation_fast_low, STAT =status)
DEALLOCATE (Autocorrelation_low_fast, STAT =status)
DEALLOCATE (Crosscorrelation_low_fast, STAT =status)
DEALLOCATE (Filtered_array_low_out_cut, STAT =status)
DEALLOCATE (Filtered_array_mid_cut, STAT =status)
DEALLOCATE (Filtered_array_high_cut, STAT =status)
!--------------------------------------------------------------
WRITE (*,6000) position
6000 format (' ', 'Finished calculation of position: ' A)
END DO ! END of main loop in program
DEALLOCATE (basic_results, STAT =status)
CLOSE (UNIT=50)
CLOSE (UNIT=52)
CLOSE (UNIT=54)
CLOSE (UNIT=56)
CLOSE (UNIT=64)
CLOSE (UNIT=66)
CLOSE (UNIT=94)
CLOSE (UNIT=95)
CLOSE (UNIT=96)
CLOSE (UNIT=6000)
CLOSE (UNIT=6001)
CLOSE (UNIT=6002)
CLOSE (UNIT=520)
pause
end program dataanalysis
!______________________________________________________________________________________________________
SUBROUTINE Correlation_raw (Data_array_cut, number_columns, number_rows_cut, Correlation_steps, &
Autocorrelation_raw, Crosscorrelation_raw, frequency, segment_numbers)
IMPLICIT NONE
INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=15) !Precision of the Real variables
INTEGER, INTENT (IN) :: number_columns
INTEGER, INTENT (IN) :: number_rows_cut
INTEGER, INTENT (IN) :: Correlation_steps
INTEGER, INTENT (IN) :: frequency
INTEGER, INTENT (IN) :: segment_numbers
REAL(kind=DBL), INTENT (IN) :: Data_array_cut (number_columns, number_rows_cut)
REAL(kind=DBL), INTENT (OUT) :: Autocorrelation_raw (2, Correlation_steps)
REAL(kind=DBL), INTENT (OUT) :: Crosscorrelation_raw(2, Correlation_steps)
INTEGER :: segment_rows !number of rows in each segment
INTEGER :: helper !helper for faster correlations
INTEGER :: boundary !helper for faster correlation
INTEGER :: i =0, j = 0, k=0 !integer for loop
REAL(kind=DBL), ALLOCATABLE, DIMENSION (:,:) :: Autocor_helper
REAL(kind=DBL), ALLOCATABLE, DIMENSION (:,:) :: Crosscor_helper
REAL(kind=DBL) :: sumX, sumY, sumX2, sumY2, sumXY !Variables for correl
INTEGER :: offset !integer for offsetting
INTEGER :: status
REAL(kind=DBL) :: average_value !Helper to calculate the average values
Autocorrelation_raw = 0
Crosscorrelation_raw = 0
segment_rows =0
helper = 0
boundary = 0
sumX = 0
sumY = 0
sumX2 = 0
sumY2 = 0
sumXY = 0
offset = 0
status = 0
average_value =0
segment_rows = number_rows_cut/segment_numbers
boundary = segment_rows - Correlation_steps
!Performing Auto-correlation
ALLOCATE (Autocor_helper(segment_numbers, Correlation_steps))
Autocor_helper = 0
outer : DO i=1, segment_numbers
helper = segment_rows * (i-1)
middle : DO j=1, Correlation_steps
inner : DO k = 1, boundary
sumX = sumX + Data_array_cut(2 , (k + helper))
sumX2 = sumX2 + Data_array_cut(2 , (k+ helper))* &
Data_array_cut(2 , (k+ helper))
sumY = sumY + Data_array_cut(2, (k+ helper+offset))
sumY2 = sumY2 + Data_array_cut(2, (k+ helper+offset)) &
*Data_array_cut(2, (k+ helper+offset))
sumXY = sumXY + Data_array_cut(2,(k+ helper)) * &
Data_array_cut(2,(k+ helper+offset))
END DO inner
Autocor_helper(i,j) = (sumXY - sumX * sumY/boundary) /(SQRT(sumX2-sumX*sumX/ &
boundary) * SQRT(sumY2-sumY*sumY/boundary))
! Adjust variables
offset=offset +1
sumX = 0
sumX2 = 0
sumY = 0
sumY2 = 0
sumXY = 0
END DO middle
offset = 0 !zero offset helper
END DO outer
helper = 0
!average the autocorrelation-segments and add time
DO i = 1, Correlation_steps
Autocorrelation_raw (1, i) = real((i-1))/frequency
DO j = 1, segment_numbers
average_value = average_value + Autocor_helper (j , i)
END DO
Autocorrelation_raw (2, i) = average_value/segment_numbers
average_value = 0
END DO
WRITE (*,*) 'Finished calculation of autocorrelation_raw! '
! OPEN (UNIT = 2002, FILE = 'auto.txt', STATUS = 'REPLACE', ACTION ='WRITE', IOSTAT=status)
! WRITE (2002, 2003) ((Autocor_helper (i,j), i=1,segment_numbers), j=1, Correlation_steps)
! 2003 FORMAT (15F10.5)
DEALLOCATE(Autocor_helper)
!Performing Crosscorrelation
sumX = 0
sumX2 = 0
sumY = 0
sumY2 = 0
sumXY = 0
offset = 0
helper = 0
ALLOCATE (Crosscor_helper(segment_numbers, Correlation_steps))
Crosscor_helper = 0
outer_cross : DO i=1, segment_numbers
helper = segment_rows * (i-1)
middle_cross : DO j=1, Correlation_steps
inner_cross : DO k = 1, boundary
sumX = sumX + Data_array_cut(2 , (k + 199 + helper))
sumX2 = sumX2 + Data_array_cut(2 , (k +199 + helper))* &
Data_array_cut(2 , (k +199 + helper))
sumY = sumY + Data_array_cut(3, (k+ helper+offset))
sumY2 = sumY2 + Data_array_cut(3, (k+ helper+offset))* &
Data_array_cut(3, (k+ helper+offset))
sumXY = sumXY + Data_array_cut(2, (k + 199 + helper)) * &
Data_array_cut(3, (k+ helper+offset))
END DO inner_cross
Crosscor_helper(i,j) = (boundary*sumXY - sumX * sumY)/(SQRT(boundary*sumX2- &
sumX*sumX)* SQRT(boundary*sumY2-sumY*sumY))
! Adjust variables
offset=offset +1
sumX = 0
sumX2 = 0
sumY = 0
sumY2 = 0
sumXY = 0
END DO middle_cross
offset = 0 !zero offset helper
END DO outer_cross
!average the autocorrelation-segments and add time
DO i = 1, Correlation_steps
Crosscorrelation_raw (1, i) = -REAL(199)/frequency + real((i-1))/frequency
DO j = 1, segment_numbers
average_value = average_value + Crosscor_helper (j , i)
END DO
Crosscorrelation_raw (2, i) = average_value/segment_numbers
average_value = 0
END DO
WRITE (*,*) 'Finished calculation of crosscorrelation_raw! '
! OPEN (UNIT = 2000, FILE = 'cross.txt', STATUS = 'REPLACE', ACTION ='WRITE', IOSTAT=status)
! WRITE (2000, 2001) ((Crosscor_helper (i,j), i=1,segment_numbers), j=1, Correlation_steps)
! 2001 FORMAT (15F10.5)
DEALLOCATE(Crosscor_helper)
END SUBROUTINE Correlation_raw