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!

open output files with variable names

Status
Not open for further replies.

thyme

Programmer
Jul 14, 2006
3
US
I am writing a code that reads data from a number of input files and processes these data. The name of the input files are read from keyboard during the program is being executed. I need to open an output file for each input file starting with the name of the input file. For example;infile=1hhp.pdb, outfile=1hhp.out
I've tried the following, but it didn't work.
do i=1,nofile
read(5,*) infile
open(outfile,file=infile,'.out')
close(outfile)
outfile=outfile+1
enddo
Is there a solution that you can think of pleease? thanx..
 
There is one I can think of that can be used to change the file name. But it is not elegant. You save the first part of the file name and add the '.out' in the end. Then you read the whole thing again. For example

PROGRAM filename
IMPLICIT NONE
CHARACTER(LEN=7) :: inp,outp
READ(*,*)inp
WRITE(8,'(A4)',ADVANCE='NO')inp
WRITE(8,'(A4)',ADVANCE='NO')'.out'
REWIND(UNIT=8)
READ(8,*)outp
WRITE(*,*)outp
END PROGRAM filename

In this simple example the filename must be of the form ****.*** You can of course change the (A4) into something else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top