      PROGRAM ANGLE2
***********************************************************************
* Program demonstrating the use of a subroutine subprogram DEGPRN to  *
* display an angle measured in radians or degrees in degrees-minutes- *
* seconds format.  Variables used are:                                *
*     ANGLE  : angle measurement                                      *
*     RADIAN : true if radian measure, else false                     *
*     RESPON : user response to more-data question                    *
*                                                                     *
* Input:  ANGLE, RADIAN, and RESPON                                   *
* Output: Value in ANGLE in degrees-minutes-seconds format (displayed *
*         by DEGPRN)                                                  *
***********************************************************************

      REAL ANGLE
      LOGICAL RADIAN
      INTEGER RESPON

* Read and convert angles until user signals no more data

10    CONTINUE
          PRINT *, 'ENTER ANGLE AND T IF IN RADIANS, F IF NOT'
          READ *, ANGLE, RADIAN
          CALL DEGPRN(ANGLE, RADIAN)
          PRINT *
          PRINT *, 'MORE ANGLES (0 = NO, 1 = YES)'
          READ *, RESPON
      IF (RESPON .NE. 0) GO TO 10
      END

** DEGPRN *************************************************
* Subroutine to display an angular measurement ANGLE in   *
* either radians or degrees in a degrees-minutes-seconds  *
* format.  RADIAN is true or false according to whether   *
* ANGLE is given in radians or degrees.  Local            *
* identifiers used are:                                   *
*     PI     : the constant pi                            *
*     DANGLE : the degree equivalent of ANGLE             *
*     DEGS   : the number of degrees                      *
*     MINUTS : the number of minutes                      *
*     SECONS : the number of seconds                      *
* Accepts:  ANGLE and RADIAN                              *
* Output:   Value of ANGLE in degrees-minutes-seconds     *
*           format                                        *
***********************************************************

      SUBROUTINE DEGPRN(ANGLE, RADIAN)

      REAL ANGLE, PI, DANGLE
      LOGICAL RADIAN
      INTEGER DEGS, MINUTS, SECONS
      PARAMETER (PI = 3.14159)
      
* First get the degree equivalent of the angle 

      IF (RADIAN) THEN
          PRINT *, ANGLE, ' RADIANS'
          DANGLE = (180.0 / PI) * ANGLE
      ELSE
          PRINT *, ANGLE, ' DEGREES'
          DANGLE = ANGLE
      END IF   
      PRINT *, 'IS EQUIVALENT TO'

* Now determine the number of degrees, minutes, and seconds

      DEGS = INT(DANGLE)
      DANGLE = DANGLE - REAL(DEGS)
      DEGS = MOD(DEGS, 360)
      DANGLE = 60.0 * DANGLE
      MINUTS = INT(DANGLE)
      DANGLE = DANGLE - REAL(MINUTS)
      SECONS = INT(DANGLE * 60.0)
      PRINT *, DEGS, ' DEGREES,', MINUTS, ' MINUTES,',
     +         SECONS, ' SECONDS' 
   
      END

