0

This program will write 'hello' at the specified position '9' of the file 'test.txt'

program test
    open(31,file='test.txt',access='stream')
    write(31,pos=9)'hello'
    close(31)
end program

Can this position specifier be used to write on terminal?
I want to be able to do something like write(*,pos=9)'hello'

Edwin_R
  • 113
  • 2

1 Answers1

1

The standard output is pre-opened as a sequential access formatted file, therefore you cannot use pos.

Why you want this? You can just use an explicit format

write(*,'(t9,a)') 'hello'

Or you can print some spaces before hello. You can even concatenate the spaces and the string.

  • when the file already contains something, then the 'pos' will write only at the position specified and will not change other contents. I wanted to do the same on the terminal. Like inserting text between something already printed. Is there a way to go 'back' on screen? – Edwin_R Jun 14 '14 at 13:07
  • Yes, using control characters http://en.wikipedia.org/wiki/Control_character or using some library such as ncurses. – Vladimir F Героям слава Jun 14 '14 at 13:22
  • But it is system dependent, beyond the Fortran standard. See also http://stackoverflow.com/questions/6792812/the-backspace-escape-character-b-in-c-unexpected-behavior – Vladimir F Героям слава Jun 14 '14 at 13:25
  • Also http://stackoverflow.com/questions/23207032/does-an-ncurses-or-similar-library-exist-which-works-well-with-fortran – M. S. B. Jun 14 '14 at 15:01