C       Programmer:				Jaycelynn Goldberg
C       Course:					CS 430 Programming Languages
C       Date Due:		online		Wed Sept. 12, 2007  11:59 PM
C                               in class        Thurs Sept 13
C       Language:				FORTRAN
C       Compiler Used:				FORCE 2.0
C       Source Filename:                        PA2B.f
C       Executable Filename (if any) or *None*: NONE
C       Professor:				Elizabeth Adams

C       Description of the program's PURPOSE:
C           To read a base 10 integer from 1-32767, and convert to base 2

C       Description of program's required INPUT:
C           An integer in the range 1-32767 (in base 10)
C
C       Description of program's expected OUTPUT
C           Original input: a base 10 integer (1-32767)
C           base 2 format of the input up to 6 places.
C
C           i.e.
C           The base 10 value of the input is: (input)
C           The base 2 value of the input is: (input in binary to 6 places)

C       Description of any MODIFICATIONS made in debugging the program

C       General COMMENTS about the program
C            I used IF statements instead of a DO loop to avoid printing
C            extra 0's.  IF, THEN statements could have been used as well,
C            but we were discouraged from using them.  For the same reason,
C            a DO, WHILE loop was not used either.
C
C       General COMMENTS explaining the syntax or features of the LANGUAGE
C
C               READ(5,10,ERR=29) REAL1   reads from the standard input device
C                                    according to the format specified by
C                                    label 10.  If an error occurs while
C                                    attempting to read input, the program
C                                    will go to label 29 (ERR=29).


C       NARRAY stores the binary values, that when printed in order,
C       are the binary representation of the input.
C       i.e. input = 0.5478
C       NARRAY(1) = 1
C       NARRAY(2) = 0
C       NARRAY(3) = 0
C       NARRAY(4) = 1
C       NARRAY(5) = 0
C       NARRAY(6) = 0
C       2nd line of output would be 'The base 2 value of input is: .100100'
        DIMENSION NARRAY(6)
        
C       counter = 0; counts how many places in the array are used
        I=0

C       Get base 10 number from user/terminal, Go to label 29 If invalid input
        READ(5,10, ERR=29) REAL1
   10   FORMAT(F8.6)

        TEMP = REAL1

C       Lines 37-59 convert a decimal fraction 0-1 to a binary fraction
C       with up to 6 places

C       If TEMP does not equal 0, and the counter is less than or equal to 6
C          go to line 20 (enter loop)
C       If TEMP = 0, or counter is greater than 6, go to line 21 (exit loop)
C
   12   IF((TEMP .NE. 0.0) .AND. (I .LE. 6)) GOTO 20
        IF((TEMP .EQ. 0.0) .OR. (I. GT. 6)) GOTO  21

C       increase counter
   20      I = I + 1
           TEMP = TEMP * 2.0
           IF(TEMP .GE. 1.0) GOTO 22
           IF(TEMP .LT. 1.0) GOTO 23

C        If TEMP > 1, value in array = 1, TEMP = decimal portion
C        loop back to label 12
   22      NARRAY(I) = 1
           TEMP = TEMP - 1.0
           GOTO 12
C        value in array = 0, loop back to label 12
   23      NARRAY(I) = 0
           GOTO 12

C       print original input, and input converted to a binary fraction
   21   WRITE(6,13) REAL1
        WRITE(6,11) (NARRAY(J), J=1,I)
   13   FORMAT(1X, 'The base 10 value of the input is: ', F8.6)
   11   FORMAT(1X, 'The base 2 value of the input is: .',6(6(I1)))

C       skip error output, and end program (label 40)
        GOTO 40

   29   WRITE(6,14)
   14   FORMAT(1X, 'ERROR IN INPUT DATA')
   40   STOP
        END
        
        

