Binary I/O in linux

Binary I/O in linux


I'm trying to read in binary files (written using C)
and also write binary files.

my small test program is:
A = 20
B = 40
C = 70
OPEN(11, file='test.tmp', form='unformatted')
write(11) A, B, C

compiled with:
ifc -extend_source -w -nbs -zero -O3 -c test.for
program TEST

17 Lines Compiled
ifc -extend_source -w -nbs -zero -O3 test.o -zero -L. -o test.x

but.... my output has an extra variable in it .
$ od -l test.tmp
0000000 12 20 40 70
0000020 12

Why is this occuring - I thought unformatted ouptut like this wouldn't put record info(?) at the start of the file. Am I missing something really simple here ?

I must also add that I am just starting to use this compiler.



7 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

The options for binary compatibility with C files, unfortunately, require you to choose between portability and convenience. If you look in the .pdf documentation, there is an option form='BINARY' which should suppress the record size information and give you C binary file compatibility.

Another option, I believe, is to used direct access, with RECL=1, to read 1 byte at a time.


Ok, I figured it out, their is a FORM='BINARY' option to the OPEN statement, However, reading through the documentation I can find no mention of this.

in for_prg.pdf page 10-137 makes only mention of UNFORMATTED or FORMATTED
in for_ug_lnx.pdf: page 107-108 the example uses unformatted to produce what i think looks like binary.

You're right, it's not fully documented that I can see except in the help pages for the CVF Windows compiler. I hope this takes care of your requirement.

Thanks Tomothy,

it does help, but without trying to sound too critical - why would I be looking through the documentation for the CVF Windows compiler when I have linux manuals and are programming on linux ?

I suppose that this will now be added to the manuals ?

submitted as documentation issue 180559

what a hassle, can't login from Opera tonight

Reported as planned for correction of documentation.

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen