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

File: [Development] / JSOC / proj / globalhs / scripts / dodscopy1 (download)
Revision: 1.3, Fri Feb 13 01:53:10 2015 UTC (3 years, 2 months ago) by tplarson
Branch: MAIN
CVS Tags: Ver_LATEST, Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-12, Ver_8-11, Ver_8-10
Changes since 1.2: +1 -1 lines
change from a.q to k.q

#! /bin/tcsh -f

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

# this script retiles a single interval in time

# submit njobs jobs at once
if (! $?GLOBALHS_RETNJOBS) then
  set njobs=6
else
  set njobs=$GLOBALHS_RETNJOBS
endif

# submit next batch of jobs when total number of retile jobs drops below jobthreshold
if (! $?GLOBALHS_RETJOBTHRESHOLD) then
  set jobthreshold=2
else
  set jobthreshold=$GLOBALHS_RETJOBTHRESHOLD
endif

# if this script inherited a label in its environment, use it as the suffix for job names
if (! $?GLOBALHS_LABEL) then
  set suff=''
else
  set suff=.$GLOBALHS_LABEL
endif

set qsubtmp=/tmp27/$USER/qsubtmp
mkdir -p $qsubtmp
if (! $?GLOBALHS_RETQUEUE) then
  set q=j.q
else
  set q=$GLOBALHS_RETQUEUE
endif

if ($q == k.q) then
  alias qsub qsub2
  alias qstat qstat2
  alias waittosubmit waittosubmit2
endif

@ 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

if (! $?timechunk) set timechunk = $totaltime
set chunksecs = `durcon $timechunk`
if ($status) then
  echo incorrect format for parameter timechunk
  exit 1
endif

if (! $?totaltimeout) set totaltimeout = $totaltime
set totalsecsout = `durcon $totaltimeout`
if ($status) then
  echo incorrect format for parameter totaltimeout
  exit 1
endif

if (! $?startoffset) set startoffset = 0d
set offsecs = `durcon $startoffset`
if ($status) then
  echo incorrect format for parameter startoffset
  exit 1
endif

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


if (! $?lmin) set lmin = 0
if (! $?lmax) set lmax = 300
if (! $?lchunkout) set lchunkout = 1

if (($lchunkin % $lchunkout && $lchunkin < $lmax + 1) && ($lchunkout % $lchunkin && $lchunkout < $lmax + 1)) then
  echo lchunkout must evenly divide lchunkin or lchunkin must evenly divide lchunkout
  exit 1
endif

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

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

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

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

if (! $?copyto) then
  echo copyto must be supplied as a script parameter in ret.parms.blank
  exit 1
endif

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

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 firstindex = `echo "($startsecs - $epochsecs)/$tstartstep" | bc`
set startsecs = `echo "$startsecs + $offsecs" | bc`
set start = `time_convert o=cal zone=tai s=$startsecs`

@ lchunkfirst = $lmin / $lchunkin
@ lchunklast  = $lmax / $lchunkin
@ nlc = ($lchunklast - $lchunkfirst) + 1

@ lc = $lchunkfirst
while ($lc <= $lchunklast)
@ lfirst = $lc * $lchunkin 
@ llast  = $lfirst + $lchunkin - 1
  if ($lfirst < $lmin) set lfirst = $lmin
  if ($llast  > $lmax) set llast  = $lmax

@ r = ( $lc - $lchunkfirst ) % $njobs
  set subfile = subr.$firstindex.$lmin-$lmax.$r$suff
  if ( ( $lc - $lchunkfirst ) < $njobs) then
    echo '#\!/bin/csh' > $subfile
    echo 'setenv PATH' $JSOCROOT'/bin/$JSOC_MACHINE' >> $subfile
    echo 'cd' $PWD >> $subfile
  endif

  echo \(time dscp dsout=$copyto rsin=$out\"\[$start/$totaltimeout]\[$lfirst-$llast]\[$lfirst-$llast]\[$ndt]\[$tagclause]\"\) '>&' dscp.log.$lfirst-$llast >> $subfile
  echo echo \$status '>&' dscp.exitstatus.$lfirst-$llast >> $subfile

@ lc++
end

waittosubmit $jobthreshold subr
set i=0
if ($nlc < $njobs) set njobs=$nlc
while ($i < $njobs)
  set subfile = subr.$firstindex.$lmin-$lmax.$i$suff
  qsub -q $q -e $qsubtmp -o $qsubtmp $subfile
@ i++
end

echo jobs submitted, start waiting

set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subr.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
while($njobsrunning > 0)
  sleep 60
  set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subr.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
end

#check for errors here

set errlist1 = `grep -Hv 0 dscp.exitstatus.* | awk -F '[.:]' '{print $3}'`
set errlist2 = `grep -Hic error dscp.log.* | grep -v :0 | awk -F '[.:]' '{print $3}'`
set errlist = `echo $errlist1 $errlist2 | sed s/" "/"\n"/g | sort -n | uniq`

if ($#errlist) then
  echo some jobs fail: $errlist
  exit 1
endif

echo successful completion

rm parms.tmp script.parms

exit 0

Karen Tian
Powered by
ViewCVS 0.9.4