Hello all,
Here is my program which is taking multiple input files and producing same number of output files. For example, I have 50 input files, the program is calculating the mean of the data the input file has and giving me 50 output files. This is the code,
PROGRAM test
IMPLICIT NONE
INTEGER::n,seqnum,ierr
DOUBLE PRECISION::avg
DOUBLE PRECISION,DIMENSION(1048576)::vdata
CHARACTER (LEN=11)::seqfilein
n = 1048576
ierr = 0
seqfilein = 'caseXXX.txt'
DO seqnum = 1,50
WRITE(seqfilein(5:7),'(I3.3)') seqnum
WRITE(*,*) seqfilein
OPEN (UNIT=10,FILE=seqfilein, STATUS='OLD', ACTION='READ', IOSTAT=ierr)
CALL READDATA(vdata,n,seqfilein)
CALL MEAN(vdata,avg,n,seqfilein)
ENDDO
STOP
END
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SUBROUTINE READDATA(y,n,seqfname)
IMPLICIT NONE
INTEGER::i,ierr
REAL::xdummy
INTEGER,INTENT(IN)::n
DOUBLE PRECISION,INTENT(OUT),DIMENSION(n)::y
CHARACTER(LEN=11),INTENT(IN)::seqfname
ierr = 0
OPEN (UNIT=3, FILE=seqfname, STATUS='OLD', ACTION='READ', IOSTAT=ierr)
DO i = 1, n
READ (3,*,IOSTAT=ierr) xdummy, y(i)
END DO
CLOSE (UNIT = 3)
RETURN
END SUBROUTINE
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
SUBROUTINE MEAN(vdata,avg,n,seqfileout)
IMPLICIT NONE
INTEGER :: i, ierr
DOUBLE PRECISION :: sum1
INTEGER, INTENT(IN) :: n
DOUBLE PRECISION, INTENT(IN), DIMENSION(n) :: vdata
DOUBLE PRECISION, INTENT(OUT) :: avg
CHARACTER(LEN=11),INTENT(IN)::seqfileout
CHARACTER (LEN=11)::seqfout
ierr = 0
seqfout = seqfileout(1:7)
sum1 = 0
DO i = 1, n
sum1 = sum1 + vdata(i)
END DO
avg = sum1/REAL(n)
OPEN (UNIT=9, FILE=trim(seqfout)//'.avg', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ierr)
WRITE(9,'(F5.2)') avg
CLOSE (UNIT = 9)
RETURN
END SUBROUTINE
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Since the mean is a single value, it is rather not efficient to open 50 files to get 50 mean values. I have been trying to group the output files. That is, my program will calculate first 10 mean values and put them in one file, then another 10 values in another file and thus I would get only 5 files rather than 50 files. (I hope I could explain about what I am trying to do).
Not sure how to proceed. Any suggestion would be appreciated.
Many thanks!