-1

I want to open a file in fortran with file name "controlinputs.12.dat" and then write into that file. The digit "12" is user defined variable whose value is stored in another variable "k". I have tried following and failed.

k=12
open(10,filename='controlinputs.',k,'.dat')

Tried storing the name in character and then using character to open file.

k=12
fname='controlinputs.',k,'.dat'
open(10,filaname=fname)
Syed Moez
  • 129
  • 15
  • Previous answers: http://stackoverflow.com/questions/6146516/writing-multiple-output-files-in-fortran, http://stackoverflow.com/questions/16291270/looping-over-variable-file-names and http://stackoverflow.com/questions/1262695/converting-integers-to-strings-in-fortran – M. S. B. Feb 11 '15 at 10:17

1 Answers1

0

This was very simple. I didn't knew how to concatenate characters. I was reading the integer 12 from a file so I saved it in character type then simply used following.

character::k*5
open(10,filename='controlinputs.'//trim(k)//'.dat')
Syed Moez
  • 129
  • 15