! Copyright 1999 Stanford University
!All rights reserved
!
!<
!radial_mod
!
!Usage:
!call radial_mod (arg1, arg2 arg3)
!
!Input Parameters:
!
!
!Output Parameters:
!
!
!
!Description:
!
!
!
!>
!-------------------------------------------------
!
!Author: Robert Clapp, ESMB 463, 7230253
!
!Date Created:Mon Apr 12 14:52:32 PDT 1999
!
!Purpose:
!
!
module radial_mod 
  implicit none
  contains
  subroutine find_p(npts,o,d,j,p,angle,limit)
    integer       ::  n(2),i1,i2,i,j(2)
    integer       ::  npts(2)
    real          ::  o(2),d(2),p(:),center(2),loc(2)
    logical       ::  angle
    real          ::  limit,pi
    center=((/0.,0./)-o)/d+1.
    pi=atan(1.)
    do i2=1,npts(2)
      do  i1=1,npts(1)
        loc=j*(/i1,i2/)  !location in space
        i=i1+(i2-1)*npts(1)  !location within map
        if (abs(loc(2)-center(2))<.00000001) then
          if (loc(1)-center(1) > 0.) then
            p(i)=limit
          else
            p(i)=-limit
          end if
        else
          p(i)=(loc(1)-center(1))/(loc(2)-center(2))
          if (angle) then
            p(i)=atan(p(i))*45./pi
          end if
        end if 
        if (angle .and. p(i)>0.) then
          p(i)=90.-p(i)
        else if (angle .and. p(i)<0.) then
          p(i)=-90.-p(i)
        end if
        if (p(i)< -limit .and. p(i) <0.) then
          p(i)=-limit
        else if (p(i)> limit .and. p(i) > 0.) then
          p(i)=limit
        end if
      end do
    end do
  end subroutine 
end module 
