#!/bin/ksh

# **************************** LICENSE START ***********************************
#
# Copyright 2012 ECMWF and INPE. This software is distributed under the terms
# of the Apache License version 2.0. In applying this license, ECMWF does not
# waive the privileges and immunities granted to it by virtue of its status as
# an Intergovernmental Organization or submit itself to any jurisdiction.
#
# ***************************** LICENSE END ************************************

#                                                             (vk may08)
# Log Metview trajectory model usage...
#

#-- do not let this script crash the master script!
set +e

#-- log only at ECMWF and not on High Performance Computers
if [ $WMO_SITE_NR = 098 -a $OS != hpcf ]
then
   #-- modify here the path to your own usage file
   MV_TRAJ_LOG="/home/graphics/cgx/public/Metview_traj_log"

   #-- first letter of runmode: 'i' or 'b'
   MV_MODE=`echo $METVIEW_MODE | cut -c1`

   if [ -f $MV_TRAJ_LOG ]
   then
      #-- try $USER first, if nothing then try $LOGNAME
      MVUSERID=$USER
      [ "$MVUSERID" = "" ] && MVUSERID=$LOGNAME
      [ "$MVUSERID" = "" ] && MVUSERID="???"

      #-- write a line into the log file
      echo "`date -u '+%d.%m.%Y %R'`; $MVUSERID; $MV_MODE; `hostname`; `cat $METVIEW_DIR_SHARE/app-defaults/MvTitleBarVersionText`" >> $MV_TRAJ_LOG

   else
      echo "Trajectory statistics file not found: $MV_TRAJ_LOG"
   fi
fi

set -e
