Skip to content
Snippets Groups Projects
subjob_cdosplit.sh 1.67 KiB
Newer Older
Guillaume S's avatar
Guillaume S committed
#!/bin/bash

#module purge
#module load cdo/2.2.0
#module list

set +xv


# ARGUMENTS
date_beg=$1
date_end=$2
nbday=$(( ($(date -d "${date_end}H00 + 1 day" +%s) - $(date -d "${date_beg}H00" +"%s") )/(60*60*24) ))
Guillaume S's avatar
Guillaume S committed
#var_list=( $(cdo showname ${fabl}) )
#var_list=( ${var_list[*]/"lsm"} )
var_list=( uwnd vwnd uhpg vhpg tpot humi )
var_nb=${#var_list[*]}
for d in $(seq -f "%02g" 0 $((nbday-1))); do

  # TIME
  date=$(date -d "${date_beg}H00 + ${d} days" +"%C%y%m%d")
  ym=${date:0:6}

  # DIRECTORIES & FILES
Guillaume S's avatar
Guillaume S committed
  pabl="${SCRATCH_DIR}/NC_${GRID/N/F}/${ym}/abl_L50Z10_${BASE_NAME}_${date}.nc"
  fabl=$(basename $pabl)
  dabl=$(dirname $pabl)

  file_nb=$( eval "ls ${dabl}/{$(tr ' ' ',' <<< ${var_list[*]})}_${fabl} 2>/dev/null" | wc -l )
  
  if [ ${file_nb} -lt ${var_nb} ]; then
  
    if [ -s ${pabl} ]; then
Guillaume S's avatar
Guillaume S committed
      while [ $(squeue -u $USER -h -t pending,running -r | wc -l) -ge 90 ]; do echo "sleeping..."; sleep 10; done
Guillaume S's avatar
Guillaume S committed
      sbatch --job-name=cdosplit_${date} --export=SCRATCH_DIR=${SCRATCH_DIR},BASE_NAME=${BASE_NAME} ${DIR_SRC}/job_cdosplit.sbatch ${date}
Guillaume S's avatar
Guillaume S committed
      echo "-CDO_SPLIT: ERROR: input files not found"; exit 1
    fi
  
  fi
  
  while [[ ${date} -eq ${date_end} && $(squeue -u $USER -h -t pending,running -r -o '%20j' | grep cdosplit_${ym} | wc -l) -gt 0 ]]; do echo "sleeping..."; sleep 10; done
  
  if [ ${date} -eq ${date_end} ]; then
Guillaume S's avatar
Guillaume S committed
    file_nb=$( eval "ls ${dabl%/*}/{${date_beg:0:6}..${date_end:0:6}}/{$(tr ' ' ',' <<< ${var_list[*]})}_${fabl/${date}.nc/*{${date_beg:6:2}..${date_end:6:2}}}.nc 2>/dev/null" | wc -l )
    if [ $((nbday*var_nb)) -eq ${file_nb} ]; then
Guillaume S's avatar
Guillaume S committed
      echo "-CDO_SPLIT: OK"
Guillaume S's avatar
Guillaume S committed
      echo "-CDO_SPLIT: ERROR"
Guillaume S's avatar
Guillaume S committed
  fi