      PROGRAM BEAM
******************************************************************
* This program calculates deflections in a cantilever beam       *
* under a given load. Three different loading conditions are     *
* analyzed:                                                      *
*   Case #1 : a single point load at the free end of the beam    *
*   Case #2 : a single point load at an interior point           *
*   Case #3 : load uniformly distributed along the beam          *
*                                                                *
* Variables used are:                                            *
*     ELAST  : modulus of elasticity                             *
*     INERT  : moment of inertia                                 *
*     LENG   : length of the beam                                *
*     NUMPTS : number of divisions at which deflections are found*
*     DELTAX : distance between points                           *
*     OPTION : option selected by the user                       *
*     LOAD   : load on the beam                                  *
*     X      : distance from the free end of the beam            *
*     A      : distances along the beam                          *
*     I      : control variable used in DO loop                  *
*     DEFLEC : deflection at distance X                          *
*     CASE1  : function to compute deflection in Case #1         *
*     CASE2  :      "    "     "        "      " Case #2         *
*     CASE3  :      "    "     "        "      " Case #3         *
*                                                                *
* Input:  ELAST, INERT, LENG, NUMPTS, OPTION, LOAD               *
* Output: A table of deflections at points along the beam        *
******************************************************************

      INTEGER NUMPTS, OPTION
      REAL ELAST, INERT, LENG, DELTAX, DEFLEC, CASE1, CASE2, CASE3,
     +     LOAD

* Get beam information

      PRINT *, 'ENTER MODULUS OF ELASTICITY, MOMENT OF INERTIA,',
     +         ' LENGTH OF THE BEAM:'
      READ *, ELAST, INERT, LENG

* Repeat the following until user selects option 0 to stop

 10   CONTINUE
         PRINT *
         PRINT *, 'SELECT ONE OF THE FOLLOWING OPTIONS:'
         PRINT *, '0 : STOP'
         PRINT *, '1 : END LOAD'
         PRINT *, '2 : INTERMEDIATE LOAD'
         PRINT *, '3 : UNIFORM LOAD'
         READ *, OPTION

         IF (OPTION .LT. 0 .OR. OPTION .GT. 3) THEN
            PRINT *, 'NOT A VALID OPTION'
         ELSE IF (OPTION .EQ. 0) THEN
            PRINT *, 'DONE PROCESSING FOR THIS BEAM'
         ELSE
            PRINT *, 'ENTER LOAD (TOTAL LOAD FOR CASES 1 AND 2, ',
     +               'UNIT LOAD FOR CASE 3): '
            READ *, LOAD
            IF (OPTION .EQ. 2) THEN
               PRINT *, 'ENTER THE DISTANCE A:'
               READ *, A
            END IF
            PRINT *, 'ENTER NUMBER OF POINTS TO USE:'   
            READ *, NUMPTS
            DELTAX = LENG / REAL(NUMPTS)

            PRINT *
            PRINT *, 'DISTANCE    DEFLECTION'
            PRINT *, '======================'

            X = 0.0
            DO 30 I = 1, NUMPTS
               IF (OPTION .EQ. 1) THEN
                  DEFLEC = CASE1(ELAST, INERT, LENG, LOAD, X)
               ELSE IF (OPTION .EQ. 2) THEN
                  DEFLEC = CASE2(ELAST, INERT, LENG, LOAD, A, X)
               ELSE
                  DEFLEC = CASE3(ELAST, INERT, LENG, LOAD, X)
               END IF

               PRINT 20, X, DEFLEC
 20            FORMAT (1X, F5.2, E16.6)

               X = X + DELTAX

 30         CONTINUE
         END IF             
      IF (OPTION .NE. 0) GO TO 10

      END


** CASE1 *********************************************************
* Computes deflections for a single point load at the free end   *
* of the beam.  Local variable used:                             *
*     TEMP   : temporary variable used in calculation of DEFLEC  * 
* Accepts: ELAST, INERT, LENG, LOAD (see main program)           *
* Returns: deflection                                            *
******************************************************************

      FUNCTION CASE1(ELAST, INERT, LENG, LOAD, X)

      REAL CASE1, ELAST, INERT, LENG, LOAD, TEMP

      TEMP = X**3 - 3.0 * LENG**2 * X + 2.0 * LENG**3
      CASE1 = (-LOAD / (6.0 * ELAST * INERT)) * TEMP

      END


**CASE2***********************************************************
* Computes deflections for a single point load at an interior    *
* point of the beam.  Local variables used:                      *
*     B:    : distance along the beam                            *
*     TEMP  : temporary variable used in calculation of DEFLEC   *
* Accepts: ELAST, INERT, LENG, LOAD, A, X (see main program)     *
* Returns: deflection                                            *
******************************************************************

      FUNCTION CASE2(ELAST, INERT, LENG,  LOAD, A, X)

      REAL CASE2, ELAST, INERT, LENG, LOAD, A, B, X, TEMP

      B = LENG - A
      IF (X .LT. B) THEN
         TEMP = -A**3 + 3.0 * A**2 * LENG - 3.0 * A**2 * X
      ELSE
         TEMP = (X - B)**3 - 3.0 * A**2 * (X - B) + 2.0 * A**3
      END IF
      CASE2 = (-LOAD / (6.0 * ELAST * INERT)) * TEMP

      END


**CASE3***********************************************************
* Computes deflections for a load uniformly distributed along    *
* the beam.  Local variables used:                               *
*     TLOAD  : total load                                        *
*     TEMP   : temporary variable used in calculation of DEFLEC  *
* Accepts: ELAST, INERT, LENG, LOAD (see main program)           *
* Returns: deflection                                            *
******************************************************************

      FUNCTION CASE3(ELAST, INERT, LENG, LOAD, X)

      REAL CASE3, ELAST, INERT, LENG, LOAD, TLOAD, TEMP

      TLOAD = LOAD * LENG
      TEMP = X**4 - 4.0 * LENG**3 * X + 3.0 * LENG**4
      CASE3 = (-TLOAD / (24.0 * ELAST * INERT * LENG)) * TEMP

      END
