I am trying to understand if it is possible to output binary from Fortran.
Specifically I have tried:
integer(kind=1) :: a
a = 64
write(unit=6,form='UNFORMATTED') a
I am trying to output this variable to the standard output so one byte of value 64 would be written.
I.E. running:
$ ./my_code | od -d
would show a single byte of value 64.
Research done:
I have seen that there is the possibility to use Binary I/O. For example for Sun Fortran 95 compiler:
https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/2_io.html (section 2.3)
But this is for files, not for standard output.
--
For standard output I have seen this post, but it is related to AIX and the /proc/self/fd/1 solution is not available in FreeBSD. I am interested in FreeBSD and Linux:
Write unformatted (binary data) to stdout
My questions are:
- Is there something in Fortran 95 or any other modern standard to allow and provision any functionality in write for this specific case?
- If so, which would be the syntax or at least, where can I learn more?
print '(B0)', ameet your requirements, or are you trying to get the ASCII value of 64?SEQUENCEandBIND(C)does to derived types. There is NO guarantee on the layout of the derived type components otherwise. You can ask a detailed question about this issue. Don't forget to show the code and the results.