Re: Optimizing a binary read routine



jgodfrey wrote:
Hi All,

I have a number of Tcl procedures I wrote a few years ago that are
designed to decode geometric data that's packed into a "Unformatted
Sequential File" that's written by a FORTRAN application.
got an example somewhere?

I would do it a bit differently, the following example is rather raw
and would just read a complete file:

fortran::usf::readformated {filename format args {
set fd [ open $filename r ]
fconfigure $fd -encoding binary -translation binary

set type [ read $fd 1 ]
binary scan [ read $fd 2 ] cc type nextlen

switch -- $type \
"79" {
# is unformated sequential file
} default {
puts stderr "Nicht die Mammi"
error "wrong filetype"
}
while { ![ append buffer [read $fd $nextlen ] ; feof $fd ] } {
binary scan [ read $fd 2 ] cc lastlen nextlen
if { $nextlen == 130 } break
}
close $fd

return [ binary scan $buffer $format ]
}

uwe
.