Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The loop that creates iterative names of files/characters? : V1,V2,V3…

Status
Not open for further replies.

lililulu

Technical User
Jun 29, 2010
2
PL
Hi,
I have a problem with a large matrix… I want to write row by row into separate files and later read them. So I need something like this (in f77):

do i=1,m
do j=1,n
row(j)=matrix(i,j)
enddo
open(1,FILE='ROW_J.txt', STATUS='NEW')
write(1,*) (row(j), j=1,n)
close(1)
enddo
**************************************
!and later
do i=1,m
open(1,FILE='ROW_J.txt', STATUS='OLD')
do j=1,n
read(1,*) row( j)
enddo
close(1)
enddo

Is it possible to do something like this?
Thanks for help :)
 
Hi lililulu

I would do this in the following way (untested program):

Code:
	Program MAT

	character*80 filename

	do i=1,m
	   write(filename,'(a,i4.4)') 'File',i
	   open(1,FILE=file(1:8),STATUS='NEW') 
	   do j=1,n
	      write(1,*) matrix(i,j)
	   enddo
	   close(1)
	enddo

! and later

	do i=1,m
	   write(filename,'(a,i4.4)') 'File',i
	   open(1,FILE=file(1:8),STATUS='OLD')
	   do j=1,n
	      read(1,*) matrix(i,j)
	   enddo
	   close(1)
	enddo

	end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top