Convert integers to strings to create output filenames at run time

前端 未结 9 2010
小鲜肉
小鲜肉 2020-11-22 02:47

I have a program in Fortran that saves the results to a file. At the moment I open the file using

OPEN (1, FILE = \'Output.TXT\')

However,

9条回答
  •  时光说笑
    2020-11-22 03:29

    A much easier solution IMHO ...................

    character(len=8) :: fmt ! format descriptor
    
    fmt = '(I5.5)' ! an integer of width 5 with zeros at the left
    
    i1= 59
    
    write (x1,fmt) i1 ! converting integer to string using a 'internal file'
    
    filename='output'//trim(x1)//'.dat'
    
    ! ====> filename: output00059.dat
    

提交回复
热议问题