|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
pban92
Joined: 23 Nov 2009 Posts: 38
|
Posted: Tue May 04, 2010 3:24 pm Post subject: Writing multiput files |
|
|
The following program I wrote to calculate mean velocity value of 104 files and write all the average values in one single file.
Code: | 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! |
|
Back to top |
|
|
brucebowler Guest
|
Posted: Tue May 04, 2010 4:07 pm Post subject: |
|
|
Quote: | OPEN (UNIT=13, FILE='mvelocity.txt', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ierr) |
You might want to replace the word 'REPLACE' with 'APPEND' (note - non-standard extension) otherwise each time you open the file you (in effect) delete the old one and create a new one. |
|
Back to top |
|
|
pban92
Joined: 23 Nov 2009 Posts: 38
|
Posted: Tue May 04, 2010 4:59 pm Post subject: |
|
|
Code: | 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! |
|
Back to top |
|
|
brucebowler Guest
|
Posted: Tue May 04, 2010 8:46 pm Post subject: |
|
|
In that case, there are 2 options (probably more but these spring to mind immediately)
1) Do as I suggested in my first answer, and (manually) delete the file before you start running the program
2) take the open and close out of the subroutine and move them to the main program. Put the OPEN before the do loop and the close after the do loop |
|
Back to top |
|
|
pban92
Joined: 23 Nov 2009 Posts: 38
|
Posted: Wed May 05, 2010 12:51 pm Post subject: |
|
|
Many thanks for your kind suggestion! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|