Convert integers to strings to create output filenames at run time

前端 未结 9 2012
小鲜肉
小鲜肉 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:49

    Try the following:

        ....
        character(len=30) :: filename  ! length depends on expected names
        integer           :: inuit
        ....
        do i=1,n
            write(filename,'("output",i0,".txt")') i
            open(newunit=iunit,file=filename,...)
            ....
            close(iunit)
        enddo
        ....
    

    Where "..." means other appropriate code for your purpose.

提交回复
热议问题