Module s2fil_filter_mod

module s2fil_filter_mod

        ! Uses
    use s2_types_mod
    use s2_sky_mod
    use s2_pl_mod
    use s2fil_types_mod
    use s2fil_error_mod

        ! Types
    public type s2fil_filter

        ! Variables
    integer, public, parameter :: S2FIL_FILTER_TYPE_MF = 1
    integer, public, parameter :: S2FIL_FILTER_TYPE_SAF = 2
    character (len=*), public, parameter :: S2FIL_FILTER_TYPE_STR_MF = 'mf'
    character (len=*), public, parameter :: S2FIL_FILTER_TYPE_STR_SAF = 'saf'
    integer, public, parameter :: S2FIL_FILTER_SCALE_TYPE_TMPL = 1
    integer, public, parameter :: S2FIL_FILTER_SCALE_TYPE_FILTER = 2
    character (len=*), public, parameter :: S2FIL_FILTER_SCALE_TYPE_STR_TMPL = 'tmpl'
    character (len=*), public, parameter :: S2FIL_FILTER_SCALE_TYPE_STR_FILTER = 'filter'

        ! Interfaces
    public interface s2fil_filter_init
    public interface s2fil_filter_get_scale

        ! Subroutines and functions
    private function s2fil_filter_init_data (tmpl, background, scale, filter_type, scale_type, mmax, norm_pres_dil, beam, heuristic) result (filter)
    private function s2fil_filter_init_copy (orig) result (copy)
    private function s2fil_filter_init_file (filename) result (filter)
    private subroutine s2fil_filter_comp_filter (filter, heu)
    public subroutine s2fil_filter_free (filter)
    public subroutine s2fil_filter_io_fits_write (filename, filter, comment)
    private subroutine s2fil_filter_io_fits_read (filename, filter)
    private subroutine s2fil_filter_io_fits_error_check (status, halt)
    private subroutine s2fil_filter_io_fits_exists (filename, status, exists)
    private subroutine s2fil_filter_io_fits_del (filename, status)
    public subroutine s2fil_filter_write_filter_map (filter, iscale, filename, comment)
    public function s2fil_filter_get_init (filter) result (init)
    public function s2fil_filter_get_lmax (filter) result (lmax)
    public function s2fil_filter_get_mmax (filter) result (mmax)
    public function s2fil_filter_get_nside (filter) result (nside)
    public function s2fil_filter_get_n_scale (filter) result (n_scale)
    public function s2fil_filter_get_norm_pres_dil (filter) result (norm_pres_dil)
    public function s2fil_filter_get_filter_type (filter) result (filter_type)
    public function s2fil_filter_get_scale_type (filter) result (scale_type)
    public function s2fil_filter_get_background (filter) result (background)
    public function s2fil_filter_get_beam (filter) result (beam)
    public function s2fil_filter_get_tmpl (filter) result (tmpl)
    private subroutine s2fil_filter_get_scale_array (filter, scale)
    private subroutine s2fil_filter_get_scale_val (filter, iscale, one_scale)
    public function s2fil_filter_get_sky (filter, iscale) result (sky)
    public function s2fil_filter_get_sky_status (filter) result (sky_status)
    public function s2fil_filter_get_filter_cl (filter, iscale) result (filter_cl)
    public function s2fil_filter_get_tmpl_cl (filter, iscale) result (tmpl_cl)

