# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
!
! Sun Jan 12 21:57:03 PST 2003
!
!
!
module back_project_mod
  use basic_util_mod
  use param_check_mod
  use sep
  implicit none
  logical, private, save :: verb
  real, private, save :: beg1(50),end1(50),beg2(50),end2(50),beg3(50)&
    &,end3(50)
  real, private, save :: bege(50),ende(50),begt(50),endt(50)
  integer, private, save :: nreg
  contains
  logical function parse_valid_back_pts(datac,bca,nca,dataz,s_x,s_y,s_z&
    &,theta,rayt,extra)
    real :: datac(:,:,:),dataz(:,:,:)
    integer :: nca,bca
    logical :: kill
    integer :: i,ncn,ikill
    real :: s_z(:),s_x(:),s_y(:),theta(:),extra(:),rayt(:)
    parse_valid_back_pts=.false.
    if (nreg.eq.0) then
      parse_valid_back_pts=.true.
      return
    end if
    ncn=bca
    do i=bca,nca
      kill=.false.
      do ikill=1,nreg
        if ( s_x(i) >= beg2(ikill) .and. s_x(i) <= end2(ikill)&
          & .and.s_y(i) >= beg3(ikill) .and. s_y(i) <= end3(ikill)&
          & .and.s_z(i) >= beg1(ikill) .and. s_z(i) <= end1(ikill)&
          & .and.theta(i) >= begt(ikill) .and. theta(i) <= endt(ikill&
          &) .and.extra(i) >= bege(ikill) .and. extra(i) <= ende(ikill) ) then
          kill=.true.
        end if
      end do
      if (.not. kill .and. ncn .ne. i) then
        datac(:,:,ncn)=datac(:,:,i)
        s_x(ncn)=s_x(i)
        s_y(ncn)=s_y(i)
        s_z(ncn)=s_z(i)
        theta(ncn)=theta(i)
        extra(ncn)=extra(i)
        rayt(ncn)=rayt(i)
        ncn= ncn+1
      end if
    end do
    ncn=ncn-1
    if (ncn < bca) then
      nca=bca-1
    end if
    parse_valid_back_pts=.true.
  end function
  logical function check_pars_back_project(tag,ok)
    character(len=*) :: tag
    logical :: stat_ok(20),stat_rerun(20),ok
    integer :: i
    check_pars_back_project=.false.
    stat_ok=.true.
    stat_rerun=.true.
    beg1=default_real
    beg2=default_real
    beg3=default_real
    end1=default_real
    end2=default_real
    end3=default_real
    begt=default_real
    endt=default_real
    bege=default_real
    ende=default_real
    stat_rerun(1)= check_par_file("kill_back_beg1",beg1,tag,beg1)
    stat_rerun(2)= check_par_file("kill_back_beg2",beg2,tag,beg2)
    stat_rerun(3)= check_par_file("kill_back_beg3",beg3,tag,beg3)
    stat_rerun(4)= check_par_file("kill_back_end1",end1,tag,end1)
    stat_rerun(5)= check_par_file("kill_back_end2",end2,tag,end2)
    stat_rerun(6)= check_par_file("kill_back_end3",end3,tag,end3)
    stat_rerun(7)= check_par_file("kill_back_beg_extra",bege,tag,bege)
    stat_rerun(8)= check_par_file("kill_back_end_extra",ende,tag,ende)
    stat_rerun(9)= check_par_file("kill_back_beg_theta",begt,tag,begt)
    stat_rerun(10)= check_par_file("kill_back_end_theta",endt,tag,endt&
      &)
    nreg=1
    do while (beg1(nreg).ne.default_real .or. beg2(nreg).ne.default_real&
      & .or. bege(nreg).ne.default_real .or. ende(nreg).ne.default_real&
      & .or. begt(nreg).ne.default_real .or. endt(nreg).ne.default_real&
      & .or. beg3(nreg).ne.default_real .or. end1(nreg).ne.default_real&
      & .or. end2(nreg).ne.default_real .or. end3(nreg).ne.default_real)
      nreg= nreg+1
    end do
    nreg=nreg-1
    where(beg1.eq.default_real)
      beg1=-1000000.
end where
    where(beg2.eq.default_real)
      beg2=-1000000.
end where
    where(beg3.eq.default_real)
      beg3=-1000000.
end where
    where(end1.eq.default_real)
      end1=1000000.
end where
    where(end2.eq.default_real)
      end2=1000000.
end where
    where(end3.eq.default_real)
      end3=1000000.
end where
    where(bege.eq.default_real)
      bege=-1000000.
end where
    where(ende.eq.default_real)
      ende=1000000.
end where
    where(begt.eq.default_real)
      begt=-1000000.
end where
    where(endt.eq.default_real)
      endt=1000000.
end where
    call from_param("verb",verb,.false.)
    if (all(stat_ok)) then
      check_pars_back_project=.true.
    end if
    if (all(stat_rerun)) then
      ok=.true.
    else
      ok=.false.
    end if
  end function
end module
