C      Programmer: Joel Frazier
C      Course: CS 430
C      Date Due: September 13, 2007
C      Language: FORTRAN
C      Compiler used: FORCE2.08
C      Source Filename: PA2B.f
C      Executable Filename (if any) or None: PA2B.EXE
C      Professor: Elizabeth Adams


C      Purpose: The purpose of this program is to explore the FORTRAN language.

C               The program demonstrates the use of input, output, formatting, subroutines, functions, loops, etc.

C               The program also demonstrates a binary decimal converter in FORTRAN


C      Input:  The input to this program is any decimal in base 10.

C      Output: The output of this program is the base 2 decimal representation

C      Language  Information

C             variables in this program whose names begin with letters A-H, or O-Z are real

C               these variables don't need to be declared because they are by default real

C             variables in this program whose names begin with letters I-N are integers

C               these variables don't need to be declared because they are by default integers

C             = is the assignment operator

C             READ is the input statement

C             5 in READ (5,_) is the default input device

C             the numbers after 5,  in the READ statements are the labels for the related FORMAT statements

C             WRITE is the output statement

C             6 in WRITE (6,_) is the default output device

C             the numbers after  6,  in the WRITE statements are the labels for the related FORMAT statements

C             FORMAT statements are not executable and may be placed anywhere in the program

C             All WRITE statements should have a 1X as the first element in the format list

C             The F format indicates a real number is to be output.

C             The I format indicates a integer number is to be output.

C             The 1st number after the F in the FORMAT statement indicates the 10 width of the variable

C             The 2nd number after the F in the FORMAT statement indicates numer of places after the decimal point

C             The CALL statement followed by the name of a subroutine executes the subprogram

C             DO 10 M = 1,5 is a loop statement.

C             The 10 after DO is the label, the M is an integer index, and the 1,5 is the range of indeces

C             The DO statement executes its contents until it reaches the CONTINUE statement at the label

C             At this point the loop increments the integer M and executes its contents again

C             It continues this execution until the integer exceeds the range

C             The F statement (IF (X) .GE. 1.0 GOTO 20) Evaluates X and if x is greater than 1.0 it goes to line 20

C             Otherwise, the Conditional goes to the line below it

C             The STOP statement ends the program execution

C             The END statement marks the end of a compilation unit

C      Read in the user input
       READ(5,9) T
  9    FORMAT(1F5.5)
       WRITE(6,11) T
  11   FORMAT(1X, 'The Base 10 Value Of The Input is: ',F5.5)
       S = 0
       P = 0

C      This loop cycles through each power of 2 and divides by the input to find the binary digits
       DO 10 M = -6,-1,1
          P = 2**M
          WRITE(6,25) P
  25      FORMAT(1X, D1.5)
          S = T / P
          IF (S .GE. 1.0) GOTO 15
             WRITE(6,20) '0'
             GOTO 10
  20   FORMAT(1X,A1)
  15   WRITE(6,20) '1'
  
C      Finally if the digit is a 1, subtract the current power of 2 from the input and loop again
       T = T - P
  10   CONTINUE
       STOP
       END
