3 # split the output of "sp2sp -s head" into multiple files, one per sweep.
10 print STDERR "usage: sweepsplit [options] [file [name]]
11 or: sp2sp -s head | sweepsplit [options]
13 -a Len Use Len digits when constructing numered output file names
14 -s N Dump only sweep number N to stdout
15 -t Type Assume input is of type T (passed to sp2sp)
21 Getopt::Long::config('no_auto_abbrev',
22 'no_ignore_case','no_ignore_case_always');
30 %optctl = ("s=i" => \$dump_sweepno,
31 "a|suffixlength=i" => \$suffixlength,
32 "t=s" => \$infile_type,
33 "v|verbose!" => \$verbose
36 if(!GetOptions(%optctl)) {
41 if($#ARGV >= 0) { # input filename provided
42 $infname = shift(@ARGV);
44 if($#ARGV >= 0) { # base part of output filenames specified
45 $fnbase = shift(@ARGV);
48 if(!$fnbase) { # If no output filename specified, construct one.
51 $fnbase =~ s|^.*/([^/]+)$|$1|; # remove leading directory names
52 $fnbase =~ s|\.[^.]*$||; # remove trailing .suffix
58 $infp = new FileHandle;
61 $topt = "-t $infile_type";
63 $infp->open("sp2sp -s head $topt $infname|") || die "pipe from sp2sp $infname: $!";
65 $infp->fdopen(STDIN, "r");
69 $heads = $infp->getline;
71 while($_ = $infp->getline) {
73 if($_ =~ m/^\#\s*sweep\s*(\d+);/) {
75 open_outfile($sweepno);
86 $infp->close || "pipe from sp2sp $infname: $!";
91 print STDERR "no sweeps found\n";
95 printf "%d sweeps\n", $nsweeps;
98 #############################################################################
107 if($dump_sweepno == -1 || $dump_sweepno == $sweepno) {
108 $fname = sprintf "%s%0*d.asc", $fnbase, $suffixlength, $sweepno;
110 $fname = '/dev/null';
112 $fp = new FileHandle $fname,"w";
118 # would like to include sweep number as comment - but gwave
119 # can't deal with this. to be fixed.