#!/bin/csh
################################################################################
#    iGMT: Interactive Mapping of Geoscientific Datasets.                      #
#                                                                              #
#    Copyright (C) 1998 - 2000  Thorsten W. Becker, Alexander Braun            #
#                                                                              #
#    This program 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 2 of the License, or         #
#    (at your option) any later version.                                       #
#                                                                              #
#    This program 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.                              #
#                                                                              #
#    In addition, iGMT is not to be used for any military purposes or          #
#    for any other activities that are against the spirit as expressed         #
#    in the Student Pugwash Pledge (www.spusa.org/pugwash/pledge.html).        #
#                                                                              #
#    You should have received a copy of the GNU General Public License         #
#    along with this program; see the file COPYING.  If not, write to          #
#    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,          #
#    Boston, MA 02111-1307, USA.                                               #
#                                                                              #
################################################################################

set version = 1.2
echo "############################################################"
echo "iGMT version $version configuration script running"
echo 
echo "If this script fails, please follow the steps as described in the manual"
echo 
echo "Please note the variable name changes as documented in the NOTES.TXT file"
echo
# check for the default shell
echo -n "Do you have Korn-shell in the usual place (/bin/ksh)? (y/n) [y]: "
set answer = $<
if ($answer == "n" || $answer == "N") then
	echo Attempting to change all references to /bin/ksh.
	echo -n "Where is the Korn or Bash shell then (maybe in `which ksh`)? [`which ksh`]: "
	set answer = $<
	if ( $answer == "" ) then
	    set answer = `which ksh`;
	endif
	set string = "+/bin/ksh+$answer+g"
	perl -i -p -e s$string *.tcl igmt igmt_helper* img2latlongrd.batch
	echo "Changed all occurences of /bin/ksh to $answer"
else
	echo Leaving Korn shell in /bin/ksh as the default shell.
endif
echo

# check for the iGMT root directory

if ($?igmt_root) then
	echo iGMT root directory is set by environment variable \"\$igmt_root\" to $igmt_root
	if ( $igmt_root != `pwd` ) then
	    echo WARNING:
	    echo This appears to be different from our working directory \(`pwd`\),
	    echo which is also quite likely the iGMT root directory.
	    echo You will probably have to change the variable setting in your 
	    echo \".login\" or \".profile\" files. 
        endif
	set idir = $igmt_root
else
	echo iGMT root directory is not set by environment variable \"\$igmt_root\"
	echo Will attempt to hardwire the directory and write to \"igmt\"
	set idir = `pwd`
	echo -n "Is our working directory (the iGMT root directory) $idir? (y/n) [y]: "
	set answer = $<
	if ($answer == "n" || $answer == "N") then
		echo -n "What is the iGMT root directory then?: "
		set idir = $<
	endif
	
	perl -i -p -e s"+/home/becker/tcltk+$idir:h/+g" igmt
	echo Changed reference to iGMT root directory in \"igmt\" to $idir
endif

echo

# check for the location of the wish binary

echo Checking for the Tcl/Tk shell \"wish\" \(make sure it\'s the right version!\)
if ($?wish_cmd) then
	echo The Tcl/Tk wish command is set by environment variable \"\$wish_cmd\" to $wish_cmd
	if ( $wish_cmd != `which wish` ) then
	    echo WARNING:
	    echo This is different from the likely lcoation of \"wish\", `which wish`.
	    echo You might have to change the variable setting, most likely in your 
	    echo \".login\" or \".profile\" file.
	    echo You can determine if \"wish\" is in your path and where it is located by
	    echo typing \"which wish\" for csh or \"type wish\" for ksh.
	endif
else
	echo Tcl/Tk wish command is not set by environment variable \"\$wish_cmd\"
	echo Will attempt to hardwire this binary and write to \"igmt\"
	set wbin = `which wish`
	echo -n "Is the wish binary located in $wbin? (y/n) [y]: "
	set answer = $<
	if ($answer == "n" || $answer == "N") then
		echo -n "What is the right wish binary then?: "
		set wbin = $<
	endif
	perl -i -p -e s"+/usr/local/bin/wish+$wbin+g" igmt
	echo Changed reference to wish command in \"igmt\" to $wbin
endif


# check for the location of the GMT binaries

echo "Where are the GMT binaries located? (Include /)"
set gmtbins = $<
echo using $gmtbins as the GMT binary directory
echo adding a line to your igmt_siteconfig.tcl file
echo set higher_version_gmtbins $gmtbins >> $idir/igmt_siteconfig.tcl
echo set lower_version_gmtbins $gmtbins >> $idir/igmt_siteconfig.tcl
echo

echo Script done, iGMT should start up when you type $idir/igmt.
echo You might want to alias $idir/igmt to something shorter.
echo Should you experience any difficulties, reexpand the tar-file and
echo apply changes by hand as explained on the iGMT web page and in the
echo manual. Further changes to the iGMT default settings such as path
echo names to data files should be done by resetting variables from 
echo \"igmt_configure.tcl\" in a file \"igmt_siteconfig.tcl\" \(to be created\).
echo "############################################################"




