#!/bin/sh
# ----------------------------------------------------------------------
#  PROGRAM: PWgui
#  PURPOSE: tries to be a GUI for the PWscf
# ----------------------------------------------------------------------
#  Anton Kokalj
#  Jozef Stefan Institute, Ljubljana, Slovenia
#  INFM DEMOCRITOS National Simulation Center, Trieste, Italy
#  Email: Tone.Kokalj@ijs.si
# ======================================================================
#  Copyright (c) 2003--2004 Anton Kokalj
# ======================================================================
#
#
# This file is distributed under the terms of the GNU General Public
# License. See the file `COPYING' in the root directory of the present
# distribution, or http://www.gnu.org/copyleft/gpl.txt .
#
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT.  IN NO EVENT SHALL ANTON KOKALJ BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

if test "x`type readlink`" = "x"; then
    # no readlink cmd; make a function-substitute
    readlink() {
        echo `ls -l $1 | awk '{print $NF}'`
    }
fi

pathname() {
    file=`type -p $1`
    if test $? -gt 0; then
        file=`which $1`
        if test $? -gt 0; then
            # give-up
            file=$1
        fi
    fi
    echo $file
}

pathdir() {
    file=`pathname $1`
    
    while test -h $file; do  
        file=`readlink $file`
    done

    dir=`dirname $file`
    ( cd $dir; pwd )
}

if [ -z "$PWGUI" ]; then
    # try to guess the PWGUI value
     export PWGUI=`pathdir $0`
fi


echo "
 ==================================================
  This is PWgui version: `cat $PWGUI/VERSION`
 --------------------------------------------------
"
if [ -d $PWGUI/bin ]; then
    echo "
 PWgui: using the \"$PWGUI/bin/itkwish\" interpreter
"
    $PWGUI/bin/itkwish $PWGUI/pwgui.tcl
else
    echo "
 PWgui: using the system default \"tclsh\" interpreter
"
    tclsh $PWGUI/pwgui.tcl
fi
