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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP to open a file 1

Status
Not open for further replies.

Truiteto

Technical User
Nov 24, 2004
2
ES
I want to do something like

N=100
Do i=1,N
open (5, file='data'N'.txt')
enddo

but I know this is not correct

Can someone tell me how to do it?

I have been searching it for weeks but I am not able to find it.

Sorry for my english

 
Two problems here

1) You are opening different files with the same handle
2) Formatting the filename

Problem 1
Use an array for the file handles
Code:
integer handle(100)
do i = 1, n
   open (handle(i), ...)
enddo

Problem 2
Formatting - the problem is getting the integer in string form without a leading space
Code:
character*10 strnum
character*20 filename
integer handle(100)
do i = 1, n
   write (strnum, *) i, '.txt'
   name = 'data' // strnum(2:)
   print *, 'Opening ',name
   open (handle(i), file=name)
enddo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top