C     Programmer:  Stephen Anderson
C     Course:  CS430, Section 0001
C     Date Due:  September 6, 2007
C     Language:  FORTRAN 77
C     Compiler used:  Force 2.0
C     Source Filename:  Project1.f
C     Executable Filename (if any) or None:  None
C     Professor:  Dr. Adams

C     Description of the program's PURPOSE:
C      Fills 3 individual arrays, prints, averages, and sorts
C      the arrays.

C     Description of program's required INPUT:
C      3 sets of inputs of 80 digits in length.
C      The input only can have positive inputs digits
C      Input cannot have decimals or commas.

C     Description of program's expected OUTPUT:
C      Prints off each of the values in order of each array.
C      Prints off the average value of each array.
C      Prints off the sorted values in order of each array.

C     Descriptions of any MODIFICATIONS made in debugging the program:
C      Took out a print function and just printed the values with an
C      implied do-loop.  After having some trouble with sorting,
C      I used the bubble sort algorithm.

C     General COMMENTS about the PROGRAM:
C      Inputs only have 80 positive digits.
C      No error checking is preformed
C

C     General COMMENTS explaining the syntax or features of the LANGUAGE
C      The three arrays are declared at the beginning as X, Y, Z.
C      Array X has 15 indexes and it has 5 digits with 2 decimal places
C      Array Y has 10 indexes and it has 7 digits with 3 decimal places
C      Array Z has 5 indexes and it has 10 digits with 5 decimal places

C      Letters I and J are used as indexes for the arrays.
C      The two numbers at each READ statement are 5, which is a
C      default input device and the nubmer after the 5 is the format
C      line.
C      The WRITE statements have two numbers after them.  The first is
C      is a 6 which is the default output device.  The number after the
C      6 is the format line.
C      In the FORMAT lines, the F stands for a real number and the
C      number after it stands for how many digits to expect along with
C      how many decimal places there are.  1X is a indicator for a space
C      Other FORMAT statements have an A and a number, this is for
C      String texts with how many spaces to allow for the text. (A30)
C      The program has one SUBROUTINE called SORT.  This function sorts
C      all the arrays.
C      The parameters for the SORT function are the array (A) and the
C      size of the array (datasize).
C      SORT implements the BUBBLE SORT algorithm.


       DIMENSION X(15)
       DIMENSION Y(10)
       DIMENSION Z(5)

C      Reads in the inputs and places them into the arrays
       WRITE (6,15) 'Please enter 80 digits with no decimals or spaces'
  15   FORMAT (A50)
       READ (5,23) (X(I), I = 1,15)
  23   FORMAT(15F5.2)
       WRITE (6,15) 'Please enter 80 digits with no decimals or spaces'
       READ (5,26) (Y(I), I = 1,10)
  26   FORMAT(10F6.3)
       WRITE (6,15) 'Please enter 80 digits with no decimals or spaces'
       READ (5,29) (Z(I), I = 1,5)
  29   FORMAT(5F10.5)
  
C      Prints the numbers in the array X
       WRITE (6,22) 'The numbers in array X are: '
  22   FORMAT (/1X, A28)
       WRITE (6,24) (X(I), I = 1,15)
  24   FORMAT(1X, 15(4(F6.2,1X)/1X))

C      Calculates the average of array X
       average = 0
       DO 40 I = 1,15,1
          average = average + X(I)
  40   CONTINUE
       average = average/15
       WRITE(6,41) 'The Average is of array X is: ', average
  41   FORMAT (/1X, (A30, F6.2)/1X)

C      Sorts and prints the numbers in array X
       WRITE (6,51) 'The numbers of array X after sorting are: '
   51  FORMAT (A40)
       CALL SORT (X, 15)
       WRITE (6,52) (X(I), I = 1,15)
   52  FORMAT (1X, 15(4(F6.2,1X)/1X))

   
C      Prints the numbers in array Y
       WRITE (6,25) 'The numbers in array Y are: '
  25   FORMAT (/1X/1X, A28)
       WRITE (6,27) (Y(I), I = 1,10)
  27   FORMAT(1X, 10(4(F7.3,1X)/1X))

C      Calculates the average of array Y
       DO 42 I = 1,10,1
          average = average + Y(I)
  42   CONTINUE
       average = average/10
       WRITE(6,43) 'The Average is of array Y is: ', average
  43   FORMAT (/1X, (A30, F7.3)/1X)

C      Sorts and prints the numbers in array Y
       WRITE (6,51) 'The numbers of array X after sorting are: '
       CALL SORT (Y, 10)
       WRITE (6,54) (Y(I), I = 1,10)
   54  FORMAT (1X, 10(4(F7.3,1X)/1X))

   
C      Prints the numbers in array Z
       WRITE (6,28) 'The numbers in array Z are: '
  28   FORMAT (/1X/1X, A28)
       WRITE (6,30) (Z(I), I = 1,5)
  30   FORMAT(1X, 5(4(F11.5,1X)/1X))

C      Calculates the average in array Z
       total = 0.0
       DO 44 I = 1,5,1
          total = total + Z(I)
  44   CONTINUE
       average = total/5
       WRITE(6,45) 'The Average is of array Z is: ', average
  45   FORMAT (/1X, (A30, F11.5)/1X)

C      Sorts and prints the numbers in array Z
       WRITE (6,51) 'The numbers of array Z after sorting are: '
       CALL SORT (Z, 5)
       WRITE (6,55) (Z(I), I = 1,5)
   55  FORMAT (1X, 5(4(F11.5,1X)/1X))
       STOP
       END
       
       
C      The function that sorts each array
       SUBROUTINE SORT (A, datasize)
       INTEGER datasize
       DIMENSION A(datasize)
       DO 10 I = 1,datasize,1
          DO 11 J = datasize,(I+1),-1
             if (A(J).lt.A(J-1))  then
                TEMP = A(J)
                A(J) = A(J-1)
                A(J-1) = TEMP
             endif
   11     CONTINUE
   10  CONTINUE
       RETURN
       END

       
