#!/bin/csh -f source /star/etc/login >& /dev/null source /star/etc/cshrc >& /dev/null kappa >& /dev/null if (`alias kappa` == "") then echo "" echo "Fatal: Initialization error of kappa environment" echo "" exit endif set kap = $KAPPA_DIR if ($#argv < 1) set argv = "help" if ($argv[1] =~ *"help"* || $argv[1] == "-h") then echo "" echo "Use: sp_trim file [nunits1 [nunits2]]" echo " e.g. 'sp_trim myfile 100'" echo "" echo "Trims off channels from the edges of the spectrum." echo "Nunits is in units of the spectral axis as set by sp_axis." echo "The default is 50 pixels/kms-1/Ghz. With only one value" echo "the same number of channels is trimmed from each side." echo "" exit endif set infile = $argv[1] set infile = `echo "$infile" | cut -d\. -f1` set infile = "${infile}.sdf" shift argv if !(-e "$infile") then echo "" echo "Fatal: file $infile not found" echo "" exit endif set nunits1 = 50 if ($#argv > 0) then set nunits1 = "$argv[1]" shift argv endif set nunits2 = $nunits1 if ($#argv > 0) then set nunits2 = "$argv[1]" endif # ---------------------------------------------------------------------- # Trim spectrum / cube # set base = `echo $infile | sed s/.sdf//` set outfile = ${base}_trim.sdf # Find out the cube dimensions. ndftrace $infile >& /dev/null set lbnd = `${kap}/parget flbnd ndftrace | head -1` set ubnd = `${kap}/parget fubnd ndftrace | head -1` set funts = `${kap}/parget funit ndftrace | head -1` set ilbnd = `echo $lbnd[3] | cut -d\. -f1` set iubnd = `echo $ubnd[3] | cut -d\. -f1` set funit = ${funts[3]} echo "" echo "Deleting $nunits1 and $nunits2 $funit, respectively, from the " echo "edges of: $infile" if ($ilbnd < $iubnd) then set prange = "${lbnd[3]}:${ubnd[3]}" set left = `echo "scale=2;((${lbnd[3]})+($nunits1))" | bc` set right = `echo "scale=2;((${ubnd[3]})-($nunits2))" | bc` else set prange = "${ubnd[3]}:${lbnd[3]}" set left = `echo "scale=2;((${ubnd[3]})-($nunits1))" | bc` set right = `echo "scale=2;((${lbnd[3]})+($nunits2))" | bc` endif set nrange = "${left}:${right}" echo "Range changed from $prange --> $nrange" ${kap}/ndfcopy $infile'(,,'${nrange}')' $outfile if (-e "$outfile") then echo "The trimmed spectrum has been saved in:" echo " '$outfile'" else echo "ERROR: trim failed" endif echo ""