forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to code for processing multiple external data files?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato
View previous topic :: View next topic  
Author Message
pban92



Joined: 23 Nov 2009
Posts: 38

PostPosted: Wed Feb 03, 2010 3:51 pm    Post subject: How to code for processing multiple external data files? Reply with quote

Hi,

I have a small program to comupte the sum from an external data file. The code is as follows,
Code:

!Program to read in the data FROM a file, sum and write out TO a file.

PROGRAM solution9
IMPLICIT NONE
INTEGER :: n
REAL :: sum
REAL, DIMENSION(40) :: filename
n = 40

CALL READFILE(filename,n)
CALL SUMDATA(filename,sum,n)
CALL WRITEDATA(sum)

CLOSE(UNIT = 3)
CLOSE(UNIT = 7)

STOP
END PROGRAM

!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SUBROUTINE READFILE(x,rep)
IMPLICIT NONE
INTEGER :: i,  ierr
INTEGER, INTENT(IN) :: rep
REAL, INTENT(OUT), DIMENSION(rep) :: x
ierr = 0
OPEN (UNIT=3, FILE='file1.txt', STATUS='OLD', ACTION='READ', IOSTAT=ierr) !READ from
DO i = 1, rep
READ (3,*,IOSTAT=ierr) x(i)
END DO
RETURN
END SUBROUTINE
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

SUBROUTINE SUMDATA(row,total,rep)
IMPLICIT NONE
INTEGER :: i
INTEGER, INTENT(IN) :: rep
REAL, INTENT(IN), DIMENSION(rep) :: row
REAL, INTENT(OUT) :: total
total = 0
DO i = 1, rep
total = total + row(i)
END DO
RETURN
END SUBROUTINE
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

SUBROUTINE WRITEDATA(output)
IMPLICIT NONE
INTEGER :: ierr
REAL, INTENT(IN) :: output
ierr = 0
OPEN (UNIT=7, FILE='output_file1.txt', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ierr) !WRITE TO
WRITE(7,*) 'The sum of the data is ', output

RETURN
END SUBROUTINE



For multiple files like file2.txt, file3.txt and so on, rather than running the program by changing the file name separately, how can I modify the program, so multiple files can be processed at one click? Any hint/online example/book reference would be a great help!

Many many thanks in advance!

pban92
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5910
Location: Salford, UK

PostPosted: Wed Feb 03, 2010 4:43 pm    Post subject: Reply with quote

Is this question different from the one you raised in http://forums.silverfrost.com/viewtopic.php?t=1516
Back to top
View user's profile Send private message
pban92



Joined: 23 Nov 2009
Posts: 38

PostPosted: Wed Feb 03, 2010 5:57 pm    Post subject: Reply with quote

Thanks a lot. My bad I completely forgot about this post. Cheers!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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