Does anyone know why when I close stdin and reopen it as unformatted,
stream access I can successfully read in files using the redirection
'<' symbol, but if I 'cat' the file and pipe it into the code, I get
an 'illegal seek' error?
I have also tried to use a named pipe created with mkfifo and this still happens.
Say I use matlab to make some data:
>> fid = fopen('test.bin','w'); >> fwrite(fid,double(pi),'double'); >> fclose(fid);
then I try the following test
program tester use iso_fortran_env implicit none doubleprecision :: pi integer :: error close(input_unit) open(unit=input_unit,access='stream',form='unformatted',iostat=error) write(output_unit,*) error read(input_unit,iostat=error) pi write(output_unit,*) error write(output_unit,*) iostat_end write(output_unit,*) iostat_eor write(output_unit,*), pi end program
Also, please note, the original source code douse not have an extra 'd' in the doubleprecision declaration. This appears to be a bug with the source highlighter.
ifort -g -warn all -check all -traceback -o tester tester.f90
Using a pipe I get this:
$ cat test.bin | ./tester 0 38 -1 -2 1.117351266127586E-315
Using redirection i get this:
$ ./tester < src/matlab/roughness/test.bin 0 0 -1 -2 3.14159265358979
this because there are no longer record indicators so when I close then
reopen stdin as stream access the program loses track of where it is in
If I try this technique with sequential access I
don't encounter this problem. (Note, you need to write binary data with
fortran so that it includes the sequential access record indicators
which are stripped off for stream access.)