Write unformatted (binary data) to stdout

后端 未结 2 1008
北海茫月
北海茫月 2021-01-19 21:17

I want to write unformatted (binary) data to STDOUT in a Fortran 90 program. I am using AIX Unix and unfortunately it won\'t let me open unit 6 as \"unformatted\". I thought

2条回答
  •  一整个雨季
    2021-01-19 21:34

    I would try to convert the data by TRANSFER() to a long character and print it with nonadvancing i/o. The problem will be your processors' limit for the record length. If it is too short you will end up having an unexpected end of record sign somewhere. Also your processor may not write the unprintable characters the way you would like.

    i.e., something like

    character(len=max_length) :: buffer
    
    buffer = transfer(data,buffer)
    
    write(*,'(a)',advance='no') trim(buffer)
    

    The largest problem I see in the unprintable characters. See also A suprise with non-advancing I/O

    ---EDIT--- Another possibility, try to use file /proc/self/fd/1 or /dev/fd/1

    test:

    open(11,file='/proc/self/fd/1',access='stream',action='write')
    write(11) 11
    write(11) 1.1
    close(11)
    end
    

提交回复
热议问题