#!/bin/sh

# **************************** LICENSE START ***********************************
#
# Copyright 2013 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 ************************************

set -x
print_err()
{
	echo ${text_ERR}  $* >> "${f_LOG}"
} 

text_ERR="Script `basename $0` FAILED> "

#Get args
if [ $# -ne 2 ] ; then
    echo "Invalid number of arguments specified for script $0 ! (" $# " instead of 2)"
    exit 1
fi

f_VDF=$1
f_LOG=$2

#Source the vapor setup script
vapor_script="${MV_VAPOR_BIN}"/vapor-setup.sh

if [ ! -f "$vapor_script"  ] ; then
	print_err "VAPOR script not found at: " $vapor_script
	# on Mac OS X there is no 'bin' directory, so lets try again ...
    vapor_script="${MV_VAPOR_HOME}"/vapor-setup.sh
    if [ ! -f "$vapor_script"  ] ; then
	  print_err "VAPOR script also not found at: " $vapor_script
	  exit 1
	fi
fi

#Source the vapor setup script
. "$vapor_script"

#Start up vapor 
vaporgui "$f_VDF" &

exit 0

