Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fortran90: read file with variable name ( character)

  1. Oct 14, 2011 #1
    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!
     
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted