C Programmer: Zane Kreider
C Course: Programming Languages 430
C Date Due: Midnight September 12th
C Language: Fortran
C Compiler used: Force 2.0
C Source Filename: PA2b.f
C Executable Filename (if any) or None: none
C Professor: Professor Adams

C Description of the program's PURPOSE:
C     To read in a base 10 decimal and echo it converted into binary

C Description of program's required INPUT:
C     a real in base 10 with a deicmal

C Description of program's expected OUTPUT:
C     The program will echo the input, with a label
C     Then it will print a label for the output, and then print the converted
C     Base 2 number

C Descriptions of any MODIFICATIONS made in debugging the program:
C     NONE

C General COMMENTS about the PROGRAM
C     Numbers are assumed to be positive integers without commas, spaces, or decimals
C     No error checking is performed
C     This program uses the fixed column format required by early FORTRAN

C General COMMENTS explaining the syntax or features of the LANGUAGE
C     C in column 1 for comments
C     Labels are numbers in columns 1 through 5
C     Continuation card entry in column 6 uses an upper case C
C     Variable names which begin with any letter other than I - N are by defaults, real.
C     Real variables beginning with any letter other than I - N do not have to be declared
C     When using READ statements, the first number 5 represents keyboard input
C     When using WRITE statements, the first number 6 represents screen output
C     Functions return values that must be stored
C     Subroutines change the values of the variables passed in, and do not return a value
C     Inside loops, control variables cannot be altered

C     This is the array to hold the converted binary number
      DIMENSION I(6)

C     ******Block 1******
C     Prompting for input
      WRITE (6,1) "Enter a base 10 decimal"
C     Read in input
      READ (5,2) B
C     Labels and echos the input
      WRITE (6,3) "The base 10 value of the input is: " , B

C     Block 1 format statments
   1  FORMAT (A23)
   2  FORMAT (F7.6)
   3  FORMAT (/1X, A35, F7.6)

C     ******Block 2******
C     Setting a variable for use in calling subroutine
      IVALUE = 6
C     Calling subroutine CONVERT passing array, size of array, and input
      CALL CONVERT (I,IVALUE,B)
C     Labels and writes the converted number
      WRITE (6,4) "The base 2 value of the input is: ." , I
C     signifies end of program
      WRITE (6,5) "The program has completed successfully!"

C     Block 2 format statements
   4  FORMAT (1X, A35, 6(6(I1)))
   5  FORMAT (/A39)

      STOP
      END
      
C     begining of subroutine CONVERT
      SUBROUTINE CONVERT (IARRAY, NUM, AVALUE)
C     Setting array size since it was passed
      DIMENSION IARRAY(NUM)
      
C     loop num times(6) which is the desired length of decimals
      DO 7 M = 1, NUM
C     multiply by 2 in order to doo multiplication conversion
      AVALUE = AVALUE * 2
      
C     if value is greater than 1 go to place one in appropriate array location
      IF (AVALUE.GE.1) GOTO 6
C     else appropriate array location is 0, then continue loop
      IARRAY(M) = 0
      GO TO 7
      
C     set array location to 1
   6  IARRAY(M) = 1
C     subtract 1 in order to continue conversion
      AVALUE = AVALUE -1
   7  CONTINUE

      RETURN
C     required to signify the end of the subroutine
      END
