#!/bin/csh
#PBS -N fizhiT3
#PBS -l ncpus=24
#PBS -l walltime=08:00:00
#PBS -j oe
#PBS -o /nobackup2b/molod/fizhi-cs-32x32x40-hfac02/input/stdout
########PBS -q normal
#PBS -V

echo 'start'
#----------------------------------------------
set namPBS=fizhiT3
set runDir=/nobackup2b/molod/fizhi-cs-32x32x40-hfac02/input
set executable=/nobackup2b/molod/fizhi-cs-32x32x40-hfac02/build/mitgcmuv
#-------------------
cd $runDir

#------
limit stacksize unlimited
module purge
module load modules scsl.1.6.1.0 intel-comp.9.1.039 mpt.1.12.0.nas pd-netcdf.3.6.0-p1
#------

set its=`egrep 'nIter0' data | sed 's/ nIter0=//'| sed 's/,$//'`

#-------------------
 mpirun -np 24 $executable
#-------------------
echo 'Copying datetime file to datetime0 - time is: ' `cat datetime`
cp datetime datetime0

set ite=`grep CHECKPOINT STDOUT.0000 | grep ckptA | sed 's/(PID.TID 0000.0001) %CHECKPOINT//' | sed 's/ //g' | sed 's/ckptA//'`
set nitPick = `/u/molod/bin/add0upto10c $ite`
if ( -f pickup.ckptA.001.001.data ) then
 echo 'file:' pickup.ckptA.001.001.data 'exist'
