Silverfrost Forums

Welcome to our forums

Writing multiput files

4 May 2010 2:24 #6349

The following program I wrote to calculate mean velocity value of 104 files and write all the average values in one single file.

PROGRAM velo
IMPLICIT NONE

INTEGER::n,seqnum,ierr
!DOUBLE PRECISION::avg
DOUBLE PRECISION,DIMENSION(1048576)::vdata
DOUBLE PRECISION::avg
!vdata = velocity data, nvdata = normalized velocity data
CHARACTER (LEN=12)::seqfilein

n = 1048576									
ierr = 0														
seqfilein = 'caseXXXX.txt'					

DO seqnum = 1,104						
WRITE(seqfilein(5:8),'(I4.4)') seqnum		
WRITE(*,*) seqfilein 
OPEN (UNIT=10,FILE=seqfilein, STATUS='OLD', ACTION='READ', IOSTAT=ierr) 

CALL READDATA(vdata,n,seqfilein)
!CALL NORMALIZEDVDATA(vdata,n,nvdata,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=12),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
	DOUBLE PRECISION :: sum1
	INTEGER, INTENT(IN) :: n
	DOUBLE PRECISION, INTENT(IN), DIMENSION(n) :: vdata
	DOUBLE PRECISION, INTENT(OUT) :: avg
    CHARACTER(LEN=12)::seqfout   
    CHARACTER(LEN=12),INTENT(IN)::seqfileout 
	INTEGER::i, ierr
	ierr = 0
	seqfout = seqfileout(1:8)								

	sum1 = 0

	DO i = 1, n
	sum1 = sum1 + vdata(i)
	END DO

	avg = sum1/REAL(n)

OPEN (UNIT=13, FILE='mvelocity.txt', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ierr)

WRITE(13,*) 'mean velocity of ', trim(seqfout), avg

CLOSE (UNIT=13)

RETURN
END SUBROUTINE

But the program is updating the most recent value only and thereby the output file has only the last mean value instead of desired 104 values. I am confused if I have to use DO loop and how to apply it around WRITE command. Pls advise.

Many thanks!

4 May 2010 3:59 #6350
OPEN (UNIT=13, FILE='mvelocity.txt', STATUS='REPLACE', POSITION='APPEND', ACTION='WRITE', IOSTAT=ierr)) 

I tried this which is appending from the last input lines. But I am trying to replace the entire file and then put the values followed by the most recent one without deleting the old one. Any further suggestion? Many thanks!

5 May 2010 11:51 #6354

Many thanks for your kind suggestion!

Please login to reply.