end module s2fil_filter_mod
Functionality to compute (and store) optimal filters from a background noise process and template function defined on the sky. Both spherical directional matched filters and scale adaptive filters may be constructed. Filters at various scales may be constrcuted either by dilating the original template (`correct' approach) or by dilating the first computed optimal filter.

Notes:

Author: J. D. McEwen (mcewen@mrao.cam.ac.uk)

Version: 0.1 January 2005


Description of Types

s2fil_filter

public type s2fil_filter
    private
    logical :: init = .false.
    integer :: lmax = 0
    integer :: mmax = 0
    integer :: n_scale = 0
    logical :: norm_pres_dil = S2FIL_NORM_PRES_DIL_DEFAULT
    integer :: filter_type = S2FIL_FILTER_TYPE_MF
    integer :: scale_type = S2FIL_FILTER_SCALE_TYPE_TMPL
    type (s2_pl) :: background
    type (s2_pl) :: beam
    type (s2_sky) :: tmpl
    real (kind=s2_sp), allocatable, dimension (:,:) :: scale
    type (s2_sky), allocatable, dimension (:) :: sky
    logical :: sky_status = .false.
    logical :: beam_status = .false.
end type s2fil_filter

Description of Variables

S2FIL_FILTER_TYPE_MF

integer, public, parameter :: S2FIL_FILTER_TYPE_MF = 1
Filter type: Matched filter.

S2FIL_FILTER_TYPE_SAF

integer, public, parameter :: S2FIL_FILTER_TYPE_SAF = 2
Filter type: Scale adaptive filter.

S2FIL_FILTER_TYPE_STR_MF

character (len=*), public, parameter :: S2FIL_FILTER_TYPE_STR_MF = 'mf'
Matched filter string description.

S2FIL_FILTER_TYPE_STR_SAF

character (len=*), public, parameter :: S2FIL_FILTER_TYPE_STR_SAF = 'saf'
Scale adaptive filter string description.

S2FIL_FILTER_SCALE_TYPE_TMPL

integer, public, parameter :: S2FIL_FILTER_SCALE_TYPE_TMPL = 1
Scale type: Scale template before

S2FIL_FILTER_SCALE_TYPE_FILTER

integer, public, parameter :: S2FIL_FILTER_SCALE_TYPE_FILTER = 2
Scale type: Scale filter

S2FIL_FILTER_SCALE_TYPE_STR_TMPL

character (len=*), public, parameter :: S2FIL_FILTER_SCALE_TYPE_STR_TMPL = 'tmpl'
Scale type template string description.

S2FIL_FILTER_SCALE_TYPE_STR_FILTER

character (len=*), public, parameter :: S2FIL_FILTER_SCALE_TYPE_STR_FILTER = 'filter'
Scale type filter string description.

Description of Interfaces

s2fil_filter_init

public interface s2fil_filter_init
    module procedure s2fil_filter_init_data
    module procedure s2fil_filter_init_copy
    module procedure s2fil_filter_init_file
end interface s2fil_filter_init

s2fil_filter_get_scale

public interface s2fil_filter_get_scale
    module procedure s2fil_filter_get_scale_array
    module procedure s2fil_filter_get_scale_val
end interface s2fil_filter_get_scale

Description of Subroutines and Functions

s2fil_filter_init_data

private function s2fil_filter_init_data (tmpl, background, scale, filter_type, scale_type, mmax, norm_pres_dil, beam, heuristic) result (filter)
    type (s2_sky), intent(in) :: tmpl
    type (s2_pl), intent(in) :: background
    real (kind=s2_sp), intent(in), dimension (:,:) :: scale
    integer, intent(in) :: filter_type
    integer, intent(in) :: scale_type
    integer, optional, intent(in) :: mmax
    logical, optional, intent(in) :: norm_pres_dil
    type (s2_pl), optional, intent(in) :: beam
    logical, optional, intent(in) :: heuristic
    type (s2fil_filter) :: filter
    ! Calls: s2_sky_set_lmax, s2fil_error, s2fil_filter_comp_filter
end function s2fil_filter_init_data
Initialise a filter structure directly from data.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_init_copy

private function s2fil_filter_init_copy (orig) result (copy)
    type (s2fil_filter), intent(in) :: orig
    type (s2fil_filter) :: copy
    ! Calls: s2fil_error
end function s2fil_filter_init_copy
Initialise a filter structure as a copy of another filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_init_file

private function s2fil_filter_init_file (filename) result (filter)
    character (len=*), intent(in) :: filename
    type (s2fil_filter) :: filter
    ! Calls: s2fil_error, s2fil_filter_io_fits_read
end function s2fil_filter_init_file
Initialise a filter structure from a filter file.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_comp_filter

private subroutine s2fil_filter_comp_filter (filter, heu)
    type (s2fil_filter), intent(inout) :: filter
    logical, optional, intent(in) :: heu
    ! Calls: s2_pl_free, s2_pl_get_spec, s2_sky_compute_alm, s2_sky_compute_map, s2_sky_conv, s2_sky_dilate, s2_sky_free, s2_sky_get_alm, s2fil_error
end subroutine s2fil_filter_comp_filter
Compute the filter structure filter variable. Space for the filters is allocated here.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_free

public subroutine s2fil_filter_free (filter)
    type (s2fil_filter), intent(inout) :: filter
    ! Calls: s2_pl_free, s2_sky_free, s2fil_error
end subroutine s2fil_filter_free
Free all data associated with an initialised filter and reset all other attributes.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_io_fits_write

public subroutine s2fil_filter_io_fits_write (filename, filter, comment)
    character (len=*), intent(in) :: filename
    type (s2fil_filter), intent(in) :: filter
    character (len=*), optional, intent(in) :: comment
    ! Calls: ftclos, ftfiou, ftgiou, ftibin, ftinit, ftpcle, ftpcom, ftpdat, ftphpr, ftpkyj, ftpkyl, ftpkys, s2_pl_io_fits_write, s2_sky_io_fits_write, s2fil_error, s2fil_filter_io_fits_error_check, s2fil_filter_io_fits_exists
end subroutine s2fil_filter_io_fits_write
Write filter structure to a fits file.

Variables:

Author: J. D. McEwen

Version: 0.1 April 2005

s2fil_filter_io_fits_read

private subroutine s2fil_filter_io_fits_read (filename, filter)
    character (len=*), intent(in) :: filename
    type (s2fil_filter), intent(out) :: filter
    ! Calls: ftclos, ftfiou, ftgcve, ftgiou, ftgkyj, ftgkyl, ftgkys, ftmahd, ftopen, ftthdu, s2fil_error, s2fil_filter_io_fits_error_check, s2fil_filter_io_fits_exists
end subroutine s2fil_filter_io_fits_read
Read a s2fil_filter file and all associated child files (i.e. template, background and skies).

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 - April 2005

s2fil_filter_io_fits_error_check

private subroutine s2fil_filter_io_fits_error_check (status, halt)
    integer, intent(inout) :: status
    logical, intent(in) :: halt
    ! Calls: ftgerr, ftgmsg
end subroutine s2fil_filter_io_fits_error_check
Check if a fits error has occured and print error message. Halt program execution if halt flag is set.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 - November 2004

s2fil_filter_io_fits_exists

private subroutine s2fil_filter_io_fits_exists (filename, status, exists)
    character (len=*), intent(in) :: filename
    integer, intent(inout) :: status
    logical, intent(out) :: exists
    ! Calls: ftclos, ftfiou, ftgiou, ftopen, s2fil_filter_io_fits_error_check
end subroutine s2fil_filter_io_fits_exists
Check if a fits file exists.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 - November 2004

s2fil_filter_io_fits_del

private subroutine s2fil_filter_io_fits_del (filename, status)
    character (len=*), intent(in) :: filename
    integer, intent(inout) :: status
    ! Calls: ftcmsg, ftdelt, ftfiou, ftgiou, ftopen
end subroutine s2fil_filter_io_fits_del
Delete a fits file.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 - November 2004

s2fil_filter_write_filter_map

public subroutine s2fil_filter_write_filter_map (filter, iscale, filename, comment)
    type (s2fil_filter), intent(inout) :: filter
    integer, intent(in) :: iscale
    character (len=*), intent(in) :: filename
    character (len=*), optional, intent(in) :: comment
    ! Calls: s2_sky_compute_map, s2_sky_write_map_file, s2fil_error
end subroutine s2fil_filter_write_filter_map
Write a fits sky file for the filter at a specified scale.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_init

public function s2fil_filter_get_init (filter) result (init)
    type (s2fil_filter), intent(in) :: filter
    logical :: init
end function s2fil_filter_get_init
Get init variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_lmax

public function s2fil_filter_get_lmax (filter) result (lmax)
    type (s2fil_filter), intent(in) :: filter
    integer :: lmax
    ! Calls: s2fil_error
end function s2fil_filter_get_lmax
Get lmax variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_mmax

public function s2fil_filter_get_mmax (filter) result (mmax)
    type (s2fil_filter), intent(in) :: filter
    integer :: mmax
    ! Calls: s2fil_error
end function s2fil_filter_get_mmax
Get mmax variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_nside

public function s2fil_filter_get_nside (filter) result (nside)
    type (s2fil_filter), intent(in) :: filter
    integer :: nside
    ! Calls: s2fil_error
end function s2fil_filter_get_nside
Get n_scale variable from the passed filter. Note nside stored in tmpl sky.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_n_scale

public function s2fil_filter_get_n_scale (filter) result (n_scale)
    type (s2fil_filter), intent(in) :: filter
    integer :: n_scale
    ! Calls: s2fil_error
end function s2fil_filter_get_n_scale
Get n_scale variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_norm_pres_dil

public function s2fil_filter_get_norm_pres_dil (filter) result (norm_pres_dil)
    type (s2fil_filter), intent(in) :: filter
    logical :: norm_pres_dil
    ! Calls: s2fil_error
end function s2fil_filter_get_norm_pres_dil
Get norm_pres_dil variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_filter_type

public function s2fil_filter_get_filter_type (filter) result (filter_type)
    type (s2fil_filter), intent(in) :: filter
    integer :: filter_type
    ! Calls: s2fil_error
end function s2fil_filter_get_filter_type
Get filter_type variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_scale_type

public function s2fil_filter_get_scale_type (filter) result (scale_type)
    type (s2fil_filter), intent(in) :: filter
    integer :: scale_type
    ! Calls: s2fil_error
end function s2fil_filter_get_scale_type
Get scale_type variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 March 2005

s2fil_filter_get_background

public function s2fil_filter_get_background (filter) result (background)
    type (s2fil_filter), intent(in) :: filter
    type (s2_pl) :: background
    ! Calls: s2fil_error
end function s2fil_filter_get_background
Get background variable from the passed filter.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_beam

public function s2fil_filter_get_beam (filter) result (beam)
    type (s2fil_filter), intent(in) :: filter
    type (s2_pl) :: beam
    ! Calls: s2fil_error
end function s2fil_filter_get_beam
Get beam variable from the passed filter.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_tmpl

public function s2fil_filter_get_tmpl (filter) result (tmpl)
    type (s2fil_filter), intent(in) :: filter
    type (s2_sky) :: tmpl
    ! Calls: s2fil_error
end function s2fil_filter_get_tmpl
Get tmpl variable from the passed filter.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_scale_array

private subroutine s2fil_filter_get_scale_array (filter, scale)
    type (s2fil_filter), intent(in) :: filter
    real (kind=s2_sp), intent(out), dimension (:,:) :: scale
    ! Calls: s2fil_error
end subroutine s2fil_filter_get_scale_array
Get copy of scale array from the passed filter.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_scale_val

private subroutine s2fil_filter_get_scale_val (filter, iscale, one_scale)
    type (s2fil_filter), intent(in) :: filter
    integer, intent(in) :: iscale
    real (kind=s2_sp), intent(out), dimension (:) :: one_scale
    ! Calls: s2fil_error
end subroutine s2fil_filter_get_scale_val
Get value from filter scale array corresponding to the index iscale. Note value copied is 2D array (since 2D dilation/scale).

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_sky

public function s2fil_filter_get_sky (filter, iscale) result (sky)
    type (s2fil_filter), intent(in) :: filter
    integer, intent(in) :: iscale
    type (s2_sky) :: sky
    ! Calls: s2fil_error
end function s2fil_filter_get_sky
Get filter variable(/sky) corresponding to the iscale index from the passed filter.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_sky_status

public function s2fil_filter_get_sky_status (filter) result (sky_status)
    type (s2fil_filter), intent(in) :: filter
    logical :: sky_status
    ! Calls: s2fil_error
end function s2fil_filter_get_sky_status
Get sky_status variable from the passed filter.

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_filter_cl

public function s2fil_filter_get_filter_cl (filter, iscale) result (filter_cl)
    type (s2fil_filter), intent(in) :: filter
    integer, intent(in) :: iscale
    type (s2_pl) :: filter_cl
    ! Calls: s2fil_error
end function s2fil_filter_get_filter_cl
Compute and return filter cl spectrum for the iscale index specified.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005

s2fil_filter_get_tmpl_cl

public function s2fil_filter_get_tmpl_cl (filter, iscale) result (tmpl_cl)
    type (s2fil_filter), intent(in) :: filter
    integer, intent(in) :: iscale
    type (s2_pl) :: tmpl_cl
    ! Calls: s2_sky_compute_alm, s2_sky_conv, s2_sky_dilate, s2_sky_free, s2fil_error
end function s2fil_filter_get_tmpl_cl
Compute and return tmpl cl spectrum for the dilation corresponding to the iscale index specified.

Notes:

Variables:

Author: J. D. McEwen

Version: 0.1 January 2005