forked from Pizzuti92/MG-MAMPOSSt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomamposstoptS.f
7611 lines (6388 loc) · 218 KB
/
gomamposstoptS.f
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 gomamposstoptS
c Version of 28/10/2021 - inclusion of beyond Hrodenski and general
c chameleon gravity. Lensing additional simulation
c plots with the gedist python package
c ADDED THE gNFW PROFILE: option kmp=10
c THE Exponent gamma is given by the tmass
c derived from gomamposst.f ...'opt' for optimization
c The pgm assumes interlopers have been removed
c unless one requires a joint halo+interlopers MAMPOSSt
c analysis
c Distances must be given in kpc from cluster center
c Velocities must be given in km/s, rest-frame
c (hence after 1/(1+<z>) correction, with <v>=0)
c History of modifications:
c Gap & Interloper removal part removed
c H0 is an input parameter (in place of the interloper rejection parameter)
c PIEMD M(r) inserted
c Modified Tiret anisotropy model inserted (it has non-zero anisotropy
c at r=0)
c Minimization program inserted
c beta-model with fixed (free choice) alpha for N(R) inserted
c Burkert and Softened IS M(r) inserted
c Hansen+Moore beta(r)=a+b*dln(rho)/dln(r) inserted
c Handling optimization with only 1 free parameter
c Inclusion of velocity errors in the analysis
c Corrected error in normalisation of Hernquist M(r)
c Removed file of 'true' values from the input files
c Added a Ngals-dependent scaling for the grid width
c so that samples with fewer galaxies use wider grids
c Added a fixed-m Einasto model
c Forcing beta<1
c Pushing the determination of los VDP to lower distances
c from the center (5 kpc)
c weights added in input file
c Last modif: Paris, June 2012
c Trieste, September 2012
c Trieste, October 2012
c Milano, November 2012
c Trieste, December 2012
c Trieste, January 2013
c Paris, February 2013
c Trieste, July 2013
c Munchen, December 2014
c Trieste, January 2015
c Aosta, September 2019
c Aosta, September 2021
c Aosta, October 2021: removed copyrighted imsl routines;
c substituted by John Burkardt's
c routines (GNU public license) and
c SLATEC routines by Jones, R. E., (SNLA)
c if needed, re-create the archives:
c (change the permission of the script to make them executable)
c ./script/script_Lib.sh
c Compile with ./script/script_compile.sh
c Execute as ./script/script_runmam.sh
implicit real*8 (a-h,o-z)
implicit integer*4 (i-n)
parameter (pig=3.1415926535d0,iga=25000,
& grav=4.302e-9,q0=-0.64,clight=2.99792458d5,npar=6)
dimension di(iga),ve(iga),eve(iga),dns(iga),ra(iga),de(iga),
& rso(iga),vso(iga),bins(400),pars(27),
& syb(1000),sybs(1000),vkb(1000),vkbs(1000),
& xx(iga),yy(iga),yboo(iga),wboo(iga),ww(iga),
& iw(iga), sigma(npar)
character*75 fgroup,frnvn,fbfn,fbn,ffn,fmlv,fprop,line,
& fsb,fsf,fsft,fkb,fkf,fkft,fparmam
real*8 rjl(1), yrjl(1)
c all file to be read by MAMPOSSt *************************
include 'datarv.i' !definition of data arrays
include 'paramsoptS.i' !all useful parameters
include 'units.i'
include 'sr.i'
include 'vkr.i'
include 'vlos.i'
include 'tsallis.i'
external fcn1,fcn2,fcn3,fa,fkii
external sr2int,sr2out,sigmar1,sigmar2,sigmar3,gwenu
external vr4nuint
external sigmarnorm
external gammarec
external frLin
external r_normal_ab
external fmg
external f_nfw
external gmg
external g_nfw
c call uerset(1,levold)
icsr = 100
icsrk = 100
c number of bootstrap resamplings for the errors on sigma_los
nboo=500
c User's inputs
qtsa=1. ! forcing Gaussian MAMPOSSt
c Tsallis constants and exponent
if (abs(qtsa-1.).gt.0.01) then
ktsa=1
atsa=qtsa/(1.-qtsa)
batsa=1.d0/(2.5d0+atsa)
if (atsa.gt.0) then
atatsa=gammarec(2.5d0+atsa)/gammarec(1.d0+atsa)*batsa**1.5
elseif (atsa.lt.-2.5) then
atatsa=gammarec(-atsa)/gammarec(-1.5-atsa)*(-batsa)**1.5
endif
else
ktsa=0
endif
c
c Values of the parameters of Hansen & Moore's (2006)
c beta = a + b dln(rho)/dln(r) relation
c
ahm=-0.15
bhm=-0.192
c***********************************************************************
c tmass=5.0
c r200=3.0
c rs=0.3
c write(*,*)gamma_mg(1.0d0,r200t,rst,15.0d0,0.0d0),gamma_true(1.0d0)
c call Likelens_bh(10,plens)
c write(*,*) plens
c stop
write(*,*) ' '
write(*,*) ' '
write(*,*) ' ***************************************'
write(*,*) ' *** ***'
if (ktsa.gt.0.5) then
write(*,*) ' *** Welcome into Tsallis MG-MAMPOSSt! ***'
else
write(*,*) ' *** Welcome into Gaussian MG-MAMPOSSt! ***'
endif
write(*,*) ' *** ***'
write(*,*) ' ***************************************'
write(*,*) ' '
write(*,*) ' '
write(*,100)
100 format(' Input files: '/
& ' (1) data (R [kpc], Vrf [km/s], errVrf [km/s], weights',/
& ' (2) input parameters for MAMPOSSt ')
read(*,9) fgroup
read(*,9) fparmam
9 format(a)
open(10,file=fgroup,status='old') !data file
open(29,file=fparmam,status='old') !parameter file (name is in gomamposst*.inp)
write(*,196) fgroup
196 format(//' Data-set is ',a50,//)
c read file with parameters for MAMPOSSt
do i=1,6
read(29,291) pars(i)
291 format(f9.4)
enddo
read(29,9) line
do i=7,12
read(29,291) pars(i)
enddo
read(29,9) line
do i=13,26
read(29,291) pars(i)
enddo
read(29,9) line
read(29,291) r2low !r200 lower bound
read(29,291) r2up !r200 upper bound
read(29,291) rclow !rc lower bound
read(29,291) rcup !rc upper bound
read(29,291) rslow !rs lower bound
read(29,291) rsup !rs upper bound
read(29,291) blow !beta lower bound
read(29,291) bup !beta upper bound
read(29,291) tmlow !tmass lower bound
read(29,291) tmup !tmass upper bound
read(29,291) scrlow !screen lower bound
read(29,291) scrup !screen upper bound
close(29)
************************************************************************
nr200=nint(pars(1)) ! number of steps for r200 fit
nrc=nint(pars(2)) ! number of steps for rc fit, scale radius of N(R)
! [if = 0 takes guess value]
! [if = -1 forces LfM, c_nu=c]
! [if = -2 fit N(R) outside MAMPOSSt]
nrs=nint(pars(3)) ! number of steps for rs fit, scale radius of M(r)
! [if = 0 takes guess value]
! [if = -1 forces MfL, c=c_nu]
! [if = -2 forces LCDM, c=c(M)]
nbs=nint(pars(4)) ! number of steps for anisotropy parameter
! [if = -1 forces a_ML=r_s]
! [if = -2 forces Hansen+Moore]
ntmass=nint(pars(5)) ! number of steps in mass parameter
nhone=nint(pars(6)) ! number of steps in the additional free parameter
! could be the screening radius for f(R)-Hu Sawicki
! or Coupling constant Q for chameleon gravity
************************************************************************
r200g=pars(7) ! r200 initial guess (Mpc)
r200=r200g ! set r200 initial value to guess value
rcg=pars(8) ! N(R) scale radius initial guess (Mpc)
rsg=pars(9) ! rho(r) scale radius initial guess (Mpc)
cbeg=pars(10) ! Anisotropy initial guess, beta', a_ML, a_OM, a_W, beta'_inf
tmassg=pars(11) ! MG parameter initial guess
screeg=pars(12) ! Screening initial guess
rs=rsg !set scale radius to guess value
screen=screeg !set screening to guess value
write(*,346) nr200,nrc,nrs,nbs,ntmass,nhone
346 format(' Grid steps in r200, rtr, rs, anis, mod1, mod2: ',6(i5))
************************************************************************
h0=pars(13) ! Hubble constant at z=0
za=pars(14) ! average redshift of the cluster (needed to evaluate Hz)
! since velocities are given as rest-frame in input file
Olam=pars(15)
Omegam=pars(16)
rlowin=pars(17) ! Inner radius for sample selection (Mpc)
rupin=pars(18) ! Outer radius for sample selection (Mpc)
kintd=0 !nint(pars(19)) ! Use universal surface density of interlopers? N/Y=0/1 (note: in this version
! the interlopers have been already removed from the input file)
knfit=nint(pars(19)) ! N(R) model, projected NFW / projected Hernquist / beta-model (1/2/3)
!
al=pars(20) ! N(R) negative exponent (only if knfit=3)
kmp=nint(pars(21)) ! rho(r) model: NFW/Hernquist/PIEMD/Burkert/SoftIS/Einasto_m=5/
! mod_NFW linear f(R)/mod_NFW beyond Horndeski/mod_NFW general chameleon (1/2/3/4/5/6/7/8/9)
kani=nint(pars(22)) ! Anisotropy model, beta'=constant, MamLok, OsiMer,
! simplified Wojtak, simplified Tiret, modified Tiret (0,1,2,3,4,5)
if (nbs.eq.-1.) kani=1 ! forced to MamLok if requested
if (nbs.eq.-2.) kani=-1 ! if Hansen&Moore, beta(r) depends on rho(r)
rcut=pars(23) ! PIEMD model rcut in Mpc (only used if kmp=3)
kbsp=nint(pars(24)) ! run MAMPOSSt in fast mode? N/Y=0/1
kopt=nint(pars(25)) ! optimization algorithm: 0/1/2=bobyqa/newuao/powell
! -1 skip optimization
c********************** implemented phenomenological screening *********
c for linear f(R) kmp.eq.7, one can decide to set an instantaneous
c transition between screeening and linear regime, by using the
c analytical approximation of Lombriser+12.
kscr=nint(pars(26)) !-1/0/1/2=noscreen (general Hordenski)/noscreen f(R)/screen(instantaneous transition)
!/screen (arctan transition)/
!if kscr=3 then the modified gravity contribution assumes the form of
!general hordenski gravity with coupling Q=Screen
c***********************************************************************
if(r200g.gt.r2up.or.r200g.lt.r2low) then
Stop('ERROR: GUESS VALUE r200 EXCEEDES PARAMETER LIMITS')
endif
if(rsg.gt.rsup.or.rsg.lt.rslow) then
Stop('ERROR: GUESS VALUE rs EXCEEDES PARAMETER LIMITS')
endif
if(rcg.gt.rcup.or.rcg.lt.rclow) then
Stop('ERROR: GUESS VALUE rc EXCEEDES PARAMETER LIMITS')
endif
if(cbeg.gt.bup.or.cbeg.lt.blow) then
Stop('ERROR: GUESS VALUE beta EXCEEDES PARAMETER LIMITS')
endif
if(tmassg.gt.tmup.or.tmassg.lt.tmlow) then
Stop('ERROR: GUESS VALUE mod1 EXCEEDES PARAMETER LIMITS')
endif
if(screeg.gt.scrup.or.screeg.lt.scrlow) then
Stop('ERROR: GUESS VALUE mod2 EXCEEDES PARAMETER LIMITS')
endif
if (kmp.lt.7) then ! if no MG model is considered, tmassg is set to zero
tmassg=0.0d0
endif
tmass=tmassg !set the mass to the guess value
c Chameleon screening allowed only for linear f(R)
if (kmp.ne.7) then
write(*,*) 'Option kscr not used in this model'
kscr=0
endif
c
if (kmp.eq.7.or.kmp.eq.9) then
if (tmassg.le.0) then
stop('ERROR: inconsitent negative MG parameter')
endif
if (tmlow.le.0) tmlow=1.0e-4
if (tmup.le.0) tmup=1.0e-4
endif
c exponent for f(R) Hu&Sawicki model (to be set manually)
nhs=2
c Coupling constant for f(R)
aQ=1./6
if (kscr.ne.-1) then
if (kscr.eq.1) then
write(*,811) nhs
811 format(/' Screening: '/
& 'f(R) gravity, Hu&Sawicki model with n =',i4,/
& ' instantaneous transition between linear and screen ')
elseif (kscr.eq.2) then
write(*,801) nhs
801 format(/' Screening: '/
& 'f(R) gravity, Hu&Sawicki model with n = ',i4,/
& ' modelled transition between linear and screen '/
& 'arcatan function with sharpness=10 ')
elseif(kmp.ne.9.and.kmp.ne.8) then
screeg=0.0d0 !screening guess value forced to be zero
nhone=0 !number of steps in screening radius
endif
else
aQ=screen !set the coupling constant in frLin(x) to be equal to
!the guess value
write(*,802) tmass,screen
802 format(/' Linear Horndeski gravity: '/
& 'guess value of free parameter mass= ',f7.4,/
& ' and coupling constant= ',f7.4 )
endif
c Stop if H&M beta(r) required and M(r) difft from NFW
c
if (kani.lt.0.and.knfit.ne.1) then
write(*,*) ' Hansen & Moore beta(r) currently '
write(*,*) ' implemented only for pNFW N(R) model '
stop
endif
kgas=0
kdata=0
if (kdata.eq.1) then
write(*,*)
write(*,*) "QUANNO POZZO M'APPALLOZZO "
write(*,*) " SPESSO POZZO "
write(*,*) " Greetings from OAVdA "
write(*,*) ""
write(*,*) "****************************************************"
write(*,*) " DATA-MODE unlocked:this is a module to read lensing"
write(*,*) " probability chain for the galaxy clusters MACS1206"
write(*,*) " and RXJ2248 and compute a MCMC sampling over "
write(*,*) " that chain. It works only for nlens=1, ncmcm=2,3,4 "
write(*,*) "****************************************************"
write(*,*) ""
endif
write(*,800)
800 format(/' Output files: '/
& ' (1) normalized distances and velocities '/
& ' (2) best-fit result parameters for N(R) '/
& ' (3) binned N(R) '/
& ' (4) fitted N(R) '/
& ' (5) fit Max Lik values for velocity distribution '/
& ' (6) binned sigma_los(R)'/
& ' (7) fitted sigma_los(R) for MAMPOSSt solution')
read(*,9) frnvn
read(*,9) fbfn
read(*,9) fbn
read(*,9) ffn
read(*,9) fmlv
read(*,9) fsb
read(*,9) fsf
open(20,file=frnvn,status='unknown')
open(30,file=fbfn,status='unknown')
open(40,file=fbn,status='unknown')
open(50,file=ffn,status='unknown')
open(60,file=fmlv,status='unknown')
open(70,file=fsb,status='unknown')
open(80,file=fsf,status='unknown')
c read system properties
c read radial positions, velocities and velocity errors;
c positions are in kpc, vels are in km/s, assumed rest-frame
c errors are in km/s
read(10,9) line
read(10,9) line
j=0
j0=-1
dimin=1.e12
222 continue
read(10,*,end=111) dkpc,vkms,evkms !,wei !to put in the case of four columns
j=j+1
di(j)=dkpc/1.e3
ve(j)=vkms
eve(j)=evkms
w(j)=1.0
c w(j)=wei
if (di(j).lt.dimin) then
dimin=di(j)
j0=j
endif
iw(j)=j
goto 222
111 continue
npg=j
close(10)
write(*,*) npg,' galaxies in the sample'
c get an estimate of the velocity dispersion
ibwt=1
call robusti(ve,npg,ibwt,va,sv)
c First guess at m200, v200; sigma_v is determined from r200
c using Mauduit & Mamon's scaling (a poly approx to it)
c and the concentration appropriate for the m200 found
c adopting a scaling intermediate between Duffy et al.'s
c and (Dolag et al.'s) Gao et al.'s [at z=0]
omegal=Olam!6
omega0=Omegam !2.*(q0+omegal) cosmological parameters
hz=h0*sqrt(omega0*(1.+za)**3+omegal)
rv=r200
rm200=100.*hz*hz/grav*r200**3
cduffy=5.78*(rm200/2.e12)**(-0.089)*1.1**(-0.52)
cgao=10.**(-0.138*dlog10(rm200*0.7)+2.646)
cmean=(cduffy+cgao)/2.
rsmean=rv/cmean
v200=10.*hz*r200
sv=(429.-0.6*cmean+0.4*cmean*cmean)*r200
write(*,182) za,rv,v200,cmean
182 format(/,' Initial estimates of <z>, r200, v200 and c are: ',
, f7.4,2x,f5.2,2x,f5.0,2x,f5.1,//)
c call the mamposst procedure subroutine
iu20=20
iu30=30
iu60=60
c MAMPOSSt subroutine
call mamposst(di,ve,eve,rso,vso,npg)
close(30)
close(60)
if (r200.ne.r200) r200=r200g
write(*,*) ' '
write(*,*) ' After MG-MAMPOSSt: '
write(*,*) ' '
write(*,*) ' build output files of binned N(R), VDP'
write(*,*) ' of best-fit N(R), VDP and of'
write(*,*) ' input N(R), VDP solutions (''true'' values)'
write(*,*) ' '
c output a binned number density profile N(R)
ibwt=0
nbins=int(dsqrt(dfloat(nga)))
do j=1,nga
dns(j)=rso(j)
enddo
c call sort(nga,dns)
c do j=1,nga
c write(*,*) dns(j)
c enddo
call sortp(dns,nga)
do j=1,nbins+1
if (j.eq.nbins+1) then
do l=1,nga-nbins*nbins
xx(l)=dns((j-1)*nbins+l)
enddo
else
do l=1,nbins
xx(l)=dns((j-1)*nbins+l)
enddo
endif
lx=l-1
call robusti(xx,lx,ibwt,cx,zero)
area=pig*(xx(lx)*xx(lx)-xx(1)*xx(1))
bj=cx
dj=dfloat(lx)/area
ej=dsqrt(dfloat(lx))/area
write(40,*) bj,dj,ej
enddo
close(40)
write(*,*) ' Binned N(R) computed'
c output the result of the best-fit for N(R):
c knfit=1,2,3 selects NFW, Hernquist, beta-model, resp.
call sigmarnorm(rc,fnorm)
if (knfit.eq.3) then
c beta model
do k=1,3000
xk=(k-1)*0.002+0.001
fr=(1.+(xk/rc)**2)**al
write(50,*) xk,fr/fnorm*nga
enddo
elseif (knfit.eq.1.or.(nrc.eq.-1.and.kmp.eq.1)) then
c NFW
c=r200/rc
gc=1./(dlog(c+1.)-c/(c+1.))
cc facnorm=gc/(2.*pig) missing the term r200^2 ? Trieste, 21/12/12
facnorm=gc/(2.*pig)/(r200*r200)
do k=1,3000
xk=(k-1)*0.002+0.001
cx=c*xk
uu=1./cx
if (uu.lt.1) then
cm1=dacos(uu)
fr=c*c*
& (1.-1./dsqrt(dabs(cx*cx-1.))*cm1)/(cx*cx-1.)
elseif (uu.gt.1) then
cm1=dacosh(uu)
fr=c*c*
& (1.-1./dsqrt(dabs(cx*cx-1.))*cm1)/(cx*cx-1.)
else
fr=c*c/3.
endif
fr=fr*facnorm
write(50,*) xk,fr/fnorm*nga
enddo
else
c Hernquist
do k=1,3000
xk=(k-1)*0.002+0.001
s=xk/rc
if (s.gt.1.d0) then
xs=dacos(1./s)/dsqrt(s*s-1.)
fr=((2.+s*s)*xs-3.)/(2.*pig*rc*rc*(1.-s*s)**2)
elseif (s.lt.1.d0) then
xs=dlog((1.+dsqrt(1.-s*s))/s)/dsqrt(1.-s*s)
fr=((2.+s*s)*xs-3.)/(2.*pig*rc*rc*(1.-s*s)**2)
endif
if (abs(s-1.d0).lt.0.001d0) then
fr=2./(15.*pig*rc*rc)
endif
write(50,*) xk,fr/fnorm*nga
enddo
endif
close(50)
c Here computes sigma_los
call dsort(rso,vso,nga,2)
nbins=int(sqrt(float(nga)))/2.
npbin=nga/nbins
do j=1,nbins
bins(j)=rso((j-1)*npbin)
bins(j+1)=rso(j*npbin)
enddo
write(*,*) ' Using ',nbins,' bins for the VDP(R) '
do j=1,nbins
npbin=0
do ii=1,nga
if (rso(ii).ge.bins(j).and.rso(ii).lt.bins(j+1)) then
npbin=npbin+1
xx(npbin)=rso(ii)
yy(npbin)=vso(ii)
ww(npbin)=1.d0
endif
enddo
if (npbin.gt.1) then
ibwt=0
call robusti(xx,npbin,ibwt,cxd,sxd)
ibwt=1
call robusti(yy,npbin,ibwt,cyd,syd)
c Bootstrap errors
do iboo=1,nboo
call boot(yy,ww,yboo,wboo,npbin)
call robusti(yboo,npbin,1,cy,sy)
syb(iboo)=sy
enddo
call sortp(syb,nboo)
j16=nint((nboo-1)*0.16+1)
j84=nint((nboo-1)*0.84+1)
esy=0.5d0*(syb(j84)-syb(j16))
write(70,713) npbin,cxd,syd,-esy,esy
713 format(i4,2x,f8.3,3(2x,f9.3))
endif
enddo
close(70)
c Jeans solution M(<r)+nu(r)+beta -> Sigma(R)+VDP(R),
c following Mamon & Lokas (2005, MNRAS, 363, 705)
c using best-fit parameters
errabs=0.
rismin=1.d-190
rismax=1.d190
ninterp=21*2
rinfinity=20.
ius=80
write(*,*) ' Evaluating expected VDP for '
write(*,*) ' Max Lik solution values: '
797 continue
v200=10.*hz*r200
write(*,516) r200,rc,r200/rc,rs,r200/rs,cbe
516 format(' r_200 = ',f6.3,
& /' r_tracer = ',f6.3,' (c_tracer= ',f7.2,')'
& /' r_mass = ',f6.3,' (c_mass= ',f7.2,')'
& /' Anisotropy parameter = ',f8.4,/)
c
c**************************************************************
errrel=0.005d0
c evaluate sigma_r at some points (it will then interpolate)
rlow=0.005d0 ! we want the profile in the inner region (12 Dec. 2014)
do i=1,ninterp
xx2 = dlog(2.d0*rinfinity)
xx1 = dlog(rlow)+dfloat(i-1)*
& dlog(1.001*rinfinity/rlow)/dfloat(ninterp-1)
c risl = dcadre(sr2int,xx1,xx2,errabs,errrel,errest,ier)
call dgaus8 (sr2int,xx1,xx2, errrel, risl, IERR)
xmin=dexp(xx1)
risok=dsqrt(risl*sr2out(xmin))
if (risl.gt.1.8d195) risok=rismax
if (risl.le.0.d0) risok=rismin
xris(i)=xx1
yris(i)=dlog(risok)
enddo
write(*,*) ' sigma_r evaluated'
c
c compute spline coeffs for later interpolation of sigma_r
c
call SPLINE_CUBIC_SET(ninterp,xris,yris,2,0.d0,2,0.d0,ypp2)
c
errrel=0.005d0
errabs=0.
do i=1,50
xx1 = dlog(rlow)+dfloat(i-1)*
& dlog(1.001*rinfinity/rlow)/dfloat(50-1)
xx2=dlog(2.*rinfinity)
xmin=dexp(xx1)
call dgaus8 (fa,xx1,xx2, errrel, ris2n, IERR)
if ((knfit.eq.1).or.(nrc.eq.-1.and.kmp.eq.1)) then
pnr=sigmar1(xmin)
elseif ((knfit.eq.2).or.(nrc.eq.-1.and.kmp.eq.2)) then
pnr=sigmar2(xmin)
else
pnr=sigmar3(xmin)
endif
ris=dsqrt(ris2n/pnr)
if (ris.eq.ris) write(ius,*) xmin,ris
enddo
close(ius)
end
C
C ________________________________________________________
C | |
C | SORT AN ARRAY IN INCREASING ORDER |
C | |
C | INPUT: |
C | |
C | X --ARRAY OF NUMBERS |
C | |
C | Y --WORKING ARRAY (LENGTH AT LEAST N) |
C | |
C | N --NUMBER OF ARRAY ELEMENTS TO SORT |
C | |
C | OUTPUT: |
C | |
C | X --SORTED ARRAY |
C |________________________________________________________|
C From napack of Netlib
SUBROUTINE SORTP(X,N)
real*8 X(N),Y(N),S,T
INTEGER I,J,K,L,M,N
I = 1
10 K = I
20 J = I
I = I + 1
IF ( J .EQ. N ) GOTO 30
IF ( X(I) .GE. X(J) ) GOTO 20
Y(K) = I
GOTO 10
30 IF ( K .EQ. 1 ) RETURN
Y(K) = N + 1
40 M = 1
L = 1
50 I = L
IF ( I .GT. N ) GOTO 120
S = X(I)
J = Y(I)
K = J
IF ( J .GT. N ) GOTO 100
T = X(J)
L = Y(J)
X(I) = L
60 IF ( S .GT. T ) GOTO 70
Y(M) = S
M = M + 1
I = I + 1
IF ( I .EQ. K ) GOTO 80
S = X(I)
GOTO 60
70 Y(M)= T
M = M + 1
J = J + 1
IF ( J .EQ. L ) GOTO 110
T = X(J)
GOTO 60
80 Y(M) = T
K = M + L - J
I = J - M
90 M = M + 1
IF ( M .EQ. K ) GOTO 50
Y(M) = X(M+I)
GOTO 90
100 X(I) = J
L = J
110 Y(M) = S
K = M + K - I
I = I - M
GOTO 90
120 I = 1
130 K = I
J = X(I)
140 X(I) = Y(I)
I = I + 1
IF ( I .LT. J ) GOTO 140
Y(K) = I
IF ( I .LE. N ) GOTO 130
IF ( K .EQ. 1 ) RETURN
GOTO 40
END
c-----------------------------------------------------------------------------
SUBROUTINE XMIDMEAN(XDATA,N,XMID)
c-----------------------------------------------------------------------------
c--- This subroutine calculates the MIDMEAN for a set of N ORDERED
c statistics stored in XDATA. The MIDMEAN is defined to be the
c mean of the central 50% of the data set. This corresponds to
c a 25% Trimmed Mean. The value of the MIDMEAN is returned as
c XMID and is defined:
c
c XMID = TRIM(.25)
c
c where TRIM(.25) is the 25% trimmed mean as defined above. For
c more information on the MIDMEAN or TRIMMED MEAN see pages 312,
c 313 and pages 307, 308 in UREDA.
c****************************************************************************
implicit real*8 (a-h,o-z)
implicit integer*4 (i-n)
dimension xdata(n)
data n1,n2,d1,d2,df,zero/1,2,1.0,2.0,0.25,0.0/
ig = int(df*n)
r = (df*n) - dfloat(ig)
sum1 = zero
do 11 i=ig + n2,n-ig-n1
sum1 = sum1 + xdata(i)
11 continue
sum3 = (d1-r)*(xdata(ig+n1) + xdata(n-ig))
xmid = (d1/(dfloat(n)*(d1-(d2*df))))*(sum3+sum1)
return
end
c
c Subroutine for the computation of mean velocity,
c velocity dispersion and r200 (in Mpc, h=0.7)
c
subroutine kine(d,v,n,va,sv,rv,eva,esv,jack)
implicit real*8 (a-h,o-z)
implicit integer*4 (i-n)
parameter (cl=2.99792458e5)
dimension d(n),v(n),x(25000),y(25000),ww(25000)
c
c Assume velocities are rest-frame (cosmologically corrected already)
c
nm=n
do j=1,n
x(j)=d(j)
y(j)=v(j)
enddo
c
c Use Gapper (ibwt=0; set ibwt=1 for biweight)
c
ibwt=0
call robusti(y,nm,ibwt,ave,sig)
va=va+ave
sv=sig
c
c Jacknife error estimate, if requested
c
if (jack.gt.0.5) then
rn=float(nm)
n1=nm-1
rn1=float(n1)
zall=sv*rn
zstar=0.0
zstar2=0.0
do k=1,nm
l=0
do j=1,nm
if (j.ne.k) then
l=l+1
ww(l)=y(j)
endif
enddo
call robusti(ww,n1,ibwt,avej,sigj)
xstar=xstar+xall-rn1*avej
zstar=zstar+zall-rn1*sigj
zstar2=zstar2+(zall-rn1*sigj)*(zall-rn1*sigj)
enddo
sstarz=(zstar2-zstar*zstar/rn)/(rn*rn1)
dof=float(nm-1)
tprob=.68
print *,' jack = 0 is unavailable'
stop
esv=sqrt(sstarz)*t68
eva=t68*sv/sqrt(rn)
else
eva=0.
esv=0.
endif
return
end
c
c
subroutine robusti(xin,n,ibwt,c,s)
C Routine that uses robust techniques to estimate the central location C
C and the spread S, for a distribution of N sorted values X.
C Based on the work of Beers, Flynn and Gebhardt, AJ 100, 32, 1990.
C When necessary, use is made of Numerical Recipes routines.
implicit real*8 (a-h,o-z)
implicit integer*4 (i-n)
parameter (pi=3.1415926535897932,nmax=20000)
dimension xin(n),x(nmax),xred(nmax)
data t1,t2 /6.0,9.0/
C Reset output variables
c=0.0
s=0.0
C Copy input data into work array
do i=1,n
x(i)=xin(i)
c=c+xin(i)
end do
c=c/float(n)
C If N<3 calculation of spread is impossible
if (n.lt.3) return
C Calculate the median M, given the sorted distribution of X
call sortp(x,n)
n2=n/2
if(2*n2.eq.n)then
xm=0.5*(x(n2)+x(n2+1))
else
xm=x(n2+1)
endif
C Calculate the Median Absolute Deviation
do i=1,n
xred(i)=abs(x(i)-xm)
end do
call sortp(xred,n)
n2=n/2
if(2*n2.eq.n)then
xmad=0.5*(xred(n2)+xred(n2+1))
else
xmad=xred(n2+1)
endif
if (xmad.eq.0.0) then
write(*,*) 'robust: no differentiation in data!'
return
end if
C Calculate the biweight location estimator
fact=1.0/(t1*xmad)
sum1=0.0
sum2=0.0
do i=1,n
u=(x(i)-xm)*fact
if (abs(u).lt.1.0) then
uhlp=(1.0-u**2)**2
sum2=sum2+uhlp
sum1=sum1+(x(i)-xm)*uhlp
end if
end do
cbi=xm+sum1/sum2
c=cbi
C Calculate the biweight scale if requested
if (ibwt.gt.0.5) then
fact=1.0/(t2*xmad)
sum1=0.0
sum2=0.0
do i=1,n
u=(x(i)-xm)*fact
if (abs(u).lt.1.0) then
uhlp1=1.0-u**2
uhlp2=uhlp1**4
uhlp3=1.0-5.0*u**2
sum1=sum1+(x(i)-xm)**2*uhlp2