do-merging-job - a commented script

 
USAGE:   do-merging-job [options] [U][D][P]
 
 Runs
      U - urtapm @ urtapm-big.ins  and  urtapt @ urtap-merged
      D - analyse residual DC-levels and prepare tp-series
      P - prepare plot
 
      Each program employed will announce the most important
      files that are produced.
 
HOW TO?
 
 After the series of urtap-<campaign>-mrg.ins jobs:
    edit the urtapm-big-ins file.
 Then:
    setenv VAR -AUN  # or your variant
    setenv CLIPDTP 3.
    set var=$VAR
 and:
    do-merging-job UDP
 
 and you may plot the results using
    plot-merged-residual
 
OPTIONS:
 
  -O out   - the output file name root for  evaluate-tp-by-project
             Default = evaluate-tp$var  (extensions will be added:
             .dat .tsj .rsl .tbl)
 
  -V var   - a variant code for urtapm and urtapt results
             that will trickle though results at later stages
             Default: taken from environment $VAR

  -F f.tbl - the feature table. Default = t/feature$VAR.tbl
             if it exists.
 
  -i ins   - The instruction file for urtapm
             Default = urtapm-big.ins

  -u ins   - The instruction file for the merged analysis with urtapt
             Default = urtap-merged.ins
 
 
ENVIRONMENT:
 
   VAR     - signals a solution variant
             E.g. -AUN is the variant where one campaign
             was unclear as to the platform/orientation
             (so that a proprietary boxcar was solved for it).
 
EXAMPLES:
          do-merging-job -O AUN UDP
           - Generates evaluate-tp results in files AUN.tbl AUN.tsj ...
             Tries to do all stages.

          do-merging-job -i urtapm-big-O.ins -u urtap-merged-O.ins DP
           - urtapm and urtap merged analyses done, this command
             evaluates the $VAR-marked results using the specified ins-files 

 
#!/bin/csh
if ( x$1 == x-h ) then
   helptext + _ $0
   exit
endif

set out = evaluate-tp
set do_urtap=0
set do_dclevel=0
set prepare_plot=0
set urtapm_ins = urtapm-big.ins
set var=

if ( $?VAR == 1 ) then
   set var=$VAR
   set out=evaluate-tp$var
endif

while ( x`beak $1` == x- )
if ( x$1 == x-O ) then
   shift
   set out = $1
else if ( x$1 == x-i ) then
   shift
   set urtapm_ins = $1
else if ( x$1 == x-u ) then
   shift
   set urtapm_merged = `echo $1 | sed 's/\.ins//'`
else if ( x$1 == x-V ) then
   shift
   set var = $1
endif
shift
end

ecq $1, U && set do_urtap=1
ecq $1, D && set do_dclevel=1
ecq $1, P && set prepare_plot=1

set campaigns = ( `sed -n '/ \^ /s/[^-]*.\([^\.-]*\).*/\1/p' $urtapm_ins` )
# retrieves the campaigns included in the actual super-campaign
#
set projects = ( )
set ipo      = ( )
set camps    = ( )
foreach c ( $campaigns )
  set projects = ( $projects `awk '/^#J/&&/'$c'/{print $3}'           project-dates.lst` )
  set ipo      = ( $ipo      `awk '/^#J/&&/'$c'/{print $6"_"$7"_"$8}' project-dates.lst` )
  set camps    = ( $camps    `awk -v c=$c '/^#J/&&/'$c'/{print c}'    project-dates.lst` )
end
# project-dates.lst contains the start and end times of campaign- and project files
#

#---------------------------------------------------------------------
if ( $do_urtap ) then

set ulog=`basename $urtapm_ins .ins`.log
urtapm @ $urtapm_ins > ! $ulog

   echo "Ready  $ulog a.m.m."
   echo "Starting urtapt  - this will take a while ..."

urtapt @ $urtap_merged.ins > ! $urtap_merged.log

   echo "Ready  $urtapt_merged.log"

# Let's prepare a dated residual file
tp2tsf ra
   if ( -r o/scg-cal-merged$var.ra.mc ) then
      echo "Ready  o/scg-cal-merged$var.ra.mc "
      ls -l o/scg-cal-merged$var.ra.mc
   else
      echo 'Cannot find o/scg-cal-merged$var.ra.mc - var='$var
      exit
   endif
