This is a barely there implementation that seems to handle the example file as far as it goes--which is just the HEADER, TEXT & DATA sections--but it might serve you as a starting point:
#! perl -slw
use strict;
use Data::Dump qw[ pp ];
my %tmpls = (
'1,2,3,4' => {
I => { 16 => 'v*', 32 => 'V*' },
F => { 32 => 'f<*' },
D => { 64 => 'd<*' },
},
'4,3,2,1' => {
I => { 16 => 'n*', 32 => 'N*' },
F => { 32 => 'f>*' },
D => { 64 => 'd>*' },
},
);
open FCS, '<:raw', 'c:\downloaded\FCSExtract-TestData\FloatData4031.fc
+s'
or die $!;
sysread( FCS, my $header, 58 ) or die $!;
my( $id,
$sText, $eText,
$sData, $eData,
$sAnalysis, $eAnalysis
) = unpack 'A6 x4 (A8)6', $header;
sysseek FCS, $sText, 0 or die $!;
sysread( FCS, my $text, $eText - $sText ) or die $!;
my $delim = substr $text, 0, 1, '';
my %text = split $delim, $text;
pp \%text;
sysseek FCS, $sData, 0 or die $!;
sysread( FCS, my $data, $eData - $sData ) or die $!;
my $tmpl = $tmpls{ $text{ '$BYTEORD' } }
{ $text{ '$DATATYPE' } }
{ $text{ '$P1B' } };
die 'Can\'t handle format' unless $tmpl;
my @data = unpack $tmpl, $data;
pp \@data;
It produces output like this: C:\test>FCS
{
"\$BEGINANALYSIS" => 0,
"\$BEGINDATA" => 1794,
"\$BEGINSTEXT" => 0,
"\$BYTEORD" => "4,3,2,1",
"\$DATATYPE" => "F",
"\$ENDANALYSIS" => 0,
"\$ENDDATA" => "441793
"\$ENDSTEXT" => 0,
"\$FIL" => "4031.fcs",
"\$INST" => " ",
"\$MODE" => "L",
"\$NEXTDATA" => 0,
...
[
"0.400000005960464",
"63555.6015625",
"8488.80078125",
"1326.24011230469",
"35157.2421875",
"174.960006713867",
"76.6800003051758",
"1597.51013183594",
"4796.81005859375",
"-13.2799997329712",
"146.910003662109",
"0.5",
"60448.80078125",
"8012.5205078125",
"1193.40002441406",
"31358.880859375",
"167.400009155273",
"31.3200016021729",
"1451.99011230469",
"5587.5400390625",
"-4.15000009536743",
"101.259994506836",
"0.899999976158142",
"31077.6015625",
"7533.00048828125",
"429.840026855469",
"11815.2001953125",
"47.5200004577637",
"16.2000007629395",
"1017.57006835938",
"3776.0302734375",
"13.2799997329712",
"92.129997253418",
1,
"40213.203125",
...
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|