#! /bin/sh
#+
#
# .. program:: plogd.sh
#
# .. _plogd.sh:
#
# =====================================================================================================
# plogd.sh -- prints the most recent release of :file:`${TROPFLUX_LOG}/{action}.log.{YYYYMMDDTHHMMSSZ}`
# =====================================================================================================
#
# SYNOPSIS
# ========
#
# ::
#
#  $ plogd.sh action
#
#
# DESCRIPTION
# ===========
#
# ``plogd.sh`` prints the most recent release of :file:`${TROPFLUX_LOG}/{action}.log.{YYYYMMDDTHHMMSSZ}`.
#
# Print is done on the default printer.
#
# SEE ALSO
# ========
#
# :ref:`tropflux_profile.sh`
#
# :ref:`dlogd.sh`
#
# :ref:`elogd.sh`
#
# :ref:`tlogd.sh`
#
# EVOLUTIONS
# ==========
#
# - fplod 20101213T145950Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * creation
#
#-
#
set -u
system=$(uname)
case "${system}" in
   AIX|IRIX64)
      echo " www : no specific posix checking"
   ;;
   *)
      set -o posix
;;
esac
unset system
#
LANG=POSIX
#
command=$(basename ${0})
#
if [ "${1}" = "" ]
then
   echo "${command} : eee : 1st parameter missing" >&2
   exit 1
fi
# test if a2ps available
tool=a2ps
type ${tool} 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
   echo "${command} : eee : ${tool} unavailable" >&2
   exit 4
fi
unset tool
unset status
#
log=$(find ${TROPFLUX_LOG} -name "${1}.log.????????T??????Z" | sort | \
tail -n 1)
tmp=${?}
if [ ${tmp} -eq 0 ]
then
   if [ "${log}" = "" ]
   then
      echo "${command} : eee : no release of ${TROPFLUX_LOG}/${1}.log" >&2
      exit 1
   else
      # printing
      a2ps --print-anyway=1 ${log}
      exit 0
   fi
else
   exit 1
fi
