This repository has been archived by the owner on Mar 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindata.f90
1170 lines (1047 loc) · 37.5 KB
/
bindata.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
program main
IMPLICIT NONE
!Program parameters
integer, parameter :: iFileIn=100,iFileOut=101
integer, parameter :: iKindDP=selected_real_kind(15,300)
!Physical parameters
real(iKindDP), parameter :: rcPi = DACOS(-1.D0), rSecsToDays=86400.0, rcC=29979245800.0 !cm/s
real(iKindDP), parameter :: rcG = 6.67408e-8 !cgs
real(iKindDP), parameter :: rcMSol = 1.98855e33 !g
!Internals
logical :: bFound, bMessy=.FALSE.
logical :: bAllScat=.FALSE., bNoLog=.FALSE., bLineMalformed=.FALSE.
integer :: iDimX=100, iDimY=100, iDimR=100
integer :: i,j,k,iErr=0, iEOF=0, iDummy, iBinX, iBinY, iBinR, iPhot=0,iPhotR=0
integer :: iArg=1, iArg_iter
integer :: iObserver, iObserverMin=0, iObserverMax=0, iObservers=1, iObs
integer, allocatable :: aiMap(:,:,:),aiMapX(:,:),aiMapY(:,:),aiMapR(:)
real(iKindDP), allocatable :: arMap(:,:,:),arMapX(:,:),arMapY(:,:),arBinX(:),arBinY(:), arNormalise(:)
real(iKindDP) :: rDummy, rLambda, rWeight, rDelay, rPosX,rPosY,rPosZ,rErr
real(iKindDP) :: rMinX=-1., rMaxX=-1., rMinY=-1., rMaxY=-1., rRngX=-1., rRngY=-1., rMinR=-1.,rMaxR=-1., rRngR=-1.
real(iKindDP) :: rMinP=1e300_iKindDP, rMaxP=0.,rMinI=1e300_iKindDP,rMaxI=0.,rRad=-1, rTemp=0.0
character(len=512) :: cFileIn="",cFileOut="", cDummy, cArg, cTicks='"%g"'
character(len=512) :: cBuffer
!Variables for reading in dump file
integer :: iNScat, iLine=0
!Variables for scatter selection
integer :: iNRScat, iNRScatMin=1, iNRScatMax=999
integer :: iNCScat, iNCScatMin=0, iNCScatMax=999
!Variables for gnuplot
logical :: bChangeCB=.FALSE., bNoKey=.FALSE., bNoTicks=.FALSE.
real(iKindDP) :: rMinCB, rMaxCB
character(len=512) :: cKey = ""
!Variables for output
logical :: bWithUnits=.FALSE.
!Reweighting variables
logical :: bReweight=.FALSE., bReweightBinLog=.FALSE., bReweightBinGeom=.FALSE., bLookupY=.TRUE.
integer :: iReweightGeom
real(iKindDP) :: rReweightPow, rReweightBase
real(iKindDP), allocatable :: arMapR(:),arBinR(:),arPosR(:),arReweightMult(:)
!Line mode variables
logical :: bLineMode=.FALSE., bLineFound=.FALSE., bLineBHEstimate=.FALSE., bLineBHUseRMS=.FALSE.
integer :: iLines=0, iNRes
integer, allocatable :: aiLine(:)
real(iKindDP) :: rLineLambda, rLineLambdaU2, rLineLambdaU1, rLineLambdaL1, rLineLambdaL2, rLineVelUpper, rLineVelLower, rLineVelMax, rLineVelMin
logical :: bLineVel=.FALSE.
!Error tracking variables
integer :: iErrWeight=0, iErrMalf=0, iErrLog=0
!Pointwise mode variables
logical :: bPointwise=.FALSE.,bPointwiseOnly=.FALSE.
real(iKindDP) :: rPathPeak, rPathFWHMlower, rPathFWHMupper, rPeakFlux, rPathCent, rFluxCent, rPathCentU, rPathCentL,rFluxTemp
integer :: iPathPeak
real(iKindDP) :: rPosXL, rPosXU
!Variables for specifying origin
logical :: bOriginMode=.FALSE., bOriginFound=.FALSE.
integer :: iOrigins=0, iOrigin
integer, allocatable :: aiOrigin(:)
!Variables for outputting CDF
logical :: bCDF=.FALSE.
!Centroid delay variables
real(iKindDP) :: rDelayCent, rDelayL, rDelayU
real(iKindDP) :: rRespMax
if(command_argument_count().EQ.0)then
print *,"DESCRIPTION:"
print *,"The bindata utility is intended to bin up delay dump outputs produced by PYTHON."
print *,""
print *,"ARGUMENTS:"
print *," -i FILE"
print *,"Input file, no suffix. "//&
"If no -i argument is provided, the first un-flagged argument is taken as the input."
print *,""
print *," -o FILE"
print *,"Output file base, no suffix. "//&
"If no -o argument is provided, the input file is used as a base."
print *,""
print *," -d N M"
print *,"Bin on a grid with N by M dimensions. Default 100 by 100."
print *,""
print *," -r VAL VAL"
print *,"Minimum & maximum wind radius in file. Default is to find from input file."
print *,""
print *," -s VAL VAL"
print *,"Minimum & maximum number of scatters. Default is 1-999."
print *,""
print *," -sc VAL VAL"
print *,"Minimum & maximum number of continuum scatters. Default is 0-999."
print *,""
print *," -p VAL VAL"
print *,"Minimum & maximum path distances to plot. Default is .9-.3.25x wind radius."
print *,""
print *," -v VAL VAL"
print *,"Wavelength range to bin. Default is to use spectrum_wavemin-max from input file."
print *,""
print *," -c VAL VAL"
print *,"Intensity range for colour plot. Default is to use gnuplot's automatic mode."
print *,""
print *," -l VAL [VAL] [VAL] [...]"
print *,"Macro-atom lines to plot. May be arbitrarily long."
print *,""
print *," -or VAL [VAL] [VAL] [...]"
print *,"Origins to plot. May be arbitrarily long. Disk = 2, Wind = 3, AGN = 4."
print *,""
print *," -rwp VAL"
print *,"Reweight mode: take data and reweight to r^VAL power law surface brightness."
print *,""
print *," -rwb VAL"
print *,"Reweight mode: reweight using VAL bins (default 100)."
print *,""
print *," -obs VAL"
print *,"Select points from observer VAL (default 0)."
print *,""
print *," -lw VAL"
print *,"When in line mode, if investigating single line for BH mass estimate, specify its wavelength."
print *,""
print *," -rms"
print *,"When making virial mass estimate, use line RMS error instead of FWHM."
print *,""
print *," -bl"
print *,"Reweight mode: Bin logarithmically, default is linear."
print *,""
print *," -bg"
print *,"Reweight mode: Bin geometrically, default is linear."
print *,""
print *," -m"
print *,"Messy, do not delete intermediate files."
print *,""
print *," -nk"
print *,"No key, remove colour key from plots."
print *,""
print *," -nl"
print *,"No log, plot linear colour scale."
print *,""
print *," -nt"
print *,"No ticks, remove tick numbers from plots."
print *,""
print *," -x"
print *,"Pointwise mode."
print *,""
print *," -xo"
print *,"Pointwise only mode."
print *,""
print *," -vel"
print *,"Plot using velocity, not frequency. Requires -lw."
STOP
endif
do while(iArg.LE.command_argument_count())
call get_command_argument(iArg, cArg)
if(cArg.EQ."-d".OR.cArg.EQ."-D")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)iDimX
if(iErr.NE.0.OR.iDimX.LT.1)then
print *,"ERROR: X dimension argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)iDimY
if(iErr.NE.0.OR.iDimY.LT.1)then
print *,"ERROR: Y dimension argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+3
else if(cArg.EQ."-r".OR.cArg.EQ."-R")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rMinR
if(iErr.NE.0 .OR.rMinR.LT.0)then
print *,"ERROR: Minimum radius argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)rMaxR
if(iErr.NE.0 .OR.rMaxR.LT.rMinR)then
print *,"ERROR: Maximum radius argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+3
rMinY=rMaxR*0.90
rMaxY=rMaxR*3.25
else if(cArg.EQ."-v".OR.cArg.EQ."-V")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rMinX
if(iErr.NE.0)then
print *,"ERROR: Minimum wavelength argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)rMaxX
if(iErr.NE.0 .OR.rMaxX.LT.rMinX)then
print *,"ERROR: Maximum wavelength argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+3
else if(cArg.EQ."-p".OR.cArg.EQ."-P")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rMinY
if(iErr.NE.0)then
print *,"ERROR: Minimum path argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)rMaxY
if(iErr.NE.0 .OR. rMaxY.LT.rMinY)then
print *,"ERROR: Maximum path argument '"//trim(cArg)//"' invalid!"
STOP
endif
bLookupY=.FALSE.
iArg=iArg+3
else if(cArg.EQ."-c".OR.cArg.EQ."-C")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rMinCB
if(iErr.NE.0)then
print *,"ERROR: Minimum intensity argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)rMaxCB
if(iErr.NE.0 .OR. rMaxY.LT.rMinY)then
print *,"ERROR: Maximum intensity argument '"//trim(cArg)//"' invalid!"
STOP
endif
bChangeCB=.TRUE.
iArg=iArg+3
else if(cArg.EQ."-s".OR.cArg.EQ."-S")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)iNRScatMin
if(iErr.NE.0 .OR.iNRScatMin.LT.0)then
print *,"ERROR: Minimum resonant scatters argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)iNRScatMax
if(iErr.NE.0 .OR.iNRScatMax.LT.iNRScatMin)then
print *,"ERROR: Maximum resonant scatters argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+3
else if(cArg.EQ."-sc".OR.cArg.EQ."-SC")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)iNCScatMin
if(iErr.NE.0 .OR.iNCScatMin.LT.0)then
print *,"ERROR: Minimum continuum scatters argument '"//trim(cArg)//"' invalid!"
STOP
endif
call get_command_argument(iArg+2, cArg)
read(cArg,*,iostat=iErr)iNCScatMax
if(iErr.NE.0 .OR.iNCScatMax.LT.iNCScatMin)then
print *,"ERROR: Maximum continuum scatters argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+3
else if(cArg.EQ."-l".OR.cArg.EQ."-L")then
iArg_iter=iArg+1
iLines=0
bLineMode=.TRUE.
do while(iArg_iter.LE.command_argument_count())
call get_command_argument(iArg_iter, cArg)
read(cArg,*,iostat=iErr)iLine
if(iErr.EQ.0 .AND.iLine.GE.0) then
iLines = iLines +1
else
EXIT
endif
iArg_iter = iArg_iter +1
end do
if(iLines.EQ.0)then
print *,"ERROR: No valid lines listed!"
STOP
endif
allocate(aiLine(iLines))
write(*,'(A)',advance='no')'Line mode- tracking line(s):'
do iArg_iter=1,iLines
call get_command_argument(iArg+iArg_iter, cArg)
read(cArg,*,iostat=iErr)aiLine(iArg_iter)
write(*,'(X,I0)',advance='no')aiLine(iArg_iter)
end do
write(*,*)''
iArg=iArg+iLines+1
else if(cArg.EQ."-or".OR.cArg.EQ."-OR")then
iArg_iter=iArg+1
iOrigins=0
bOriginMode=.TRUE.
do while(iArg_iter.LE.command_argument_count())
call get_command_argument(iArg_iter, cArg)
read(cArg,*,iostat=iErr)iOrigin
if(iErr.EQ.0 .AND.iOrigin.GE.-1) then
iOrigins = iOrigins +1
else
EXIT
endif
iArg_iter = iArg_iter +1
end do
if(iOrigins.EQ.0)then
print *,"ERROR: No valid origins listed!"
STOP
endif
allocate(aiOrigin(iOrigins))
write(*,'(A)',advance='no')'Origin mode- tracking origin(s):'
do iArg_iter=1,iOrigins
call get_command_argument(iArg+iArg_iter, cArg)
read(cArg,*,iostat=iErr)aiOrigin(iArg_iter)
write(*,'(X,I0)',advance='no')aiOrigin(iArg_iter)
end do
write(*,*)''
iArg=iArg+iOrigins+1
else if(cArg.EQ."-rwp".OR.cArg.EQ."-RWP")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rReweightPow
if(iErr.NE.0 )then
print *,"ERROR: Reweighting power argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+2
bReweight=.TRUE.
else if(cArg.EQ."-rwb".OR.cArg.EQ."-RWB")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)iDimR
if(iErr.NE.0 .OR.iDimR.LT.0)then
print *,"ERROR: Reweighting bins argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+2
else if(cArg.EQ."-obs".OR.cArg.EQ."-OBS")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)iObserverMin
if(iErr.NE.0 .OR.iObserverMin.LT.0)then
print *,"ERROR: Observer argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+2
call get_command_argument(iArg, cArg)
read(cArg,*,iostat=iErr)iObserverMax
if(iErr.NE.0)then
!If there is no valid upper bound
iObserverMax = iObserverMin
else if(iObserverMax.LT.iObserverMin)then
print *,"ERROR: Observer range must be low to high!"
STOP
else
iArg=iArg+1
endif
else if(cArg.EQ."-lw".OR.cArg.EQ."-LW")then
call get_command_argument(iArg+1, cArg)
read(cArg,*,iostat=iErr)rLineLambda
if(iErr.NE.0 )then
print *,"ERROR: Line wavelength argument '"//trim(cArg)//"' invalid!"
STOP
endif
iArg=iArg+2
bLineBHEstimate=.TRUE.
else if(cArg.EQ."-bg".OR.cArg.EQ."-BG")then
iArg=iArg+1
bReweightBinGeom=.TRUE.
else if(cArg.EQ."-bl".OR.cArg.EQ."-BL")then
iArg=iArg+1
bReweightBinLog=.TRUE.
else if(cArg.EQ."-m".OR.cArg.EQ."-M")then
bMessy=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-nk".OR.cArg.EQ."-NK")then
bNoKey=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-nl".OR.cArg.EQ."-NL")then
bNoLog=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-nt".OR.cArg.EQ."-NT")then
bNoTicks=.TRUE.
cTicks='" "'
iArg=iArg+1
else if(cArg.EQ."-x".OR.cArg.EQ."-X")then
bPointwise=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-xo".OR.cArg.EQ."-XO")then
bPointwise=.TRUE.
bPointwiseOnly=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-vel".OR.cArg.EQ."-VEL")then
bLineVel=.TRUE.
iArg=iArg+1
else if(cArg.EQ."-i".OR.cArg.EQ."-I")then
call get_command_argument(iArg+1, cFileIn)
iArg=iArg+2
else if(cArg.EQ."-o".OR.cArg.EQ."-O")then
call get_command_argument(iArg+1, cFileOut)
iArg=iArg+2
else
call get_command_argument(iArg, cFileIn)
iArg=iArg+1
endif
end do
if(cFileOut.EQ."")cFileOut=cFileIn
inquire(file=trim(cFileIn)//".delay_dump", exist=bFound)
if(.NOT.bFound)then
print *,"ERROR: Input file '"//trim(cFileIn)//".delay_dump' does not exist!"
STOP
endif
if(bLineBHEstimate.AND..NOT.bLineMode)then
print *,'Trying to estimate BH mass from a line, but no line is specified!'
STOP
endif
if(bLineBHEstimate.AND.iLines.GT.1)then
print *,'Trying to estimate BH mass from a line, but too many lines specified!'
STOP
endif
if(bLineVel.AND..NOT.bLineBHEstimate)then
print *,'Trying to plot line velocity without knowing line wavelength!'
STOP
endif
if(bLookupY .AND. rMinR.LT.0 .AND. bReweight)then
rRad = rfGetKeyword(trim(cFileIn)//".pf","rstar") !Units = cm
rMinR = rfGetKeyword(trim(cFileIn)//".pf","wind_keplerian.diskmin")*rRad !Units = rstar
rMaxR = rfGetKeyword(trim(cFileIn)//".pf","wind_keplerian.diskmax")*rRad !Units = rstar
endif
if(rMinX.LT.0)then
! rMinX = rfGetKeyword(trim(cFileIn)//".pf","spectrum_wavemin")
! rMaxX = rfGetKeyword(trim(cFileIn)//".pf","spectrum_wavemax")
! print '(X,A,ES8.2,A,ES8.2,A,I0,A)','Binning wavelengths from ',rMinX,' to ',rMaxX,' in ',iDimX,' steps'
endif
if(bLookupY)then
rRad = rfGetKeyword(trim(cFileIn)//".pf","wind.radmax")
rMinY= rRad*0.50/(rSecsToDays*rcC) !Find delay in days from travel time in light-seconds, then seconds->days
rMaxY= rRad*4.50/(rSecsToDays*rcC)
print '(X,A,ES8.2,A,ES8.2,A,I0,A)','Binning paths from ',rMinY,' to ',rMaxY,'cm in ',iDimY,' steps'
endif
rRngX=rMaxX-rMinX
rRngY=rMaxY-rMinY
rRngR=rMaxR-rMinR
if(bPointwise)then
print '(A)','Plotting pointwise mode'
endif
iObservers = 1 +(iObserverMax - iObserverMin)
if(iObservers > 1)then
print '(A,I0,A,I0)','Plotting observers ',iObserverMin,' to ',iObserverMax
else
print '(A,I0)','Plotting observer ',iObserverMin
endif
! ============================================================================
! ALLOCATION AND ZEROING SECTION
! ----------------------------------------------------------------------------
allocate(aiMapX(iDimX,iObserverMin:iObserverMax), aiMapY(iDimY,iObserverMin:iObserverMax))
allocate(aiMapR(iDimR), aiMap(iDimX,iDimY,iObserverMin:iObserverMax))
allocate(arMapX(iDimX,iObserverMin:iObserverMax), arMapY(iDimY,iObserverMin:iObserverMax))
allocate(arMapR(iDimR), arMap(iDimX,iDimY,iObserverMin:iObserverMax))
allocate(arBinX(iDimX+1), arBinY(iDimY+1), arNormalise(iObserverMin:iObserverMax))
do i=0,iDimX
arBinX(i+1)=rMinX+i*(rMaxX-rMinX)/real(iDimX)
end do
do i=0,iDimY
arBinY(i+1)=rMinY+i*(rMaxY-rMinY)/real(iDimY)
end do
aiMap=0
aiMapX=0
aiMapY=0
arMap=0.0
arMapX=0.0
arMapY=0.0
arNormalise=0.0
! ============================================================================
! REWEIGHTING SECTION
! ----------------------------------------------------------------------------
if(bReweight)then
! Allocate and zero arrays.
allocate(arBinR(iDimR+1), arPosR(iDimR), arReweightMult(iDimR))
if(bReweightBinLog)then
rReweightBase = (log(rMaxR) - log(rMinR)) / iDimR
arBinR(1) = rMinR
do i=1,iDimR
arBinR(i+1)= exp(log(rMinR) + rReweightBase*i)
end do
elseif(bReweightBinGeom)then
iReweightGeom=0
do i=1,iDimR
iReweightGeom = iReweightGeom+i
end do
rReweightBase = (rMaxR-rMinR) / iReweightGeom
arBinR(1) = rMinR
do i=1,iDimR
arBinR(i+1) = arBinR(i) + rReweightBase*i
end do
else
do i=0,iDimR
arBinR(i+1)=rMinR+i*(rMaxR-rMinR)/real(iDimR)
end do
endif
aiMapR=0
arMapR=0.0
arReweightMult=1.0
print '(X,A,ES9.3,A,ES9.3,A,I0,A,ES9.2,A)',&
'Reweighting range from ',rMinR,' to ',rMaxR,' in ',iDimR,' bins to r^',rReweightPow,'.'
iErr=0
iEOF=0
open(iFileIn,file=trim(cFileIn)//".delay_dump",status="OLD",action="READ")
read(iFileIn,*) cDummy
do while(iErr.EQ.0.AND.iEOF.EQ.0)
read(iFileIn,'(A512)',iostat=iEOF) cBuffer
if(cBuffer(1:1).NE."#")then
read(cBuffer,*,iostat=iErr) rDummy, rLambda, rWeight, rPosX, rPosY, rPosZ, &
iNScat, iNRScat, rDelay, iObserver, iOrigin, iNRes
if(iErr.GT.0)then
iErr=0
iEOF=0
elseif(iNScat.EQ.1) then
iBinR = ifLookupIndex(arBinR, sqrt(rPosX**2+rPosY**2) )
if(iBinR.GT.0)then
aiMapR(iBinR) = aiMapR(iBinR) + 1
arMapR(iBinR) = arMapR(iBinR) + rWeight
endif
endif
endif
end do
close(iFileIn)
bReweight=.FALSE. !Have we successfully reweighted?
open(iFileOut,file=trim(cFileIn)//".brightness",status="REPLACE",action="WRITE")
do i=1,iDimR
arPosR(i) = (arBinR(i)+arBinR(i+1)) / 2.0
if(aiMapR(i).EQ.0)then
print '(X,A,ES10.4,A,ES10.4,A)','WARNING: Unsampled radial bin from ',&
arBinR(i),' to ',arBinR(i+1),'cm.'
write(iFileOut,'(ES12.5,X)') arPosR(i)
else
bReweight=.TRUE.
arMapR(i) = arMapR(i) / (rcPi * (arBinR(i+1)**2-arBinR(i)**2)) !Area correction
if(i>1) arReweightMult(i) = arMapR(1)/arMapR(i) !Build reweight map
write(iFileOut,'(3(ES12.5,X),I0)') arPosR(i), arMapR(i),arReweightMult(i),aiMapR(i) !Write to brightness file
endif
enddo
close(iFileOut)
if(.NOT.bReweight)then
print '(X,A)','ERROR: No radial bins sampled, could not reweight.'
STOP
endif
endif
! ============================================================================
print *,"Reading in '"//trim(cFileIn)//".delay_dump'..."
iPhotR =0
iErr=0
iEOF=0
iLine=0
open(iFileIn,file=trim(cFileIn)//".delay_dump",status="OLD",action="READ")
read(iFileIn,*) cDummy
iLine=iLine+1
do while(iErr.EQ.0 .AND.iEOF.EQ.0)
read(iFileIn,'(A512)',iostat=iEOF) cBuffer
iLine=iLine+1
if(cBuffer(1:1).NE."#")then
iPhot=iPhot+1
read(cBuffer,*,iostat=iErr) rDummy, rLambda, rWeight, rPosX, rPosY, rPosZ, &
iNScat, iNRScat, rDelay, iObserver, iOrigin, iNRes
iNCScat = iNScat - iNRScat
!If we're in line mode, check to see if this photon's origin line is in the list of tracked lines
if(bLineMode)then
bLineFound=.FALSE.
do i=1,iLines
if(iNRes.EQ.aiLine(i)) bLineFound=.TRUE.
enddo
endif
!If we're in origin mode, check to see if this photon's origin is in the list of tracked origins
if(bOriginMode)then
bOriginFound=.FALSE.
do i=1,iOrigins
if(iOrigin.EQ.aiOrigin(i)) bOriginFound=.TRUE.
enddo
endif
if(iErr.GT.0)then
iErr=0
iEOF=0
iErrMalf=iErrMalf+1
if(iErrMalf.LT.10)then
print '(X,A,I0)','WARNING: Malformed entry on line ',iLine
elseif(iErrMalf.EQ.10)then
print '(X,A,I0,A)','WARNING: Malformed entry on line ',iLine,'. Suppressing further warnings.'
endif
elseif(iObserver.LT.iObserverMin.OR.iObserver.GT.iObserverMax)then
!Do nothing
elseif(bLineMode.AND..NOT.bLineFound)then
!Do nothing
elseif(bOriginMode.AND..NOT.bOriginFound)then
!Do nothing
elseif(iNCScat.LT.iNCScatMin.OR.iNCScat.GT.iNCScatMax)then
!Do nothing
elseif(iNRScat.LT.iNRScatMin.OR.iNRScat.GT.iNRScatMax)then
!Do nothing
else
iPhotR= iPhotR+1
if(bLineVel)then
iBinX = ifLookupIndex(arBinX,rfWaveToVel(rLambda, rLineLambda))
else
iBinX = ifLookupIndex(arBinX,rLambda)
endif
iBinY = ifLookupIndex(arBinY,rDelay/rSecsToDays)
if(iBinX.LT.1 .OR. iBinY.LT.1)then
iErrLog=iErrLog+1
if(iErrLog.LT.10) then
print '(X,A,ES10.4,A,ES10.4,A,I0)','WARNING: Point at frequency ',rLambda,&
', path ',rDelay/rSecsToDays,' lies outside range #',iErrLog
elseif(iErrLog.EQ.10)then
print '(X,A,ES10.4,A,ES10.4,A,I0,A)','WARNING: Point at frequency ',rLambda,&
', path ',rDelay/rSecsToDays,' lies outside range #',iErrLog,". Suppressing further warnings."
endif
else
!If using surface brightness correction, then adjust
if(bReweight)then
rRad = sqrt(rPosX**2+rPosY**2)
iBinR = ifLookupIndex(arBinR, rRad)
if(iBinR .GT. -1)then
rWeight = arReweightMult(iBinR) * rWeight * rRad**(-1.5)
aiMap(iBinX,iBinY,iObserver) = aiMap(iBinX,iBinY,iObserver) + 1
arMap(iBinX,iBinY,iObserver) = arMap(iBinX,iBinY,iObserver) + rWeight
aiMapX(iBinX,iObserver) = aiMapX(iBinX,iObserver) + 1
arMapX(iBinX,iObserver) = arMapX(iBinX,iObserver) + rWeight
aiMapY(iBinY,iObserver) = aiMapY(iBinY,iObserver) + 1
arMapY(iBinY,iObserver) = arMapY(iBinY,iObserver) + rWeight
arNormalise(iObserver) = arNormalise(iObserver) + rWeight
else
iErrWeight=iErrWeight+1
if(iErrWeight.LT.10)then
print '(X,A,ES9.2,A,I0)','WARNING: Point at radius ',rRad,' could not be reweighted #',iErrWeight
elseif(iErrWeight.EQ.10)then
print '(X,A,ES9.2,A,I0,A)','WARNING: Point at radius ',rRad,' could not be reweighted #',&
iErrWeight,'. Suppressing further warnings.'
endif
endif
else
aiMap(iBinX,iBinY,iObserver) = aiMap(iBinX,iBinY,iObserver) + 1
arMap(iBinX,iBinY,iObserver) = arMap(iBinX,iBinY,iObserver) + rWeight
aiMapX(iBinX,iObserver) = aiMapX(iBinX,iObserver) + 1
arMapX(iBinX,iObserver) = arMapX(iBinX,iObserver) + rWeight
aiMapY(iBinY,iObserver) = aiMapY(iBinY,iObserver) + 1
arMapY(iBinY,iObserver) = arMapY(iBinY,iObserver) + rWeight
arNormalise(iObserver) = arNormalise(iObserver) + rWeight
endif
endif
endif
endif
end do
close(iFileIn)
if(iErrLog.GT.0) print '(X,A,I0,A)',"WARNING: ",iErrLog," points lay outside the map range."
if(iErrMalf.GT.0)print '(X,A,I0,A)',"WARNING: ",iErrMalf," lines in the file were malformed."
print '(X,I0,A,I0,A,I0,A)',iPhotR,"/",iPhot," photons scattered."
if(iPhotR.EQ.0)then
print *,'ERROR: No photons fit scattering parameters'
STOP
endif
!For each observer, output a plot
do iObs=iObserverMin,iObserverMax
!If there is only one observer, don't bother adding the name
if(iObservers.GT.1)then
print '(A,I0,A)','Writing to "'//trim(cFileOut)//'.',iObs,'.eps"'
else
print '(A)','Writing to "'//trim(cFileOut)//'.eps"'
endif
print *,"Total flux for observer: ",arNormalise(iObs)
if(bWithUnits)then
!Give units
do i=1, iDimX
do j=1, iDimY
!We have binned erg s in bins of [A|m/s] and days
arMap(i,j,iObs) = arMap(i,j,iObs) * rSecsToDays / &
((arBinX(i+1)-arBinX(i)) * (arBinY(i+1)-arBinY(i)))
end do
end do
else
!Normalise the results
rRespMax = 0
do i=1, iDimX
do j=1, iDimY
if(arMap(i,j,iObs).GT.rRespMax) rRespMax = arMap(i,j,iObs)
end do
end do
arMap(:,:,iObs) = arMap(:,:,iObs)/rRespMax
endif
!If we are tracking a single line to find the mass
if(bLineMode.AND.iLines.EQ.1)then
call sLineAnalysis(arMapX(:,iObs),arMapY(:,iObs),arBinX,arBinY, rLineLambda)
endif
if(.not.bPointwiseOnly)then
open(iFileOut,file=trim(cFileOut)//".bin_XY",status="REPLACE",action="WRITE")
do j=1,iDimY
rPosY = rMinY+(j-.5)*(rMaxY-rMinY)/real(iDimY)
do i=1,iDimX
rPosX = rMinX+(i-.5)*(rMaxX-rMinX)/real(iDimX)
if(aiMap(i,j,iObs).GT.0 .AND. arMap(i,j,iObs).GT.0) then
rErr = sqrt(REAL(aiMap(i,j,iObs)))/aiMap(i,j,iObs)
write(iFileOut,'(4(ES12.5,1X))') rPosX, rPosY, arMap(i,j,iObs), rErr
else
write(iFileOut,'(4(ES12.5,1X))') rPosX, rPosY, 0.0, 1.0
endif
end do
end do
close(iFileOut)
endif
if(bPointwise)then
!If we're doing this pointwise, then for each
open(iFileOut,file=trim(cFileOut)//".bin_XYp",status="REPLACE",action="WRITE")
do i=1,iDimX
rPathPeak = rfFindPeak(arMap(i,:,iObs), arBinY, iPathPeak)
rPathCent = rfFindCentroid(arMap(i,:,iObs), arBinY, rPathCentL, rPathCentU, 0.8*arBinY(iPathPeak))
if(rPathCent > 0)then
write(iFileOut,'(6(ES12.5,1X))') (arBinX(i)+arBinX(i+1))/2, arBinX(i), arBinX(i+1),&
rPathCent, rPathCentL, rPathCentU
endif
end do
close(iFileOut)
endif
open(iFileOut,file=trim(cFileOut)//".bin_X",status="REPLACE",action="WRITE")
do i=1,iDimX
rPosX = rMinX+(i-.5)*(rMaxX-rMinX)/real(iDimX)
if(aiMapX(i,iObs).GT.0 .AND. arMapX(i,iObs).GT.0) then
rErr = sqrt(REAL(aiMapX(i,iObs)))/aiMapX(i,iObs)
write(iFileOut,'(3(ES12.5,1X))') rPosX, arMapX(i,iObs), rErr
else
write(iFileOut,'(3(ES12.5,1X))') rPosX, 0.0, 1.0
endif
end do
close(iFileOut)
open(iFileOut,file=trim(cFileOut)//".bin_Y",status="REPLACE",action="WRITE")
do i=1,iDimY
rPosY = rMinY+(i-.5)*(rMaxY-rMinY)/real(iDimY)
if(aiMapY(i,iObs).GT.0 .AND. arMapY(i,iObs).GT.0) then
rErr = sqrt(REAL(aiMapY(i,iObs)))/aiMapY(i,iObs)
write(iFileOut,'(3(ES12.5,1X))') rPosY, arMapY(i,iObs), rErr
else
write(iFileOut,'(3(ES12.5,1X))') rPosY, 0.0, 1.0
endif
end do
close(iFileOut)
open(iFileOut,file=trim(cFileOut)//".plot",status="REPLACE",action="WRITE")
write(iFileOut,'(A)')'set term postscript eps color enhanced font "Times-New-Roman,18"'
if(iObservers.GT.1)then
write(iFileOut,'(A,I0,A)')'set output "'//trim(cFileOut)//'.',iObs,'.eps"'
else
write(iFileOut,'(A)')'set output "'//trim(cFileOut)//'.eps"'
endif
write(iFileOut,'(A)')'set multiplot'
write(iFileOut,'(A)')'set bmargin 0; set tmargin 0; set lmargin 0; set rmargin 0'
if(.NOT.bNoLog)then
write(iFileOut,'(A)')'set log cb'
write(iFileOut,'(A)')'set cbtics format "%.1T"'
endif
write(iFileOut,'(A)')'set colorbox user origin 0.65,0.05 size .05,0.3'
if(bNoKey.OR.bPointwiseOnly)then
write(iFileOut,'(A)')'unset colorbox'
endif
write(iFileOut,'(A)')'set origin 0.1,0.4'
write(iFileOut,'(A)')'set size 0.5,0.5'
write(iFileOut,'(A)')'set xrange ['//trim(r2c(rMinX))//':'//trim(r2c(rMaxX))//']'
write(iFileOut,'(A)')'set yrange ['//trim(r2c(rMinY))//':'//trim(r2c(rMaxY))//']'
write(iFileOut,'(A)')'set xtics ('//trim(r2c(rMinX))//', '//trim(r2c(rMinX+.25*rRngX))//&
', '//trim(r2c(rMinX+.5*rRngX))//', '//trim(r2c(rMinX+.75*rRngX))//&
', '//trim(r2c(rMaxX))//') mirror format ""'
write(iFileOut,'(A)')'unset xlabel'
write(iFileOut,'(A)')'set ytics ('//trim(r2c(rMinY))//', '//trim(r2c(rMinY+.25*rRngY))//&
', '//trim(r2c(rMinY+.5*rRngY))//', '//trim(r2c(rMinY+.75*rRngY))//&
', '//trim(r2c(rMaxY))//') mirror format ""'
write(iFileOut,'(A)')'unset ylabel'
write(iFileOut,'(A)')'set tics front'
write(iFileOut,'(A)')'set palette rgb -34,-35,-36'
if(bChangeCB)then
write(iFileOut,'(A)')'set cbrange ['//trim(r2c(rMinCB))//':'//trim(r2c(rMaxCB))//']'
else
write(iFileOut,'(A)')'set cbrange [1e-5 : 1]'
endif
if(.NOT.bNoKey)then
if(bNoLog)then
cKey = 'set cblabel "Log "'
else
cKey = 'set cblabel '
endif
if(bLineVel)then
cKey = trim(cKey)//'"{/Symbol j}(v, {/Symbol t}) '
else
cKey = trim(cKey)//'"{/Symbol j}(v, {/Symbol t}) '
endif
if(bWithUnits)then
cKey = trim(cKey)//' erg {\305}^{-1}'
endif
cKey = trim(cKey)//'" font ",24" offset 1,0'
endif
if(bPointwiseOnly)then
write(iFileOut,'(A)')'plot "'//trim(cFileOut)//'.bin_XYp" u 1:4:2:3:5:6 w xyerrorbars notitle'
elseif(bPointwise)then
write(iFileOut,'(A)')'plot "'//trim(cFileOut)//'.bin_XY" u 1:2:3 w ima notitle, \'
write(iFileOut,'(A)')' "'//trim(cFileOut)//'.bin_XYp" u 1:4:2:3:5:6 w xyerrorbars notitle linewidth 3.0 lc rgb "light-magenta"'
else
write(iFileOut,'(A)')'plot "'//trim(cFileOut)//'.bin_XY" u 1:2:3 w ima notitle'
endif
write(iFileOut,'(A)')'set origin 0.6,0.4'
write(iFileOut,'(A)')'set size 0.15,0.5'
write(iFileOut,'(A)')'set xrange [*:*] reverse'
write(iFileOut,'(A)')'set yrange ['//trim(r2c(rMinY))//':'//trim(r2c(rMaxY))//']'
write(iFileOut,'(A)')'set xtics autofreq format ""'
write(iFileOut,'(A)')'unset xlabel'
write(iFileOut,'(A)')'unset ytics'
write(iFileOut,'(A)')'unset ylabel'
write(iFileOut,'(A)')'unset colorbox'
write(iFileOut,'(A)')'unset log x'
write(iFileOut,'(A)')'unset log y'
write(iFileOut,'(A)')'unset log cb'
write(iFileOut,'(A)')'set y2tics ('//trim(r2c(rMinY))//', '//trim(r2c(rMinY+.25*rRngY))//&
', '//trim(r2c(rMinY+.5*rRngY))//', '//trim(r2c(rMinY+.75*rRngY))//&
', '//trim(r2c(rMaxY))//') mirror format '//trim(cTicks)
if(.NOT.bNoTicks)write(iFileOut,'(A)')'set y2label "Delay {/Symbol t} (days)" font ",22"'
write(iFileOut,'(A)')'plot "'//trim(cFileOut)//'.bin_Y" u 2:1 w l notitle'
write(iFileOut,'(A)')'set origin 0.1,0.25'
write(iFileOut,'(A)')'set size 0.5,0.15'
write(iFileOut,'(A)')'set xrange ['//trim(r2c(rMinX))//':'//trim(r2c(rMaxX))//'] noreverse'
write(iFileOut,'(A)')'set yrange [*:*]'
if(bNoTicks)then
elseif(bLineVel)then
write(iFileOut,'(A)')'set xlabel "Velocity (10^{3} km s^{-1})" font ",22"'
write(iFileOut,'(A)')'set xtics ('//trim(r2c(rMinX))//', '//trim(r2c(rMinX+.25*rRngX))//&
', '//trim(r2c(rMinX+.5*rRngX))//', '//trim(r2c(rMinX+.75*rRngX))//&
', '//trim(r2c(rMaxX))//') mirror format '//'"%.1f"'
else
write(iFileOut,'(A)')'set xlabel "Wavelength (10^{-10}cm)" font ",22"'
write(iFileOut,'(A)')'set xtics ('//trim(r2c(rMinX))//', '//trim(r2c(rMinX+.25*rRngX))//&
', '//trim(r2c(rMinX+.5*rRngX))//', '//trim(r2c(rMinX+.75*rRngX))//&
', '//trim(r2c(rMaxX))//') mirror format '//'"%.0f"'
endif
write(iFileOut,'(A)')'set ytics autofreq format ""'
write(iFileOut,'(A)')'unset ylabel'
write(iFileOut,'(A)')'unset y2tics'
write(iFileOut,'(A)')'unset y2label'
write(iFileOut,'(A)')'unset log x'
write(iFileOut,'(A)')'unset log y'
write(iFileOut,'(A)')'plot "'//trim(cFileOut)//'.bin_X" u 1:2 w l notitle'
close(iFileOut)
call EXECUTE_COMMAND_LINE('gnuplot '//trim(cFileOut)//'.plot')
if(.NOT.bMessy)then
call EXECUTE_COMMAND_LINE('rm '//trim(cFileOut)//'.bin_* '//trim(cFileOut)//'.plot ')
endif
end do
print *,"Finished"
contains
Subroutine sLineAnalysis(arMapWave, arMapPath, arBinWave, arBinPath, rLineWave)
Real(iKindDP), intent(in), dimension(:) :: arMapWave, arMapPath, arBinWave, arBinPath
Real(iKindDP), intent(in) :: rLineWave
Real(iKindDP) :: rWaveWidth, rFreqPeak, rPathPeak, rPathCent, rPathCentU, rPathCentL
Real(iKindDP) :: rVelocity, rMass, rRadiusMin, rRadiusMax, rMassMin, rMassMax, rRadius
Real(iKindDP) :: rFormFactor, rFormFactorError
Integer :: iPathPeak
rPathPeak = rfFindPeak(arMapPath, arBinPath, iPathPeak)
rPathCent = rfFindCentroid(arMapPath, arBinPath, rPathCentL, rPathCentU, 0.8*arBinPath(iPathPeak))
if(bLineBHUseRMS)then
rWaveWidth = rfFindRMS(arMapWave, arBinWave, rPathCent)
else
rWaveWidth = rfFindFWHM(arMapWave, arBinWave)
endif
print *,'Path centroid for line: '//trim(r2c(rPathCent))//' days (1σ: '//trim(r2c(rPathCentL))//' - '//trim(r2c(rPathCentU))//' days)'
print *,'Width for line:'//trim(r2c(rWaveWidth))
rFormFactor = 5.0
rFormFactorError = 1.0
rVelocity = rcC * rWaveWidth / rLineWave
rRadius = rPathCent * rSecsToDays * rcC
rRadiusMin = rPathCentL * rSecsToDays * rcC
rRadiusMax = rPathCentU * rSecsToDays * rcC
rMass = rFormFactor * rRadius * rVelocity**2 / (rcG * rcMSol)
rMassMin = (rFormFactor - rFormFactorError) * rRadiusMin * rVelocity**2 / (rcG * rcMSol)
rMassMax = (rFormFactor + rFormFactorError) * rRadiusMax * rVelocity**2 / (rcG * rcMSol)
print *,'Mass for line: '//trim(r2c(rMass))//' ('//trim(r2c(rMassMin))//' - '//trim(r2c(rMassMax))//')'
End Subroutine
Real(iKindDP) Function rfWaveToVel(rWave, rLineWave)
Real(iKindDP), intent(in) :: rLineWave, rWave
rfWaveToVel = rcC * (rWave - rLineWave) / rLineWave
End Function
Real(iKindDP) Function rfFindFWHM(arVal, arBin)
Real(iKindDP), intent(in), dimension(:) :: arVal, arBin
Real(iKindDP) :: rPeak, rPeakVal, rHalfL, rHalfU
Integer :: i, iPeak
rPeak = rfFindPeak(arVal, arBin, iPeak, rPeakVal)
do i=iPeak,size(arVal)
if(arVal(i).LE.rPeakVal/2.0)then
rHalfU = arBin(i)
EXIT
endif
enddo
do i=iPeak,1,-1
if(arVal(i).LE.rPeakVal/2.0)then
rHalfL = arBin(i+1)
EXIT
endif
enddo
rfFindFWHM = rHalfU - rHalfL
End Function
Real(iKindDP) Function rfFindRMS(arVal, arBin, rPeak)
Real(iKindDP), intent(in), dimension(:) :: arVal, arBin
Real(iKindDP), intent(in) :: rPeak
Real(iKindDP) :: rRMS, rValTot
Integer :: i, iPeak
rValTot = 0.0
do i=1,size(arVal)
rValTot = rValTot + arVal(i)
enddo
do i=1,size(arVal)
rRMS = rRMS + (arVal(i) * (((arBin(i)+arBin(i+1))/2) - rPeak) ** 2.0)
enddo
rfFindRMS = sqrt(rRMS/rValTot)
End Function
Real(iKindDP) Function rfFindCentroid(arVal, arBin, rCentLOpt, rCentUOpt, rThresholdOpt)
Real(iKindDP), intent(in), dimension(:) :: arVal, arBin
Real(iKindDP), intent(in), optional :: rThresholdOpt