Binary I/O in linux

Binary I/O in linux

Bild des Benutzers Community Admin

Hi,

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

my small test program is:
PROGRAM TEST
IMPLICIT NONE
INTEGER A, B, C
A = 20
B = 40
C = 70
OPEN(11, file='test.tmp', form='unformatted')
write(11) A, B, C
close(11)
stop
END

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
0000024


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.

Thanks

John

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

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.

Bild des Benutzers Community Admin

Grrrrrrrrrrrr

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.

i.e.
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.

Bild des Benutzers Tim Prince

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.

Bild des Benutzers Community Admin

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 ?

Bild des Benutzers Tim Prince

submitted as documentation issue 180559

Tim
what a hassle, can't login from Opera tonight

Bild des Benutzers Tim Prince

Reported as planned for correction of documentation.

Melden Sie sich an, um einen Kommentar zu hinterlassen.