Reading a character string of unknown length

后端 未结 4 2062
轻奢々
轻奢々 2021-02-02 00:07

I have been tasked with writing a Fortran 95 program that will read character input from a file, and then (to start with) simply spit it back out again. The tricky part is that

4条回答
  •  盖世英雄少女心
    2021-02-02 00:32

    I'm using Fortran 90 to do this:

    X = Len_Trim( Seq(I) )           ! length of individual sequence
    write(*,'(a)') Seq(I)(1:X)
    

    You can simply declare Seq to be a large character string and then trim it as your write it out. I don't know how kosher this solution is but it certainly works for my purpose. I know that some compilers do not support "variable format expressions", but there are various workarounds to do the same thing almost as simply.

    GNU Fortran variable expression workaround.

提交回复
热议问题