I have the following codes to compute average value of 20 random data from an external file and write to another external file.
PROGRAM avgvalue
IMPLICIT NONE
INTEGER:: i,n,average, status, sum1
INTEGER, DIMENSION(20) :: x
sum1 = 0
status = 0
n = 20
OPEN (UNIT=3, FILE='file01_set01.txt', STATUS='OLD', ACTION='READ', IOSTAT=status)
OPEN (UNIT=4, FILE='result_file01_set01.txt',STATUS='REPLACE', ACTION='WRITE', IOSTAT=status)
DO i = 1, n
READ (3,*,IOSTAT=status) x(i)
END DO
DO i = 1,n
sum1 = sum1 + x(i)
END DO
average = sum1/n
WRITE (4,*) average
CLOSE(3)
CLOSE(4)
STOP
END PROGRAM
How to run the above program for multiple files with the following names,
file01_set01.txt file01_set02.txt file01_set03.txt file01_set04.txt file01_set05.txt
have been searching everywhere but with no luck. Any hint or suggestion pls?
Many thanks!