(file) Return to dopkbgn CVS log (file) (dir) Up to [Development] / JSOC / proj / globalhs / scripts

File: [Development] / JSOC / proj / globalhs / scripts / dopkbgn (download)
Revision: 1.27, Thu Jun 15 23:01:13 2017 UTC (7 months ago) by tplarson
Branch: MAIN
CVS Tags: Ver_LATEST, Ver_9-1, HEAD
Changes since 1.26: +22 -11 lines
generalize use of guess file, propagation apodization keyword

#! /bin/tcsh -f

# this script sets up and runs all iterations of peakbagging.
# to change the number or type of iteration, specify niter, npflags, and amflags in pkb.parms.blank.

setenv PATH $JSOCROOT/bin/$JSOC_MACHINE':'$JSOCROOT/proj/globalhs/scripts':'$JSOCROOT/proj/globalhs/scripts/pkbgn':'$PATH

set idldir=$JSOCROOT/proj/globalhs/scripts/idl
set pbdir=$JSOCROOT/proj/globalhs/scripts/pkbgn

@ i = 1
while ($i <= $#argv )
  set $argv[$i]
@ i++
end

if (! $?starttime) then
  echo must specify parameter starttime
  exit 1
endif

if (! $?totaltime) then
  echo must specify parameter totaltime
  exit 1
endif

set totalsecs = `durcon $totaltime`
if ($status) then
  echo incorrect format for parameter totaltime
  exit 1
endif

set timecheck = `echo "$totalsecs % 86400" | bc`
if ($timecheck) then
  echo totaltime must be an integer number of days
  exit 1
endif

set ndays = `echo "$totalsecs / 86400" | bc`

if (! $?lmin) set lmin = 0
if (! $?lmax) set lmax = 300
if ($?writeflag) then
  set wfclause = "writeflag=$writeflag"
else
  set wfclause = ""
endif

echo `date` on $HOST
echo $PWD
echo $0 $argv

if (! -es pkb.parms.blank) then
  echo parameter file blank missing: pkb.parms.blank is required
  exit 1
endif

#grep -v "^[[:space:]]*#" pkb.parms.blank | sed s@"[[:space:]]"@"\n"@g | grep -v '^[[:space:]]*$'  > parms.tmp
grep -v "^[[:space:]]*#" pkb.parms.blank | grep -v '^[[:space:]]*$'  > parms.tmp
grep -v '^[[:space:]]*$' pkb.parms.blank | grep "^[[:space:]]*##" | awk -F '##' '{print $2}' | sed s@"[[:space:]]"@"\n"@g | grep -v '^[[:space:]]*$' > script.parms

set vars = `cat script.parms`
@ i = 1
while ($i <= $#vars )
  set $vars[$i]
@ i++
end

if (! $?guessfile) set guessfile=vw_V.72.par

# TAG may have been defined in script.parms 
if ($?TAG) then
  set tagclause = "TAG=$TAG"
else
  set tagclause = `cat parms.tmp | grep ^in= | cut -d= -f2- | sed s/"'"/""/g | sed s@"\["@"\n"@g | sed s@]@"\n"@g | grep TAG`
endif

if (! $?ica) set ica=2
set npflags = `echo $npflags | cut -d, -f1- --output-delimiter=' '`
set amflags = `echo $amflags | cut -d, -f1- --output-delimiter=' '`
if ($#npflags != $niter || $#amflags != $niter) then
  echo problem with parameter file blank: number of flags does not match niter
  exit 1
endif

if (! $?iweed) set iweed=0
if (! $?iasymweed) set iasymweed=0
if ($iweed && $iasymweed) then
  echo problem with parameter file blank: cannot set both iweed and iasymweed.
  exit 1
endif
# the following is not used if iweed=0
if (! $?weedthresh) set weedthresh=10
if (! $?asymsign) set asymsign=1

set in = `cat parms.tmp | grep ^in= | sed s/\'//g | sed s/\"//g | awk -F '[=[]' '{print $2}'`
set epoch = `show_info -j $in | grep -i '^keyword:t_start_epoch' | cut -d, -f5`
set epochsecs = `time_convert o=jsoc time=$epoch`
set tstartstep = `show_info -j $in | grep -i '^keyword:t_start_step' | cut -d, -f5`
set cadence = `show_info -j $in | grep -i '^keyword:t_step' | cut -d, -f5`
set ndt   = `echo "$totalsecs / $cadence" | bc`

if (! $?executable) then
  if ($ndt < 210000) then
    set executable=jpkbgn
  else
    set executable=jpkbgn360d
  endif
endif

durcon $starttime >& /dev/null
if ($status) then
  set startsecs = `time_convert o=jsoc time=$starttime`
  set firstday  = `echo "($startsecs - $epochsecs)/86400" | bc` 
else
  set startsecs = `durcon $starttime` 
  set firstday = `echo "$startsecs / 86400" | bc`
  set startsecs = `echo "$startsecs + $epochsecs" | bc`
endif

set index = `echo "($startsecs - $epochsecs)/$tstartstep" | bc`

set in = `cat parms.tmp | grep ^in= | sed s/\'//g | sed s/\"//g | awk -F 'in=' '{print $2}' | sed s/XXXX/$starttime/g | sed s/MMMM/$lmin-$lmax/g | sed s/TTTT/$ndt/g`
show_info -q "$in" key=calver64 > calver.tmp
set calver = `uniq calver.tmp`
if ($#calver > 1) then
  echo CALVER64 varies across the input
  exit 1
endif
if ($calver == InvalidKeyname) set calver=0

show_info -q "$in" key=version > version.tmp
set version = `uniq version.tmp`
if ($#version > 1) then
  echo VERSION varies across the input
  exit 1
endif

# VERSION may have been (re)defined in script.parms 
if ($?VERSION) then
  set verclause = "VERSION=$VERSION"
else if ($version != InvalidKeyname) then
  set verclause = "VERSION=$version"
else
  set verclause = ""
endif

if (-es m$niter{q.36}) goto iterdone

echo ndt=$ndt'L' > parms.idl
echo lmin=$lmin >> parms.idl
echo lmax=$lmax >> parms.idl
echo tsample=$cadence >> parms.idl
echo icasea=$ica >> parms.idl
if ($iweed) echo weedthresh=$weedthresh >> parms.idl
echo asymsign=$asymsign >> parms.idl

@ noib1=660 * $ndays
@ noib2=710 * $ndays
set noib=\"$noib1' '$noib2\"
#set noib=\"6220' '9820\"
@ ndf0= $ndays / 4
if ($ndf0 < 5) set ndf0=5
@ ndf1= 7 * $ndays
if ($ndf1 < 10) set ndf1=10

set test=`cat $pbdir/$guessfile | wc`
@ ncol = $test[2] / $test[1]

if ($ica <= 2) then
  awk -v nd=$ndays '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12+log(nd/72.0)}' $pbdir/$guessfile > par1
else if ($ncol == 12) then
  awk -v nd=$ndays '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12+log(nd/72.0),"1.55"}' $pbdir/$guessfile > par0
  cat parms.idl $idldir/mkpar1_asym.idl | idl
else
  awk -v nd=$ndays '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12+log(nd/72.0),$13}' $pbdir/$guessfile > par1
endif

idl << EOF
getpar1q,$lmin,$lmax
EOF

set first=`/bin/ls par*q | awk -F "[rq]" '{print $2}' | sort -n | tail -1`
cat parms.tmp | sed s/XXXX/$starttime/g | sed s/TTTT/$ndt/g | sed s/BBBB/"$noib"/g | sed s/EEEE/$ndf0/g | sed s/FFFF/$ndf1/g | sed s/parIIII/par$first/g > parms.MMMM

rm -f pblist0
set l=$lmax
while ($l >= $lmin)
  echo $l >> pblist0
@ l=$l - 1
end

rm -f iter.log
set i=$first
while ($i < $niter)
  echo starting iteration $i
  doiter index=$index iter=$i noiseperturb=$npflags[$i] allmodes=$amflags[$i] executable=$executable $wfclause
  if ($status) then
    echo failure of pkbgn, check iter.log
    exit 1
  endif
@ i++
end
echo starting final iteration $niter
doiter index=$index iter=$niter noiseperturb=$npflags[$niter] allmodes=$amflags[$niter] executable=$executable last=1

if (-es iter.log) then
  echo failure of pkbgn, check iter.log
  exit 1
endif

iterdone:
set last=$niter

set thi=`cat m$last{q.36} | wc -l`
set eig=`cat m$last{q.18} | wc -l`
set six=`cat m$last{q} | wc -l`

echo $six $eig $thi $last $firstday > list
idl << EOF
weed,$ndt,$cadence,$ica
EOF

if (! -es split$last{qr}.$firstday.18.2d) then
  echo error in weeding, splittings file either does not exist or is empty
  exit 1
endif
echo weeding done, splittings files made

set filelist=(`/bin/ls par[0-9]* {m,res}[0-9]*{q,qc,qp,qx,qw,q.18,q.36} tmp*.idl`)
tar -czf archive.$firstday.tar.gz $filelist

# modeseries and archseries should be defined in script.parms above
$executable @pkb.parms.$lmin out=$modeseries >& log.history
if ($status) then
  echo failure to create history record, check log.history
  exit 1
endif
set histrecnum = `grep histrecnum log.history`
set $histrecnum
set historyseries = `show_info -j $modeseries | grep -i '^link: history' | cut -d, -f2`

set tstart = `time_convert s=$startsecs zone=TAI`
set stopsecs = `echo "$startsecs + $totalsecs" | bc`
set tstop = `time_convert s=$stopsecs zone=TAI`
set midsecs = `echo "$startsecs + ($totalsecs / 2)" | bc`
set tobs = `time_convert s=$midsecs zone=TAI`
set now = `date -u  +%Y.%m.%d_%T`

set in = `cat pkb.parms.$lmin | grep ^in= | awk -F 'in=' '{print $2}'`
show_info -kq "$in" key=apinner,apwidth > ap.tmp
set apclause = `cat ap.tmp | grep -v '^#'`

set_info -c ds=$modeseries HISTORY=$historyseries\[:'#'$histrecnum] $tagclause $verclause $apclause NDT=$ndt LMIN=$lmin LMAX=$lmax T_START=$tstart T_STOP=$tstop T_OBS=$tobs CALVER64=$calver DATE=$now m6=m$last{qr}.$firstday m18=m$last{qr}.$firstday.18 m36=m$last{qr}.$firstday.36
if ($?) then
    echo failure to ingest mode parameters for starttime = $starttime, totaltime = $totaltime
    exit 1
endif
set_info -c ds=$archseries HISTORY=$historyseries\[:'#'$histrecnum] $tagclause $verclause NDT=$ndt LMIN=$lmin LMAX=$lmax T_START=$tstart T_STOP=$tstop T_OBS=$tobs CALVER64=$calver DATE=$now archive=archive.$firstday.tar.gz
if ($?) then
    echo failure to ingest iteration history for starttime = $starttime, totaltime = $totaltime
    exit 1
endif

rm ap.tmp calver.tmp version.tmp parms.tmp parms.MMMM parms.idl script.parms pblist pblist0 eee m0 m1 list faillist
echo successful completion
exit 0


Karen Tian
Powered by
ViewCVS 0.9.4