Fortran90: read file with variable name ( character)

  • Comp Sci
  • Thread starter typeon
  • Start date
  • #1
4
0
Hi there,

I am trying to make a Fortran90 program that open files with this pattern:

1a041.dat
wp2d2.dat
qad33.dat
mntf4.dat
erh55.dat
...etc.
so the first four digits I want to consider them as a variable character, then it comes an integer value that increases by one for every file. The last part is the ".dat"

I don't know how to tell my program to read this character for every file and then to open it.

I think I have managed to sort out the integer part by converting the integer value into a string value by using write(numchr,*) j.

This is an extract of the program:
PROGRAM database
character(40) :: numchr ! this is to turn integer into string
character(10) :: prot ! this is to read the first 4 digits
integer :: j,n,i,k

n = 10
DO j = 1,n
write(numchr,*) j

open (j, file = prot // trim(adjustl(numchr)) // ".dat",status='old')
etc....
close(j)
ENDDO

Many thanks!
 

Answers and Replies

Related Threads on Fortran90: read file with variable name ( character)

Replies
3
Views
920
  • Last Post
Replies
10
Views
2K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
5
Views
6K
  • Last Post
Replies
2
Views
1K
Replies
2
Views
311
Replies
6
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
14
Views
1K
Top