binary file read - Help

From: Jeff Godfrey (
Date: 12/11/03

Date: Thu, 11 Dec 2003 13:19:34 -0600

Hi All,

Once again, I'm stepping off into an area where I have no business... ;^)

I am trying to read a binary file (using tcl 8.4.5 on WinXP) that was
created by a FORTRAN executable (also on WinXP). Unfortunately, I know
almost nothing about reading binary data in tcl, and my FORTRAN is *very*

I've written a small FORTRAN application that just reads 3 integer values
from the file and prints them to the screen.

The (correct) output from the FORTRAN is: 14, 24, 4

Next, I've tried to read the values using the following tcl:

set fileID [open "test.bin" RDONLY]
fconfigure $fileID -translation binary
set binaryData [read $fileID]
close $fileID

binary scan $binaryData ccc a b c
binary scan $binaryData sss d e f
binary scan $binaryData iii g h i

puts "$a, $b, $c"
puts "$d, $e, $f"
puts "$g, $h, $i"

The output I get is as follows:

75, 4, 14
1099, 14, 0
918603, 134479872, 24

While *some* of my numbers appear to be there, something is obviously wrong
(alignment?). I've been told by others that FORTRAN binary files are
difficult to read using another language, but I don't know why that would be
the case.

So, that's it. How can I get there from here?

BTW, all above code has been retyped, so any minor errors (?) are a function
of that, not the original program...