C       PROGRAMMER: DAVID DAVIS
C       COURSE: CS430 - PROGRAMMING LANGUAGES
C       DATE DUE: WEDNESDAY, SEPTEMBER 13, 2007
C       LANGUAGE: FORTRAN 77
C       COMPILER USED: FORCE 2.0
C       SOURCE FILENAME: FORTRANPROG2.F
C       EXECUTABLE FILENAME (IF ANY) OR NONE: FORTRANPROG2.EXE
C       PROFESSOR: E. ADAMS

C       DESCRIPTION OF THE PROGRAM'S PURPOSE:
C           THE PURPOSE OF THIS PROGRAM IS TO READ IN A BASE 10 INTEGER
C           AND CONVERT IT TO BASE 2 AND OUTPUT BOTH NUMBERS. THE
C           PROGRAM MUST ALSO READ IN A DECIMAL NUMBER IN BASE 10
C           CONVERT IT, AND OUTPUT THE CORRESPONDING VALUE IN BASE 2.

C       DESCRIPTION OF PROGRAM'S REQUIRED INPUT:
C           THE FIRST INPUT CONSISTS OF AN INTEGER BETWEEN 1 AND 32767
C           IN BASE 10. THE SEOOND INPUT REQUIRED FROM THE USER IS
C           A DECIMAL/FRACTION IN BASE 10.

C       DESCRIPTION OF PROGRAM'S EXPECTED OUTPUT:
C           THE OUTPUT CONSISTS OF THE ORIGINAL BASE 10 INTEGER INPUT
C           AS WELL AS THE CORRESPONDING VALUE IN BASE 2. ALSO, THE
C           OUPUT CONSISTS OF A BASE 10 DECIMAL/FRACTION ENTERED BY THE
C           USER AS WELL AS ITS CORRESPONDING VALUE IN BASE 2. ALL
C           REQUESTED INPUT IS LABELED VIA PROMPTS. ALL DATA OUPUT IS
C           LABELED AS WELL.

C       DESCRIPTIONS OF ANY MODIFICATIONS MADE IN DEBUGGING THE PROGRAM:
C           NONE

C       GENERAL COMMENTS ABOUT THE PROGRAM:
C           THE PROGRAM USES A DO LOOP TO DETERMINE THE VALUE OF THE
C           BASE 10 INTEGER IN BASE 2. THIS DO LOOP MAKES USE OF THE
C           BUILT IN FUNCTION MOD, WHICH RETURNS THE REMAINDER OF THE
C           THE VALUE INPUT BY THE USER DIVIDED BY 2.

C       GENERAL COMMENTS EXPLAINING THE SYNTAX OR FEATURES OF THE LANGUAGE:
C           NONE

C     THE FOLLOWING CODE DEFINES THE FUNCTION IWHOLE. THE IWHOLE
C     FUNCTION TAKES IN ONE PARAMETER, A REAL NUMBER I. A IS THE
C     NUMBER TO ROUND DOWN TO THE NEAREST WHOLE VALUE. THE WHOLE
C     NUBMER IS RETURNED.
      FUNCTION IWHOLE(A)
      IWHOLE = 0
      IF(A .GT. 1) THEN
      IWHOLE = 1
      ENDIF
      RETURN
      END

C     THE FOLLOWING TWO LINES DECLARE TWO SEPARATE ARRAYS OF
C     VARYING SIZE. IARRAY WILL HOLD 15 INTEGERS. JARRAY WILL
C     HOLD 6 INTEGERS.
      DIMENSION IARRAY(15)
      DIMENSION JARRAY(6)

C     PART A:

C     PROMPTS THE USERS TO ENTER AN INTEGER BETWEEN 1 AND 32767.
C     USES THE FORMAT STATEMENT 10 WHERE THE A35 REPRESENTS A STRING
C     WITH 35 CHARACTERS. THE /1X TELLS THE COMUTER TO MAKE A NEW LINE
C     AND LEAVE 1 BLANK SPACE.
      WRITE(6,10) 'Enter an integer between 1 and 32767: '
  10  FORMAT(/1X,A38,/1X)

C     READS IN THE INPUT VALUE ENTERED BY THE USER AND STORES THAT
C     VALUE IN THE VARIABLE INPUT. USES FORMAT STATEMENT 11 WHICH
C     SPECIFIES 1 INTEGER TO BE READ IN.
      READ(5,11) INPUT
  11  FORMAT(1I5)