endif

#---------------------------------------------------------------------
if ( $do_dclevel ) then
  echo " "
  echo "Doing DC-levels: 1. evaluate-tp-by-project -R -o $out -tsj "

   rm -f o/scg-cal-merged
$var.dc.mc
   evaluate-tp-by-project -R -o $out -tsj   # does that job really honour $VAR ???
echo " "
echo "Doing DC-levels: 2. tslist o/scg-cal-merged$var.jd.ts -RTPV evaluate-tp$var.tsj -I "'\'
echo "                    O1:'MJD|2:DCLVL' o/scg-cal-merged
$var.dc.mc"

   tslist o/scg-cal-merged$var.jd.ts -RTPV evaluate-tp$var.tsj -I \
         -O1:'MJD|2:DCLVL' o/scg-cal-merged.dc.mc

   echo "Ready DC-level file  o/scg-cal-merged
$var.dc.mc"
endif
#---------------------------------------------------------------------
if ( $prepare_plot ) then
# This is the most tricky part.
# In the time series plot we want to have small gaps when there is no campaign.
# A source script redtp.cmd is created with redtp commands to annotate the
# plot features at the right location with e.g. dates
#
echo " "
echo "JOB 1: Symbols for campaigns"
  rm -f redtp.cmd campaign-dates
  touch redtp.cmd campaign-dates
  foreach p ( $projects )
    echo "Symbols for project $p"
    set r = ( `tp-index-of-project $p` )
    echo redtp -S -i $r >> redtp.cmd
  end
  echo "Generating GMT commands: psxy-project-symbols.cmd"
  source redtp.cmd >! psxy-project-symbols.cmd
echo "____________________________________________"
echo " "
echo "JOB 2: Central times of campaigns"
  foreach c ( $campaigns )
    echo "Campaign $c"
    rm -f prj.tmp
    touch prj.tmp
    foreach pf ( `the-project-files -c .drop.smp $c` )
      set r = ( `tp-index-of-project $pf` )
      if ( $#r > 0 ) then
         redtp -i $r[1] $r[1] $c >>  prj.tmp
      endif     
    end
#
# with similar code like below, find the start & end time of a campaign
#
# First: echo 'psxy -R -JX -K -O -m -N -W2/255/0/0 <<EOF >> plot/PS/$ps' >! campaign-windows
#
# set rbeg = ( `head -1
prj.tmp` )
# set rend = ( `tail -1
prj.tmp` )
# echo ">"              >> campaign-windows
# echo "$rbeg[1] -100"  >> campaign-windows
# echo "$rbeg[1]  200"  >> campaign-windows
# echo "$rend[1] -100"  >> campaign-windows
# echo "$rend[1]  200"  >> campaign-windows
#
# afterwards:  echo EOF >>
campaign-windows
#
    set nof = `awk 'END{print int(NR/2+.6)}' prj.tmp`
    if ( $nof != 0 ) then
       set r = ( `awk '(NR == '$nof' ){print $0}' prj.tmp` )
       if ( $#r > 1 ) then
          set j = `calc $r[2]+1`
          set d = ( `tslist o/scg-cal-merged$var.ra.mc -qqq -LM -L'M],Rwd' \
                     -C0 -Ft1,f13.6,f13.6 -p2:1,2 -E1:tp.tse,D -j$r[2] -Un$j | tail -1` )
          set ymd = `jdc -j -- $d[2]`
          echo "$r[1] 1005 10 45 0 1 $ymd" >> campaign-dates
          echo r   = $r
          echo d   = $d
          echo ymd = $ymd
        endif
    endif
    echo "_____________________________________________"
  end

  echo "Ready for plot:"
  echo "  File psxy-project-symbols.cmd"
  echo "  File campaign-dates"
  echo " "
  echo "Issue:"
  echo "  plot-merged-residual -DC o/scg-cal-merged.dc.mc o/scg-cal-merged-AUN.ra.mc"
  echo " "
endif

exit






.bye