#!/bin/bash
#set -x
set -o posix
#set -u
#set -e
#+
#
# ==================
# Flist_archfile.sh
# ==================
#
# --------------------------
# Check the compilation file
# --------------------------
#
# SYNOPSIS
# ========
#
# ::
#
#  $ Flist_archfile.sh Institute
#
#
# DESCRIPTION
# ===========
#
#
# List arch file available.
# The first line of each file in NEMO/ARCH directory is echoed.  
#
#
# EXAMPLES
# ========
#
# ::
#
#  $ ./Flist_archfile.sh 
#
#  $ ./Flist_archfile.sh CNRS
#
# TODO
# ====
#
# option debug
#
#
# EVOLUTIONS
# ==========
#
# $Id: Flist_archfile.sh 3198 2011-12-07 14:53:38Z rblod $
#
#
#
#   * creation
#
#-

if [ -n "$2" ]; then
shift
fi

echo "Available compilers for -m option :"
for file in  $(ls ${MAIN_DIR}/ARCH | grep fcm )
do
zvar1=${file#arch-}
zvar2=$(head -1 ${MAIN_DIR}/ARCH/$file)
#echo "${zvar1%.fcm} : ${zvar2#\#}"
printf "%-20s %s %-s\n" "${zvar1%.fcm}" : "${zvar2#\#}"
done


if [ "$1" == "all" ]; then
   for dir  in  $(ls ${MAIN_DIR}/ARCH | grep -v fcm )
   do 
      echo "Available compilers at ${dir} :"
      for file in  $(ls ${MAIN_DIR}/ARCH/${dir} | grep  fcm )
      do
      zvar1=${file#arch-}
      zvar2=$(head -1 ${MAIN_DIR}/ARCH/${dir}/$file)
      #echo "${zvar1%.fcm} : ${zvar2#\#}"
      printf "%-20s %s %-s\n" "${zvar1%.fcm}" : "${zvar2#\#}"
      done
   done
else
   if [ -d ${MAIN_DIR}/ARCH/${1} ]; then
      echo "Available compilers at $1 :"
      for file in  $(ls ${MAIN_DIR}/ARCH/$1 | grep fcm )
      do
      zvar1=${file#arch-}
      zvar2=$(head -1 ${MAIN_DIR}/ARCH/${1}/$file)
      #echo "${zvar1%.fcm} : ${zvar2#\#}"
      printf "%-20s %s %-s\n" "${zvar1%.fcm}" : "${zvar2#\#}"
      done
   fi
fi