#! /bin/csh -f
# Last edited on 1999-08-31 23:56:02 by hcgl

set usage = "$0 [-reverse] BAND CANDNUM EXT CURVE0 INI0 LEN0 CURVE1 INI1 LEN1"

# For each segment of the given candidate, reads
# the file CURVE/fBAND.EXT and 
# extracts from it the samples that comprise
# the segment. The result is written to a file
# fBAND-seg-cCANDNUM-SIDE-seg.EXT
# where SIDE is 0 or 1.
# If "-reverse" is given, the SIDE=1 segment
# is reversed

if ( "x$1" == "x-reverse" ) then
  set revop = ( "-reverse" ); shift
else
  set revop = ( )
endif

if ( $#argv != 9 ) then
  echo "usage: ${usage}"; exit 1
endif
 
set band = "$1"; shift;
set candnum = "$1"; shift;
set ext = "$1"; shift;
set curvea = "$1"; shift;
set inia = "$1"; shift;
set lena = "$1"; shift;
set curveb = "$1"; shift;
set inib = "$1"; shift;
set lenb = "$1"; shift;

set ifilea = "${curvea}/f${band}.${ext}"
set ifileb = "${curveb}/f${band}.${ext}"

set ofilea = "f${band}-seg-c${candnum}-0.${ext}"
set ofileb = "f${band}-seg-c${candnum}-1.${ext}"

/bin/rm -f ${ofilea} ${ofileb}
extract-segment ${inia} ${lena} < ${ifilea} > ${ofilea}
extract-segment ${revop} ${inib} ${lenb} < ${ifileb} > ${ofileb}