-
Notifications
You must be signed in to change notification settings - Fork 11
/
SimLens.f90
139 lines (110 loc) · 4.2 KB
/
SimLens.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
!Simple program demonstrating how to generate a simulated lensed map
!AL, Feb 2004; Updated Oct 2007
program SimLensCMB
use HealpixObj
use HealpixVis
use Random
use spinalm_tools
use IniFile
use AMLUtils
implicit none
Type(HealpixInfo) :: H
Type(HealpixMap) :: M, GradPhi
Type(HealpixPower) :: P
Type(HealpixAlm) :: A
integer :: nside, lmax
integer(I_NPIX) :: npix
character(LEN=1024) :: w8name = '../Healpix_2.00/data/'
character(LEN=1024) :: file_stem, cls_file, out_file_root, cls_lensed_file
character(LEN=1024) :: healpixloc
integer, parameter :: lens_interp =1, lens_exact = 2
integer :: lens_method = lens_interp
integer :: mpi_division_method = division_equalrows
integer :: interp_method, rand_seed
logical :: err, want_pol
real :: interp_factor
integer status
#ifdef MPIPIX
integer i
call mpi_init(i)
#endif
Ini_Fail_On_Not_Found = .true.
call Ini_Open(GetParam(1), 3,err)
if (err) then
#ifdef MPIPIX
call mpi_finalize(i)
#endif
stop 'No ini'
end if
nside = Ini_Read_Int('nside')
npix = nside2npix(nside)
lmax = Ini_Read_Int('lmax')
cls_file = Ini_Read_String('cls_file')
out_file_root = Ini_Read_String('out_file_root')
lens_method = Ini_Read_Int('lens_method')
want_pol = Ini_Read_Logical('want_pol')
rand_seed = Ini_Read_Int('rand_seed')
interp_method = Ini_read_int('interp_method')
Ini_Fail_On_Not_Found = .false.
w8name = Ini_Read_String('w8dir')
interp_factor=0
if (lens_method == lens_interp) interp_factor = Ini_Read_Real('interp_factor',3.)
#ifdef MPIPIX
mpi_division_method = Ini_Read_Int('mpi_division_method',division_balanced);
#endif
call Ini_Close
file_stem = trim(out_file_root)//'_lmax'//trim(IntToStr(lmax))//'_nside'//trim(IntTOStr(nside))// &
'_interp'//trim(RealToStr(interp_factor,3))//'_method'//trim(IntToStr(interp_method))//'_'
if (want_pol) file_stem=trim(file_stem)//'pol_'
file_stem = trim(file_stem)//trim(IntToStr(lens_method))
cls_lensed_file = trim(file_stem)//'.dat'
call SetIdlePriority()
if (w8name=='') then
call get_environment_variable('HEALPIX', healpixloc, status=status)
if (status==0) then
w8name = trim(healpixloc)//'/data/'
end if
end if
if (w8name=='') then
write (*,*) 'Warning: using unit weights as no w8dir found'
call HealpixInit(H,nside, lmax,.true., w8dir='', method= mpi_division_method)
else
call HealpixInit(H,nside, lmax,.true., w8dir=w8name,method=mpi_division_method)
end if
if (H%MpiID ==0) then !if we are main thread
!All but main thread stay in HealpixInit
call HealpixPower_nullify(P)
call HealpixAlm_nullify(A)
call HealpixMap_nullify(GradPhi)
call HealpixMap_nullify(M)
call HealpixPower_ReadFromTextFile(P,cls_file,lmax,pol=.true.,dolens = .true.)
!Reads in unlensed C_l text files as produced by CAMB (or CMBFAST if you aren't doing lensing)
call HealpixAlm_Sim(A, P, rand_seed,HasPhi=.true., dopol = want_pol)
call HealpixAlm2Power(A,P)
call HealpixPower_Write(P,trim(file_stem)//'_unlensed_simulated.dat')
call HealpixAlm2GradientMap(H,A, GradPhi,npix,'PHI')
if (lens_method == lens_exact) then
call HealpixExactLensedMap_GradPhi(H,A,GradPhi,M)
else if (lens_method == lens_interp) then
call HealpixInterpLensedMap_GradPhi(H,A,GradPhi, M, interp_factor, interp_method)
else
stop 'unknown lens_method'
end if
call HealpixMap2Alm(H,M, A, lmax, dopol = want_pol)
!This automatically frees previous content of A, and returns new one
call HealpixAlm2Power(A,P)
call HealpixAlm_Free(A)
!Note usually no need to free objects unless memory is short
call HealpixPower_Write(P,cls_lensed_file)
!Save map to .fits file
!call HealpixMap_Write(M, '!lensed_map.fits')
end if
#ifdef MPIPIX
call HealpixFree(H)
call mpi_finalize(i)
#endif
#ifdef DEBUG
write (*,*) 'End of program'
pause
#endif
end program SimLensCMB