Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1: Input data has lines organized as follows: column 1: character code (

ID: 3731267 • Letter: P

Question

Problem 1: Input data has lines organized as follows: column 1: character code (one of A, B, C, D) columns 2-3: integer (named m) columns 4-8: real value (named r) Write a FORTRAN 90 program which reads this data from the keyboard (use the Unix redirect with the data file) A sum is found for each code For code A sum " +r For code B sum (m2 + r2) For code C sum sin(mr) + cos(mr) Ignore code D if it occurs Additionally print neatly formatted output of the data read in. Provide test results for the data file 0.5 A 342.44 A-320.16 C-223.99 D 039.86 C 129.69 B-249.06 D 029.90 C 041.57 C-238.37 B-136.53 Problem2 Repeat Problem 1, but now use FORTRAN funictions to do the calculations for the values to sum AND read the data from the data file named data.dat Provide test results for the data file given above. NOTES: In addition to the above requirements, also satisfy the following: 1. Whenever you write a program that gets interactive input from the user running the program, your program must prompt the user (with the appropriate print statement asking for the required input) just before the related read statement. 2. Include IMPLICIT NONE in all your programs 3. The first line of your 190 source file must be a comment which includes your name 4. The first line of output from your program must include your name

Explanation / Answer

Answer:

------------------------------------------

PROGRAM TEST_SUM
   CHARACTER code
   INTEGER m
   REAL r
   REAL sum_code
   INTEGER num
   CHARACTER (LEN=10) file_name
   num = 1
   file_name = "data.dat"
   open(unit=num,file=file_name)
   read(num,*)code,m,r
   CALL CALC(code,m,r,sum_code)
   CALL OUTPUT(code,sum_code)
END

SUBROUTINE CALC(code,m,r,sum_code)
   CHARACTER code
   INTEGER m
   REAL r
   REAL sum_code
   SELECT CASE(code)
       CASE('A')
           sum_code = r**m + r**(-1*m)
       CASE('B')
           sum_code = (m**2 + r**2)**0.5
       CASE('C')
           sum_code = SIN(m*r) + COS(m*r)
       CASE('D')
           sum_code = 0
   END SELECT
   RETURN
END

SUBROUTINE OUTPUT(code,sum_code)
   CHARACTER code
   REAL sum_code
   PRINT *,'Code:',code
   PRINT *,'Sum:',sum_code
   RETURN
END

-------------------------------------------