3
|
1 |
#!/usr/bin/perl
|
|
2 |
#======================================================================
|
|
3 |
# S P L I T C N V
|
|
4 |
# doc: Mon Oct 25 22:24:21 2010
|
|
5 |
# dlm: Fri Oct 29 20:04:42 2010
|
|
6 |
# (c) 2010 A.M. Thurnherr
|
|
7 |
# uE-Info: 16 29 NIL 0 0 72 2 2 4 NIL ofnI
|
|
8 |
#======================================================================
|
|
9 |
|
|
10 |
# split SeaBird CNV file using scan values found with yoyo
|
|
11 |
# e.g. splitCNV P403_015_1sec.cnv `importCNV -s P403_015_1sec.cnv | yoyo -QFscan -ut`
|
|
12 |
|
|
13 |
# HISTORY:
|
|
14 |
# Oct 25, 2010: - created
|
|
15 |
# Oct 26, 2010: - BUG: *.00 file always only contained the 1st record
|
|
16 |
# Oct 29, 2010: - cosmetics
|
|
17 |
|
|
18 |
# scan number must be the first field of each record
|
|
19 |
|
|
20 |
die("Usage: $0 <CNV-file> <val> [...]\n")
|
|
21 |
unless (@ARGV >= 2 && -f $ARGV[0]);
|
|
22 |
|
|
23 |
chomp($basename = `basename $ARGV[0] .cnv`);
|
|
24 |
|
|
25 |
$state = 0; # init finite state machine
|
|
26 |
$next = 0; # next extension number
|
|
27 |
$trg = 2; # NB: yoyo -ut includes first & last scans
|
|
28 |
|
|
29 |
open(IN,$ARGV[0]);
|
|
30 |
while (<IN>) {
|
|
31 |
if ($state == 0) { # state 0: reading header
|
|
32 |
push(@HDR,$_);
|
|
33 |
$state = 1 if /^\*END\*/;
|
|
34 |
next;
|
|
35 |
}
|
|
36 |
if ($state == 1) { # state 1: begin new file
|
|
37 |
close(OUT);
|
|
38 |
printf(STDERR "writing $basename.%02d\n",$next);
|
|
39 |
open(OUT,sprintf(">$basename.%02d",$next++));
|
|
40 |
foreach my $h (@HDR) { print(OUT $h); }
|
|
41 |
$state = 2;
|
|
42 |
}
|
|
43 |
if ($state == 2) { # state 2: copy data until target scan
|
|
44 |
print(OUT);
|
|
45 |
my(@f) = split;
|
|
46 |
$trg++,$state=1 if ($f[0] == $ARGV[$trg]);
|
|
47 |
}
|
|
48 |
}
|