I'm new to Fortran95 and I've got the following task:
I've got
N
files with research data named as:file0001.asc, file0002.asc, ..., fileN.asc
. Each of these files containsI x J
numbers (equal for all files) and what I need to do is write a new file (let's name itoutput.asc
) withI x J
numbers each of them being the mean (average) value of the same element ofN
files. For example element:
output(1,3) = sum(file0001(1,3),file0002(1,3),...,fileN(1.3)) / N
The whole process needs to be pretty automated, so the program should count the number of files N
in the folder and also the dimension of the elements of the files I x J
because I will need to do it for many different sets of data.
EDIT:
So far I've written some (pseudo) code, looking like this:
PROGRAM MultiTableMeanValue
DIMENSION out(?,?) !need to find this dimension somehow
OPEN(4,file='output.asc',form='formatted')
10 FORMAT('iso',i3.3,'.dat')
!I create the matrix to sum up the values of the output matrix in every loop
DO i=1,? ! (Where “?” is the number of rows and columns which is need to find somehow
DO j=1,? ! since I can’t do it manually cause they are like 1000+).
S(I,j)=0
ENDDO
ENDDO
READ*, N !N is the number of files
DO i=001,N !somehow need its format to be 001,002 cuz N is around 400-900,
!so I’ll need ‘10 FORMAT’ above
OPEN(5,file='file',N,'.asc') !My files are file001,file002,…,fileN and
!I need to open each one of these in every loop.
!Write their numbers in “out” matrix
!then SUM with each of the other files in every
!loop and then divide by N.
DO j=1,? ! (Where “?” is again the unknown number of rows and columns
DO k=1,?
READ(5,*) out(j,k)
S(j,k)=S(j,k)+out(j,k)
END DO
END DO
END DO
DO i=1,?
DO i=1,?
S(i,j)=S(i,j)/N
WRITE(4,*) S(i,j)
ENDDO
ENDDO
CLOSE(4)
CLOSE(5)
END PROGRAM MultiTableMeanValue
Question:
How can I expand this initial idea to complete my task?