#!/bin/ksh
#--------------------------------------------------------------------------------#
# This file is part of PALM.
#
# PALM is free software: you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# PALM. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 1997-2012  Leibniz University Hannover
#--------------------------------------------------------------------------------#
#
# Current revisions:
# -----------------
#
# Former revisions:
# -----------------
# $Id: nc2vdf 1068 2012-11-26 10:15:04Z hoffmann $
#
# 1067 2012-11-26 10:13:14Z maronga
# Code put under GNU GPL
#
# Description:
# ------------
# Starting script for nc2vdf. The script does only work on hicegate2, bicegate2,
# uv as well as on the server at imuk.
#------------------------------------------------------------------------------#

    check_muk=false
    check_hlrn=false
    check_workstation=false
    sys="unknown"


    echo "*** checking hostname..."
    if [ $(expr "$HOSTNAME" : ".*muk.uni-hannover.de") -gt 0 ]
    then
       check_muk=true
    fi

    if [ $(expr "$HOSTNAME" : ".*hicegate2") -gt 0 ]
    then
       check_hlrn=true
    fi
    if [ $(expr "$HOSTNAME" : ".*bicegate2") -gt 0 ]
    then
       check_hlrn=true
    fi
    if [ $(expr "$HOSTNAME" : ".*huv") -gt 0 ]
    then
       check_hlrn=true
    fi
    if [ $(expr "$HOSTNAME" : ".*buv") -gt 0 ]
    then
       check_hlrn=true
    fi
#    if [ $(expr "$HOSTNAME" : "") -eq 1 ] ### insert $HOSTNAME of your workstation here if you are not running vapor on one of the systems above
#    then
#       check_workstation=true
#    fi



    if [ $check_muk == "true" ]
    then
       sys="IMUK"
       . /muksoft/packages/vapor/2.1.0/bin/vapor-setup.sh
    fi

    if [ $check_hlrn == "true" ]
    then
       sys="HLRN"
       . /usr/share/modules/init/ksh
       module load vapor
       module load ncl
    fi
    
    if [ $check_workstation == "true" ]
    then
       sys="workstation"
    fi

    if [ $sys == "unknown" ]
    then
       echo "+++ unknown system."
       #exit 0
    else
       echo "*** nc2vdf will execute at $sys"
    fi

    if which nc2vdf.ncl >/dev/null; then
       ncl $PALM_BIN/nc2vdf.ncl "inputfile= \"$1\""
    else
       echo "  +++ nc2vdf.ncl not found."
    fi