22 use s2_sky_mod
, only: s2_sky_file_type_map, s2_sky_file_type_sky
26 use pix_tools
, only: nside2npix
28 use extension
, only: getargument, narguments
29 use paramfile_io
, only: paramfile_handle, parse_init, parse_int, &
30 parse_real, parse_double, parse_lgt, parse_string, concatnl
34 character(len=S2_STRING_LEN) :: filename_param
35 character(len=S2_STRING_LEN) :: description
36 character(len=S2_STRING_LEN) :: line
37 type(paramfile_handle
) :: handle
39 real(s2_dp),
parameter :: omega_matter_lower = 0d0
40 real(s2_dp),
parameter :: omega_matter_upper = 1d0
41 real(s2_dp),
parameter :: omega_matter_default = 0.3d0
42 real(s2_dp),
parameter :: omega_lambda_lower = 0d0
43 real(s2_dp),
parameter :: omega_lambda_upper = 1d0
44 real(s2_dp),
parameter :: omega_lambda_default = 0.6d0
45 real(s2_dp),
parameter :: h_lower = 0d0
46 real(s2_dp),
parameter :: h_upper = 10d0
47 real(s2_dp),
parameter :: h_default = 1d-2
48 real(s2_dp),
parameter :: ze_lower = 1d2
49 real(s2_dp),
parameter :: ze_upper = 1d4
50 real(s2_dp),
parameter :: ze_default = 1d3
51 real(s2_dp),
parameter :: wh_default = 1d-10
52 real(s2_sp),
parameter :: fwhm_default = 330d0
53 logical,
parameter :: rhand_default = .true.
54 logical,
parameter :: harmonic_space_default = .true.
55 logical,
parameter :: out_cl_default = .false.
56 logical,
parameter :: rescale_cl_default = .true.
57 logical,
parameter :: read_lut_default = .false.
58 integer,
parameter :: ntheta_default = 100
59 integer,
parameter :: lmax_default = 64
60 integer,
parameter :: nside_default = 128
61 character(len=*),
parameter :: file_type_map_str =
'map'
62 character(len=*),
parameter :: file_type_sky_str =
'sky'
64 character(len=S2_STRING_LEN) :: filename_out, filename_out_cl
65 character(len=S2_STRING_LEN) :: filetype_str = file_type_map_str
66 integer :: filetype = s2_sky_file_type_map
69 real(s2_sp),
allocatable :: cl(:)
70 real(s2_dp) :: omega_matter, omega_lambda, h, ze, wh
71 integer :: nside, lmax
73 real(s2_sp) :: alpha=0e0, beta=-90e0, gamma=0e0
74 logical :: rhand = .true.
75 logical :: apply_beam = .false.
76 real(s2_sp) :: fwhm = fwhm_default
77 logical :: harmonic_space
79 logical :: rotation_alm = .false.
85 character(len=S2_STRING_LEN) :: filename_lut
89 filename_out =
'sky.fits'
90 filename_out_cl =
'out_Cl.txt'
91 filename_lut =
'lut.dat'
92 omega_matter = omega_matter_default
93 omega_lambda = omega_lambda_default
100 rhand = rhand_default
102 harmonic_space = harmonic_space_default
103 ntheta = ntheta_default
105 write(*,
'(a)')
'***********************************************'
106 write(*,
'(a)')
'BIANCHI2 VII_h rotating universe CMB simulation'
107 write(*,
'(a)')
'Anthony Lasenby & Jason McEwen October 2005'
108 write(*,
'(a)')
'mcewen@mrao.cam.ac.uk '
109 write(*,
'(a)')
'***********************************************'
117 if(narguments() == 0)
then
120 if(narguments() /= 1)
then
122 comment_add=
'Usage: bianchi2_sim [input parameter filename]')
124 call getargument(1, filename_param)
126 handle = parse_init(trim(filename_param))
131 write(line,
'(a,f4.1,a,f4.1,a)')
'(In the range ', &
132 omega_matter_lower,
' <= omega_matter < ', omega_matter_upper,
')'
133 description = concatnl(
'', &
134 'Enter omega_matter: ', &
137 omega_matter = parse_double(handle,
'omega_matter', &
138 default=omega_matter_default, descr=description)
139 if(omega_matter < omega_matter_lower .or. &
140 omega_matter >= omega_matter_upper)
then
141 if(handle%interactive) goto 1
142 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
143 comment_add=
'omega_matter invalid')
147 write(line,
'(a,f4.1,a,f4.1,a)')
'(In the range ', &
148 omega_lambda_lower,
' <= omega_lambda < ', omega_lambda_upper,
')'
149 description = concatnl(
'', &
150 'Enter omega_lambda: ', &
153 omega_lambda = parse_double(handle,
'omega_lambda', &
154 default=omega_lambda_default, descr=description)
155 if(omega_lambda < omega_lambda_lower .or. &
156 omega_lambda >= omega_lambda_upper)
then
157 if(handle%interactive) goto 1
158 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
159 comment_add=
'omega_lambda invalid')
163 if((omega_matter + omega_lambda) >= 1d0)
then
164 if(handle%interactive)
then
166 write(*,
'(a)')
' * Only open models are allowed *'
169 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
170 comment_add=
'Only open models are allowed')
174 write(line,
'(a,f4.1,a,f4.1,a)')
'(In the range ', &
175 h_lower,
' <= h <= ', h_upper,
')'
176 description = concatnl(
'', &
180 h = parse_double(handle,
'h', &
181 default=h_default, descr=description)
182 if(h < h_lower .or. h > h_upper)
then
183 if(handle%interactive) goto 3
184 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
185 comment_add=
'h invalid')
190 write(line,
'(a,e9.2,a,e9.2,a)')
'(In the range ', &
191 ze_lower,
' <= zE <= ', ze_upper,
')'
192 description = concatnl(
'', &
196 ze = parse_double(handle,
'zE', &
197 default=ze_default, descr=description)
198 if(ze < ze_lower .or. ze > ze_upper)
then
199 if(handle%interactive) goto 4
200 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
201 comment_add=
'zE invalid')
206 description = concatnl(
'', &
209 wh = parse_double(handle,
'wH', &
210 default=wh_default, descr=description)
212 if(handle%interactive) goto 5
213 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
214 comment_add=
'wH invalid')
218 description = concatnl(
'', &
219 'Enter right-handedness status (logical): ')
220 rhand = parse_lgt(handle,
'rhand', &
221 default=rhand_default, descr=description)
224 description = concatnl(
'', &
225 'Enter alpha (degrees): ')
227 alpha = parse_real(handle,
'alpha', &
228 default=alpha, descr=description)
229 if(alpha < -360d0 .or. alpha > 360)
then
230 if(handle%interactive) goto 6
231 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
232 comment_add=
'alpha invalid')
234 alpha = alpha / 180e0 * pi
237 description = concatnl(
'', &
238 'Enter beta (degrees): ')
240 beta = parse_real(handle,
'beta', &
241 default=beta, descr=description)
242 if(beta < -180d0 .or. beta > 180)
then
243 if(handle%interactive) goto 7
244 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
245 comment_add=
'beta invalid')
247 beta = beta / 180e0 * pi
250 description = concatnl(
'', &
251 'Enter gamma (degrees): ')
253 gamma = parse_real(handle,
'gamma', &
254 default=gamma, descr=description)
255 if(gamma < -360d0 .or. gamma > 360)
then
256 if(handle%interactive) goto 8
257 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
258 comment_add=
'gamma invalid')
260 gamma = gamma / 180e0 * pi
263 description = concatnl(
'', &
264 'Enter apply_beam status (logical): ')
265 apply_beam = parse_lgt(handle,
'apply_beam', &
266 default=apply_beam, descr=description)
270 description = concatnl(
'', &
271 'Enter beam fwhm (arcmin): ')
273 fwhm = parse_real(handle,
'fwhm', &
274 default=fwhm_default, descr=description)
276 if(handle%interactive) goto 9
277 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
278 comment_add=
'fwhm invalid')
283 description = concatnl(
"", &
284 "Enter the maximum harmonic l (lmax) for the simulated sky: ")
286 lmax = parse_int(handle,
'lmax', &
287 default=lmax_default, descr=description)
289 if(handle%interactive) goto 10
290 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
291 comment_add=
'lmax invalid')
296 description = concatnl(
"", &
297 "Enter the resolution parameter (nside) for the simulated sky: ", &
298 "(npix = 12*nside**2, where nside must be a power of 2)")
300 nside = parse_int(handle,
'nside', &
301 default=nside_default, descr=description)
302 if(nside2npix(nside) < 0)
then
303 if(handle%interactive) goto 11
304 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
305 comment_add=
'nside invalid')
309 description = concatnl(
'', &
310 'Enter harmonic_space status (logical): ')
311 harmonic_space = parse_lgt(handle,
'harmonic_space', &
312 default=harmonic_space_default, descr=description)
313 if (harmonic_space == .true.)
then
315 description = concatnl(
"", &
316 "Enter the number of terms (Ntheta) used for the integrations: ")
318 ntheta = parse_int(handle,
'Ntheta', &
319 default=ntheta_default, descr=description)
321 if(handle%interactive) goto 12
322 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
323 comment_add=
'Ntheta invalid')
328 description = concatnl(
'', &
329 'Enter filename_out: ')
330 filename_out = parse_string(handle,
'filename_out', &
331 default=trim(filename_out), descr=description)
334 description = concatnl(
'', &
335 'Enter output file type (filetype={map; sky}): ')
337 filetype_str = parse_string(handle,
'filetype', &
338 default=trim(filetype_str), descr=description)
341 select case (filetype_str)
343 case (file_type_map_str)
344 filetype = s2_sky_file_type_map
346 case (file_type_sky_str)
347 filetype = s2_sky_file_type_sky
350 if(handle%interactive) goto 13
351 call
bianchi2_error(bianchi2_error_sim_param_invalid,
'bianchi2_sim', &
352 comment_add=
'Invalid output file type')
357 description = concatnl(
'', &
358 'Enter out_Cl (logical): ')
359 out_cl = parse_lgt(handle,
'out_Cl', &
360 default=out_cl_default, descr=description)
362 if (out_cl == .true.)
then
364 description = concatnl(
'', &
365 'Enter rescale_Cl (logical): ')
366 rescale_cl = parse_lgt(handle,
'rescale_Cl', &
367 default=rescale_cl_default, descr=description)
370 description = concatnl(
'', &
371 'Enter filename_out_Cl: ')
372 filename_out_cl = parse_string(handle,
'filename_out_Cl', &
373 default=trim(filename_out_cl), descr=description)
377 description = concatnl(
'', &
378 'Enter read_LUT (logical): ')
379 read_lut = parse_lgt(handle,
'read_LUT', &
380 default=read_lut_default, descr=description)
382 if (read_lut==.true.)
then
384 description = concatnl(
'', &
385 'Enter filename_LUT: ')
386 filename_lut = parse_string(handle,
'filename_LUT', &
387 default=trim(filename_lut), descr=description)
399 if (harmonic_space)
then
402 if (read_lut==.true.)
then
405 write(*,
'(a)')
'Computing BIANCHI2 simulation in harmonic space, using a lut...'
407 nside, lmax, ntheta, alpha, beta, gamma,lut)
410 write(*,
'(a)')
'Computing BIANCHI2 simulation in harmonic space, without using a lut...'
412 nside, lmax, ntheta, alpha, beta, gamma)
417 write(*,
'(a)')
'Simulation complete'
422 write(*,
'(a)')
'Computing BIANCHI2 simulation in real space...'
426 write(*,
'(a)')
'Simulation complete'
451 write(*,
'(a,a)')
'Simulated map written to ', trim(filename_out)
454 if (out_cl == .true.)
then
460 write(*,
'(a,a)')
'Simulated power spectrum written to ', &
461 trim(filename_out_cl)
466 write(*,
'(a)')
'Simulation parameters:'