Re: Optimizing a binary read routine
- From: Uwe Klein <uwe_klein_habertwedt@xxxxxxxxxxx>
- Date: Fri, 02 May 2008 19:25:22 +0200
jgodfrey wrote:
Hi All,got an example somewhere?
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.
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
.
- References:
- Optimizing a binary read routine
- From: jgodfrey
- Optimizing a binary read routine
- Prev by Date: Re: Splitting string
- Next by Date: Re: Optimizing a binary read routine
- Previous by thread: Optimizing a binary read routine
- Next by thread: Re: Optimizing a binary read routine
- Index(es):