#- prepare new submission :
 echo 'Copy pickup ckptA files to pickup ' $nitPick 'files'
   mv pickup.ckptA.001.001.data pickup.$nitPick.001.001.data
   mv pickup.ckptA.002.001.data pickup.$nitPick.002.001.data
   mv pickup.ckptA.003.001.data pickup.$nitPick.003.001.data
   mv pickup.ckptA.004.001.data pickup.$nitPick.004.001.data
   mv pickup.ckptA.005.001.data pickup.$nitPick.005.001.data
   mv pickup.ckptA.006.001.data pickup.$nitPick.006.001.data
   mv pickup.ckptA.007.001.data pickup.$nitPick.007.001.data
   mv pickup.ckptA.008.001.data pickup.$nitPick.008.001.data
   mv pickup.ckptA.009.001.data pickup.$nitPick.009.001.data
   mv pickup.ckptA.010.001.data pickup.$nitPick.010.001.data
   mv pickup.ckptA.011.001.data pickup.$nitPick.011.001.data
   mv pickup.ckptA.012.001.data pickup.$nitPick.012.001.data
   mv pickup.ckptA.013.001.data pickup.$nitPick.013.001.data
   mv pickup.ckptA.014.001.data pickup.$nitPick.014.001.data
   mv pickup.ckptA.015.001.data pickup.$nitPick.015.001.data
   mv pickup.ckptA.016.001.data pickup.$nitPick.016.001.data
   mv pickup.ckptA.017.001.data pickup.$nitPick.017.001.data
   mv pickup.ckptA.018.001.data pickup.$nitPick.018.001.data
   mv pickup.ckptA.019.001.data pickup.$nitPick.019.001.data
   mv pickup.ckptA.020.001.data pickup.$nitPick.020.001.data
   mv pickup.ckptA.021.001.data pickup.$nitPick.021.001.data
   mv pickup.ckptA.022.001.data pickup.$nitPick.022.001.data
   mv pickup.ckptA.023.001.data pickup.$nitPick.023.001.data
   mv pickup.ckptA.024.001.data pickup.$nitPick.024.001.data
   mv pickup.ckptA.001.001.meta pickup.$nitPick.001.001.meta
   mv pickup.ckptA.002.001.meta pickup.$nitPick.002.001.meta
   mv pickup.ckptA.003.001.meta pickup.$nitPick.003.001.meta
   mv pickup.ckptA.004.001.meta pickup.$nitPick.004.001.meta
   mv pickup.ckptA.005.001.meta pickup.$nitPick.005.001.meta
   mv pickup.ckptA.006.001.meta pickup.$nitPick.006.001.meta
   mv pickup.ckptA.007.001.meta pickup.$nitPick.007.001.meta
   mv pickup.ckptA.008.001.meta pickup.$nitPick.008.001.meta
   mv pickup.ckptA.009.001.meta pickup.$nitPick.009.001.meta
   mv pickup.ckptA.010.001.meta pickup.$nitPick.010.001.meta
   mv pickup.ckptA.011.001.meta pickup.$nitPick.011.001.meta
   mv pickup.ckptA.012.001.meta pickup.$nitPick.012.001.meta
   mv pickup.ckptA.013.001.meta pickup.$nitPick.013.001.meta
   mv pickup.ckptA.014.001.meta pickup.$nitPick.014.001.meta
   mv pickup.ckptA.015.001.meta pickup.$nitPick.015.001.meta
   mv pickup.ckptA.016.001.meta pickup.$nitPick.016.001.meta
   mv pickup.ckptA.017.001.meta pickup.$nitPick.017.001.meta
   mv pickup.ckptA.018.001.meta pickup.$nitPick.018.001.meta
   mv pickup.ckptA.019.001.meta pickup.$nitPick.019.001.meta
   mv pickup.ckptA.020.001.meta pickup.$nitPick.020.001.meta
   mv pickup.ckptA.021.001.meta pickup.$nitPick.021.001.meta
   mv pickup.ckptA.022.001.meta pickup.$nitPick.022.001.meta
   mv pickup.ckptA.023.001.meta pickup.$nitPick.023.001.meta
   mv pickup.ckptA.024.001.meta pickup.$nitPick.024.001.meta
   mv pickup_fizhi.ckptA.001.001.data pickup_fizhi.$nitPick.001.001.data
   mv pickup_fizhi.ckptA.002.001.data pickup_fizhi.$nitPick.002.001.data
   mv pickup_fizhi.ckptA.003.001.data pickup_fizhi.$nitPick.003.001.data
   mv pickup_fizhi.ckptA.004.001.data pickup_fizhi.$nitPick.004.001.data
   mv pickup_fizhi.ckptA.005.001.data pickup_fizhi.$nitPick.005.001.data
   mv pickup_fizhi.ckptA.006.001.data pickup_fizhi.$nitPick.006.001.data
   mv pickup_fizhi.ckptA.007.001.data pickup_fizhi.$nitPick.007.001.data
   mv pickup_fizhi.ckptA.008.001.data pickup_fizhi.$nitPick.008.001.data
   mv pickup_fizhi.ckptA.009.001.data pickup_fizhi.$nitPick.009.001.data
   mv pickup_fizhi.ckptA.010.001.data pickup_fizhi.$nitPick.010.001.data
   mv pickup_fizhi.ckptA.011.001.data pickup_fizhi.$nitPick.011.001.data
   mv pickup_fizhi.ckptA.012.001.data pickup_fizhi.$nitPick.012.001.data
   mv pickup_fizhi.ckptA.013.001.data pickup_fizhi.$nitPick.013.001.data
   mv pickup_fizhi.ckptA.014.001.data pickup_fizhi.$nitPick.014.001.data
   mv pickup_fizhi.ckptA.015.001.data pickup_fizhi.$nitPick.015.001.data
   mv pickup_fizhi.ckptA.016.001.data pickup_fizhi.$nitPick.016.001.data
   mv pickup_fizhi.ckptA.017.001.data pickup_fizhi.$nitPick.017.001.data
   mv pickup_fizhi.ckptA.018.001.data pickup_fizhi.$nitPick.018.001.data
   mv pickup_fizhi.ckptA.019.001.data pickup_fizhi.$nitPick.019.001.data
   mv pickup_fizhi.ckptA.020.001.data pickup_fizhi.$nitPick.020.001.data
   mv pickup_fizhi.ckptA.021.001.data pickup_fizhi.$nitPick.021.001.data
   mv pickup_fizhi.ckptA.022.001.data pickup_fizhi.$nitPick.022.001.data
   mv pickup_fizhi.ckptA.023.001.data pickup_fizhi.$nitPick.023.001.data
   mv pickup_fizhi.ckptA.024.001.data pickup_fizhi.$nitPick.024.001.data
   mv pickup_fizhi.ckptA.001.001.meta pickup_fizhi.$nitPick.001.001.meta
   mv pickup_fizhi.ckptA.002.001.meta pickup_fizhi.$nitPick.002.001.meta
   mv pickup_fizhi.ckptA.003.001.meta pickup_fizhi.$nitPick.003.001.meta
   mv pickup_fizhi.ckptA.004.001.meta pickup_fizhi.$nitPick.004.001.meta
   mv pickup_fizhi.ckptA.005.001.meta pickup_fizhi.$nitPick.005.001.meta
   mv pickup_fizhi.ckptA.006.001.meta pickup_fizhi.$nitPick.006.001.meta
   mv pickup_fizhi.ckptA.007.001.meta pickup_fizhi.$nitPick.007.001.meta
   mv pickup_fizhi.ckptA.008.001.meta pickup_fizhi.$nitPick.008.001.meta
   mv pickup_fizhi.ckptA.009.001.meta pickup_fizhi.$nitPick.009.001.meta
   mv pickup_fizhi.ckptA.010.001.meta pickup_fizhi.$nitPick.010.001.meta
   mv pickup_fizhi.ckptA.011.001.meta pickup_fizhi.$nitPick.011.001.meta
   mv pickup_fizhi.ckptA.012.001.meta pickup_fizhi.$nitPick.012.001.meta
   mv pickup_fizhi.ckptA.013.001.meta pickup_fizhi.$nitPick.013.001.meta
   mv pickup_fizhi.ckptA.014.001.meta pickup_fizhi.$nitPick.014.001.meta
   mv pickup_fizhi.ckptA.015.001.meta pickup_fizhi.$nitPick.015.001.meta
   mv pickup_fizhi.ckptA.016.001.meta pickup_fizhi.$nitPick.016.001.meta
   mv pickup_fizhi.ckptA.017.001.meta pickup_fizhi.$nitPick.017.001.meta
   mv pickup_fizhi.ckptA.018.001.meta pickup_fizhi.$nitPick.018.001.meta
   mv pickup_fizhi.ckptA.019.001.meta pickup_fizhi.$nitPick.019.001.meta
   mv pickup_fizhi.ckptA.020.001.meta pickup_fizhi.$nitPick.020.001.meta
   mv pickup_fizhi.ckptA.021.001.meta pickup_fizhi.$nitPick.021.001.meta
   mv pickup_fizhi.ckptA.022.001.meta pickup_fizhi.$nitPick.022.001.meta
   mv pickup_fizhi.ckptA.023.001.meta pickup_fizhi.$nitPick.023.001.meta
   mv pickup_fizhi.ckptA.024.001.meta pickup_fizhi.$nitPick.024.001.meta
   mv pickup_vegtiles.ckptA.001.001.data pickup_vegtiles.$nitPick.001.001.data
   mv pickup_vegtiles.ckptA.002.001.data pickup_vegtiles.$nitPick.002.001.data
   mv pickup_vegtiles.ckptA.003.001.data pickup_vegtiles.$nitPick.003.001.data
   mv pickup_vegtiles.ckptA.004.001.data pickup_vegtiles.$nitPick.004.001.data
   mv pickup_vegtiles.ckptA.005.001.data pickup_vegtiles.$nitPick.005.001.data
   mv pickup_vegtiles.ckptA.006.001.data pickup_vegtiles.$nitPick.006.001.data
   mv pickup_vegtiles.ckptA.007.001.data pickup_vegtiles.$nitPick.007.001.data
   mv pickup_vegtiles.ckptA.008.001.data pickup_vegtiles.$nitPick.008.001.data
   mv pickup_vegtiles.ckptA.009.001.data pickup_vegtiles.$nitPick.009.001.data
   mv pickup_vegtiles.ckptA.010.001.data pickup_vegtiles.$nitPick.010.001.data
   mv pickup_vegtiles.ckptA.011.001.data pickup_vegtiles.$nitPick.011.001.data
   mv pickup_vegtiles.ckptA.012.001.data pickup_vegtiles.$nitPick.012.001.data
   mv pickup_vegtiles.ckptA.013.001.data pickup_vegtiles.$nitPick.013.001.data
   mv pickup_vegtiles.ckptA.014.001.data pickup_vegtiles.$nitPick.014.001.data
   mv pickup_vegtiles.ckptA.015.001.data pickup_vegtiles.$nitPick.015.001.data
   mv pickup_vegtiles.ckptA.016.001.data pickup_vegtiles.$nitPick.016.001.data
   mv pickup_vegtiles.ckptA.017.001.data pickup_vegtiles.$nitPick.017.001.data
   mv pickup_vegtiles.ckptA.018.001.data pickup_vegtiles.$nitPick.018.001.data
   mv pickup_vegtiles.ckptA.019.001.data pickup_vegtiles.$nitPick.019.001.data
   mv pickup_vegtiles.ckptA.020.001.data pickup_vegtiles.$nitPick.020.001.data
   mv pickup_vegtiles.ckptA.021.001.data pickup_vegtiles.$nitPick.021.001.data
   mv pickup_vegtiles.ckptA.022.001.data pickup_vegtiles.$nitPick.022.001.data
   mv pickup_vegtiles.ckptA.023.001.data pickup_vegtiles.$nitPick.023.001.data
   mv pickup_vegtiles.ckptA.024.001.data pickup_vegtiles.$nitPick.024.001.data
 echo 'Change start iteration number for next run '
   cp STDOUT.0001 STDOUT.0001-$ite
   sed "s/ nIter0=$its/ nIter0=$ite/" data > data.tmp
   mv data.tmp data
   sleep 5
  qsub $runDir/runScript.columbia
else
 echo 'file:' pickup.ckptA.001.001.data 'do not exist !'
endif

exit
