!=======================================
PROGRAM INTERNAL_FUNCTION_DEMO
!Calculates areas of a circle and a square

   CHARACTER CFORMAT*60 !Character to hold format spec 

   PI=ACOS(-1.)
   
!The circle
   R=200
   !Based on col ref numbers below,
   CFORMAT='(     A,                 F5.1,A,            T40,G10.3)' 
   PRINT CFORMAT,'For circle, radius ',R,', area is: ',AREA('circle',R,R)
   !cols ref:      123456789012345678901234567890234567890
   
!The square
   A=100;B=100
   PRINT CFORMAT,'For square, side ',A,', area is: ',AREA('rectangle',A,B)
CONTAINS !------------------------------
   FUNCTION AREA(OBJECT,LENGTH1,LENGTH2)
      CHARACTER(*) OBJECT
      !Alternatively CHARACTER*(*) OBJECT
      !Alternatively CHARACTER OBJECT*(*)
      REAL LENGTH1, LENGTH2
      SELECT CASE(OBJECT)
      CASE('circle')
         AREA=PI*LENGTH1**2
      CASE('rectangle')
         AREA=LENGTH1*LENGTH2
      ENDSELECT
   END FUNCTION    
END PROGRAM
!=======================================

