I am trying to get a fortran 90 application to open fifo and write formatted data to it. I divided this into a minimal example. Let foo.f90 be the following program:
program foo open(1,file='fifo',position='asis',action='write') write(1,*)'Hello, world!' write(1,*)'Goodbye.' end program
Now compile and run the program:
$ gfortran-4.7.1 -o foo foo.f90 $ rm -f fifo $ ./foo $ cat fifo Hello, world! $ rm -f fifo $ mkfifo fifo $ cat fifo > bar & [1] 6115 $ strace -o foo.st ./foo At line 3 of file foo.f90 (unit = 1, file = 'fifo') Fortran runtime error: Invalid argument [1]+ Done cat fifo > bar $ tail foo.st write(3, " Hello, world!\n", 15) = 15 lseek(3, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) ftruncate(3, 18446744073709551615) = -1 EINVAL (Invalid argument) write(2, "At line 3 of file foo.f90 (unit "..., 52) = 52 write(2, "Fortran runtime error: ", 23) = 23 write(2, "Invalid argument", 16) = 16 write(2, "\n", 1) = 1 close(3) = 0 exit_group(2) = ? +++ exited with 2 +++
Thus, the program works quite well when written to a regular file. However, when writing to fifo, it tries to resize the file after the first recording, terminating the application after that.
I'm new to Fortran, so I'm not sure if this is a bug in gfortran, or is there a way to open a file that will suppress this syscall ftruncate . I would prefer to follow a formatted sequential approach: my lines have different lengths, and I would prefer not to specify the record number with each write .
linux fortran named-pipes gfortran fortran90
Mvg
source share