PROGRAM Polar_to_Rectangular
!-----------------------------------------------------------------------
! This program accepts the polar coordinates of a point & displays
! the corresponding rectangular coordinates.  The subroutine Convert is
! used to effect the conversion.  Variables used are:
!   R_Coord, T_Coord : polar coordinates
!   X_Coord, Y_Coord : rectangular coordinates
!   Response         : user response to more-data query
!
! Input:  R_Coord, T_Coord, and Response
! Output: X_Coord and Y_Coord
!-----------------------------------------------------------------------

  IMPLICIT NONE
  REAL ::  R_Coord, T_Coord, X_Coord, Y_Coord
  CHARACTER(LEN = 1) :: Response

! Read and convert coordinates until user signals no more data

  DO
     PRINT *, "Enter polar coordinates (in radians):"
     READ *, R_Coord, T_Coord
     CALL Convert(R_Coord, T_Coord, X_Coord, Y_Coord)
     PRINT *, "Rectangular coordinates:"
     PRINT *, X_Coord, Y_Coord  
     PRINT *
     PRINT *, "More points to convert (Y or N)?"
     READ "(A)", Response
     IF (Response == 'N' .OR. Response == 'n') EXIT
  END DO

END PROGRAM Polar_to_Rectangular


! Convert --------------------------------------------------------------
! Subroutine to convert polar coordinates (R,Theta) to rectangular
! coordinates (X,Y).
! Accepts:  Polar coordinates R and Theta
! Returns:  Rectangular coordinates X and Y
!-----------------------------------------------------------------------

SUBROUTINE Convert(R, Theta, X, Y)

 REAL, INTENT(IN) ::  R, Theta 
 REAL, INTENT(OUT) :: X, Y 

 X = R * COS(Theta)
 Y = R * SIN(Theta)

END SUBROUTINE Convert