C     LABELS THE OUTPUT FOR THE BASE 10 NUMBER ENTERED BY THE USERS.
C     USES FORMAT STATEMENT 12 WHICH SPECIFIES A STRING OF 35
C     CHARACTERS. THE /1X REPRESENTS A NEW LINE WITH 1 BLANK SPACE. THE
C     I5 TELLS THE COMPUTER TO PRINT AN INTEGER, INPUT, IN 5 SPACES.
      WRITE(6,12) 'The base 10 value of the input is: ', INPUT
  12  FORMAT(/1X,A35,I5/1X)

C     THE FOLLOWING DO LOOP FILLS AN ARRAY WITH THE DIGITS OF THE BASE
C     10 NUMBER INPUT BY THE USER WITH THE CORRESPONDING VALUE IN BASE
C     2. THE LOOP STORES THE VALUES IN REVERSE ORDER FOR THE CORRECT
C     RESULT.
      DO 13 M = 15, 1, -1
      IARRAY(M) = MOD(INPUT,2)
      INPUT = INPUT / 2
  13  CONTINUE

C     PRINTS THE VALUE OF THE BASE 10 NUMBER IN BASE 2. USES AN IMPLIED
C     DO LOOP TO PRINT THE VALUES STORED IN IARRAY. USES FORMAT
C     STATEMENT 14 WHERE THE 1X IS TO PRINT A BLANK SPACE, THE A34 IS
C     USED TO PRINT A STRING OF 34 CHARACTEFS, THE 15 IS THE NUMBER OF
C     DIGITS TO PRINT. THE I1 IS TO PRINT AN INTEGER.
      WRITE(6,14) 'The base 2 value of the input is: ',(IARRAY(I),
     C    I = 1,15)
  14  FORMAT(1X,A34,15(I1))


C     PART B:

C     PROMPTS THE USERS TO ENTER A DECIMAL NUMBER OR FRACTION.
C     USES THE FORMAT STATEMENT 10 DESCRIBED ABOVE.
      WRITE(6,21) 'Enter a decimal number to convert: '
  21  FORMAT(/1X,A34,/1X)
  
C     READS IN THE INPUT VALUE ENTERED BY THE USER AND STORES THAT
C     VALUE IN THE VARIABLE FINPUT. USES FORMAT STATEMENT 15 WHICH
C     SPECIFIES 1 DECIMAL VALUE TO BE READ IN WITH ALL DIGITS AFTER
C     THE DECIMAL.
      READ(5,15) FINPUT
  15  FORMAT(F7.6)

C     LABELS THE OUTPUT FOR THE BASE 10 DECIMAL ENTERED BY THE USERS.
C     USES FORMAT STATEMENT 16 WHICH SPECIFIES A STRING OF 35
C     CHARACTERS. THE /1X REPRESENTS A NEW LINE WITH 1 BLANK SPACE. THE
C     F7.6 SPECIFIES A REAL NUMBER WITH 6 DIGITS AFTER THE DECIMAL.
      WRITE(6,16) 'The base 10 value of the input is: ', FINPUT
  16  FORMAT(/1X,A35,F7.6/1X)

C     THE FOLLOWING DO LOOP FILLS JARRAY WITH ALL ZEROS.
      DO 17 M = 1, 6
         JARRAY(M) = 0
  17  CONTINUE

C     THE FOLLOWING DO LOOP DETERMINES THE BASE 2 VALUE OF THE BASE 10
C     DECIMAL ENTERED BY THE USER. CALLS THE IWHOLE FUNCTION TO STORE
C     THE CORRECT VALUE IN THE ARRAY. USES A GOTO STATEMENT TO EXIT
C     DO LOOP ONCE THE BASE 2 NUMBER HAS TERMINATED.
      DO 18 M = 6, 1, -1
         FINPUT = FINPUT * 2
         IF (FINPUT .NE. 1) THEN
           JARRAY(M) = IWHOLE(FINPUT)
         END IF
         IF (FINPUT .EQ. 1) THEN
           JARRAY(M) = 1
           GOTO 19
         END IF
  18  CONTINUE

C     PRINTS THE VALUE OF THE BASE 10 DECIMAL IN BASE 2. USES AN IMPLIED
C     DO LOOP TO PRINT THE VALUES STORED IN IARRAY. USES FORMAT
C     STATEMENT 20 WHERE THE 1X IS TO PRINT A BLANK SPACE, THE A36 IS
C     USED TO PRINT A STRING OF 34 CHARACTERS, THE 6 IS THE NUMBER OF
C     DIGITS TO PRINT. THE I1 IS TO PRINT AN INTEGER.
  19  WRITE(6,20) 'The base 2 value of the input is: .',(JARRAY(I),
     C    I = 6,1,-1)
  20  FORMAT(1X,A36,6(I1))

C     STOPS EXECUTION OF PROGRAM.
      STOP
      END
