#!/bin/bash # # Given a tarred restart file, puts in on the local repository # # Author: F. Massonnet # Date : November 2016 set -o nounset set -o errexit set -x if [ $# == 0 ] then echo "dispatch.bash restart-file.tar" echo "EXAMPLE: " echo "dispatch.bash /esnas/exp/nemo/original_files/a05p/restart_files/a05p/19580101/fc00/restarts/RESTO_a05p_19580101_fc00_32_19890101-19891231.tar" echo "" exit fi rfile=$1 workdir=/scratch/Earth/$USER/TMP_24881 mkdir -p $workdir echo "WORKDIR >>>>> $workdir <<<<<<" if [ ! -f $rfile ] then echo "$rfile not found" exit fi # Obtain some information... fbase=`basename $rfile` exp=$(echo $fbase | cut -d'_' -f 2) sdate=$(echo $fbase | cut -d'_' -f 3) memb=$(echo $fbase | cut -d'_' -f 4) chunk=$(echo $fbase | cut -d'_' -f 5) runperiod=$(echo $fbase | cut -d'_' -f 6) runperiod=${runperiod%.tar} # remove the .tar endperiod=$(echo $runperiod | cut -d'-' -f 2) #tar xf $rfile -C $workdir # Check whether the restarts are rebuilt or not. If not, stop -- not coded yet nfiles_oce=`ls $workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_oce*.nc | wc -l` nfiles_ice=`ls $workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_ice*.nc | wc -l` if [ $nfiles_oce != 1 ] || [ $nfiles_ice != 1 ] then echo "Either the ocean or the ice restart files are not rebuilt" echo "Aborting, for now rebuilding outside HPC is not possible" exit fi fileoce=$workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_oce.nc fileice=$workdir/NEMO_Restart_${chunk}/${exp}_????????_restart_ice.nc # Get grid information nx=`ncdump -h $fileoce | grep "x =" | awk {'print $3'}` ny=`ncdump -h $fileoce | grep "y =" | awk {'print $3'}` nz=`ncdump -h $fileoce | grep "z =" | awk {'print $3'}` if [ $nx = 362 ] && [ $ny = 292 ] then grid=ORCA1 else echo "Not coded yet, to add" exit fi # Get sea ice model information. Looking for variable a_i_htc1 which is LIM3-indicative if [ `ncdump -h $fileice | grep a_i_htc1 | wc -l` != 0 ] then seaicemodel=LIM3 else echo "sea ice model unknown, or maybe LIM2?" fi # Create output directory for ocean and ice if [ ! -d /esnas/releases/ic/ocean/ORCA1L75 ] then echo "Configuration does not exist: ${grid}L${nz}" echo "There must be an error." exit fi # Do the ocean mkdir -p /esnas/releases/ic/ocean/${grid}L${nz}/${exp} fileout=/esnas/releases/ic/ocean/${grid}L${nz}/${exp}/${exp}_${memb}_${endperiod}_restart.nc cp $fileoce $fileout chmod 777 $fileout gzip -v $fileout # Do the ice mkdir -p /esnas/releases/ic/ice/${grid}_${seaicemodel}/${exp} fileout=/esnas/releases/ic/ice/${grid}_${seaicemodel}/${exp}/${exp}_${memb}_${endperiod}_restart_ice.nc cp $fileice $fileout chmod 777 $fileout gzip -v $fileout