#!/bin/bash -f
# set -vx
#
lst_rev () {
    CFGLST=`ls $1 | sort -u -r ` 
    CONFIG=$2
    ALLLST=${@:3}
    nrevall=`echo $ALLLST | wc -w`
    nrevcfg=`echo $CFGLST | wc -w`
    echo ""
    printf "%-27s : " $CONFIG
    irev=1
    irevcfg=1
    while [[ $irev -le $nrevall ]] ; do
       rev=`echo $ALLLST | cut -d\  -f ${irev}`
       #while [[ $irevcfg -le $nrevcfg ]] ; do
          cfgrev=`echo $CFGLST | cut -d\  -f ${irevcfg}`
          if [[ $cfgrev -eq $rev ]] ; then
             printf "%-5s  " $rev
             irevcfg=$((irevcfg+1))
          else
             printf "%-5s  " "*****" 
          fi
       #done
       irev=$((irev+1))
    done
}

  . ./param.cfg

  mach=${COMPILER}
  NEMO_VALID=${NEMO_VALIDATION_DIR}
 
 # list of all revision available
 DIRLST='';for dir in `find NEMO_VALIDATION -maxdepth 3 -mindepth 3` ; do REV=`basename $dir`; DIRLST="$DIRLST $REV"; done
 DIRLST=`echo $DIRLST | grep -o -E '\w+' | sort -u -r `

 # start checking
 echo ""
 printf " List of all avail. rev. is : "
 for dir in `echo $DIRLST`; do printf "%5s  " $dir ; done
 printf "\n"
# printf "%27s %${nrev}s" "" $DIRLST
 echo ""
 echo "   !---- check revision available for each configuration ----!   "
 for CONFIG in WGYRE_PISCES_ST WORCA2_ICE_PISCES_ST WORCA2_OFF_PISCES_ST WAMM12_ST WORCA2_SAS_ICE_ST WAGRIF_DEMO_ST WSPITZ12_ST WISOMIP_ST WOVERFLOW_ST WLOCK_EXCHANGE_ST WVORTEX_ST WICE_AGRIF_ST 
 do
    DIR=${NEMO_VALIDATION_DIR}/${CONFIG}/${COMPILER}
    lst_rev $DIR $CONFIG $DIRLST
 done
 printf "\n"
 printf "\n"
#
exit
