# $Id: env_gate.csh,v 1.18 2004/05/06 07:36:54 fmayet Exp $
# $Log: env_gate.csh,v $
# Revision 1.18  2004/05/06 07:36:54  fmayet
# *** empty log message ***
#
# Revision 1.17  2004/04/23 13:00:23  ccomtat
# Remove GATEHOME definition. Should be done in login script
#
# Revision 1.16  2004/04/23 12:57:25  ccomtat
# Check that G4VERSION is defined
# G4VERSION4, G4VERSION5_1, and G4VERSION5_2 are defined according to G4VERSION
#
# Revision 1.15  2003/08/14 09:48:17  lsimon
# remove LMF_DETECTOR_COMPTON variable
#
# Revision 1.14  2003/08/06 16:23:36  gsantin
# new way to set the Geant4 version
#
# Revision 1.13  2003/06/18 15:22:56  lsimon
# LMF is able or not to store crystal compton
#
# Revision 1.12  2003/06/16 16:36:37  dstrul
# Changes in the way the variables ROOTSYS and GATEHOME are set and handled
#
# Revision 1.11  2003/05/15 17:23:29  dstrul
# Fix for compatibility with G4.5.1: added environment variable G4VERSION5_1
#
# Revision 1.10  2003/05/04 15:40:40  dstrul
# Fix for case where G4INSTALL is undefined
#
# Revision 1.9  2003/04/11 13:53:26  gsantin
# first part of the migration to Geant4.5.0
#
# Revision 1.8  2003/03/12 12:39:11  ccomtat
# comment GATEHOME definition
#
# Revision 1.7  2003/03/04 08:12:09  ccomtat
# correct bug in if (ROOTSYS) then
#
# Revision 1.6  2003/02/07 12:30:36  ccomtat
# Add ECAT7 I/O and GATEHOME definition
#
# Revision 1.5  2002/10/04 17:00:42  gsantin
# added the ROOT libs to LD_LIBRARY_PATH
#
# Revision 1.4  2002/08/30 11:53:00  dstrul
# G4WORKDIR changed from the product of pwd to .
#
# Revision 1.3  2002/08/07 15:34:02  dstrul
# Slightly clarified the meaning of the ROOT-related options
#
# Revision 1.2  2002/08/07 15:06:16  dstrul
# New commented, portable (hopefully) version of the configuration script
#
# Revision 1.1  2002/07/27 21:13:54  dstrul
# Renamed env.csh into env_gate.csh


########### Comments
#
# This script performs two tasks:
# 1. it launches the Geant4 configuration script
# 2. it defines the environment variables required by GATE
#
# The script assumes two prerequisites:
# 1. that the user has already defined the variable G4INSTALL
# 2. that there is a configuration script 'env.csh' in the directory $G4INSTALL
# 
# You will need to make sure that both conditions are met before you can use this script 
#
###########



########### Geant4 configuration stage
#
# In the section below, we make sure that we have access to a script
# 'env.csh' in the directory $G4INSTALL, then launch this script
#
# If you have configured Geant4 by some other mean, you can actually 
# skip this stage and go directly to the Gate configuration stage 
#
##########

# We test that the variables G4INSTALL ans G4VERSION are set 
if [ -z $G4INSTALL ] ; then
    #echo "The environment variable G4INSTALL is not defined yet."
    #echo "You must define G4INSTALL before you can configure (and compile) GATE."
    #echo "Aborting"
    exit
else
    if [ -z $G4VERSION ] ; then
	#echo "The environment variable G4VERSION is not defined yet."
	#echo "You must define G4VERSION before you can configure (and compile) GATE."
	#echo "Aborting"
	exit
    fi
fi
export G4V=`echo ${G4VERSION} | cut -c 1-3`

#echo "The current value of G4INSTALL is: ${G4INSTALL}"
#echo "The current value of G4VERSION is: ${G4VERSION}"
#echo "Geant4 release number = ${G4V}"
#echo ""
#echo "Launching Geant4 configuration script "$G4INSTALL"/env.csh"
#echo ""

# We test that there truly is a directory $G4INSTALL
if [ ! -d $G4INSTALL ] ; then
    #echo "This does not seem to be a valid directory."
    #echo "You must define G4INSTALL before you can configure (and compile) GATE."
    #echo "Aborting"
    exit
fi

# We test that there is a Geant4 configuration script 'env.csh' in the directory $G4INSTALL
if [ ! -f $G4INSTALL"/env.sh" ] ; then
    #echo "I could not find a valid Geant4 script file env.csh in "$G4INSTALL
    #echo "You must provide a path with a valid Geant4 configuration script env.sh."
    #echo "Aborting"
    exit
fi

# Launch the Geant4 configuration script
#source $G4INSTALL"/env.sh"

########### End of Geant4 configuration stage


########### Gate configuration stage
#
# In the section below, we configure the GATE environment variables
# Those are essentially related to the various data-output options
#
# Most options can probably be left as they are
# However, you may need to check the variables G4ANALYSIS_USE_ROOT and
# G4ANALYSIS_USE_ROOT_PLOTTER, since both variables enable options that rely 
# on the presence of the ROOT libraries. If these libraries are not installed on 
# your system, you need to disable these options (i.e. comment the lines out)
#
##########

#echo ""
#echo "Configuring GATE options"
#echo ""

# Set the working directories
export G4WORKDIR='.'
#echo "G4WORKDIR set to $G4WORKDIR"
export G4TMP=$G4WORKDIR"/tmp"
#echo "G4TMP set to $G4TMP"
export G4BIN=$G4WORKDIR"/bin"
#echo "G4BIN set to $G4BIN"

# Enable the use of analysis and data-output 
# This line should normally always be left as it is
export G4ANALYSIS_USE=1
#if [ $G4ANALYSIS_USE ] ; then
    #echo "Data analysis and output features enabled"
#else
    #echo "Data analysis and output features disabled"
#fi


# Enable the use of the ASCII output file
# Comment this line if you want to disable this output (to speed-up the simulations for instance)
export G4ANALYSIS_USE_FILE=1
#if [ $G4ANALYSIS_USE_FILE ] ; then
    #echo "Ascii data output enabled"
#else
    #echo "Ascii data output disabled"
#fi


# We check whether the ROOT home-directory variable has been set
# If that's the case, we assume that ROOT is installed on this system and enable 
# the ROOT-based data output and plotter
if [ $ROOTSYS ] ; then
  # Enable the use of ROOT-based features (data output and optionally plotting)
  # Comment this line if you don't want to use ROOT 
    export G4ANALYSIS_USE_ROOT=1
  # Enable the use of the ROOT-based real-time plotter
  # Comment this line if you don't want to use the ROOT plotter
  # setenv G4ANALYSIS_USE_ROOT_PLOTTER    1
    unset G4ANALYSIS_USE_ROOT_PLOTTER
  # Add the path for the ROOT shared libraries if not yet done  
    if [ -d $ROOTSYS/lib ] ; then
	if [ $LD_LIBRARY_PATH ] ; then
	    #echo "Checking your LD_LIBRARY_PATH variable..."
	    #echo $LD_LIBRARY_PATH | grep $ROOTSYS/lib > /dev/null
	    if [ $status ] ; then
		#echo " ==> OK: ${ROOTSYS}/lib added to your LD_LIBRARY_PATH"  
		export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ROOTSYS}/lib
#	    else
		#echo " ==> OK: ${ROOTSYS}/lib is already in your LD_LIBRARY_PATH"
	    fi
	else
	    #echo " ==> ${ROOTSYS}/lib added to your LD_LIBRARY_PATH"  
	    export LD_LIBRARY_PATH=${ROOTSYS}/lib
	fi
#    else
	#echo "WARNING: there is no ${ROOTSYS}/lib directory"
	#echo "         you should check that ROOT shared libraries are included in LD_LIBRARY_PATH"
    fi
fi  
#if [ ${G4ANALYSIS_USE_ROOT} ] ; then
    #echo "Use of ROOT enabled"
#else
    #echo "Use of ROOT disabled"
#fi
#if [ ${G4ANALYSIS_USE_ROOT_PLOTTER} ] ; then
    #echo "ROOT real-time plotter enabled"
#else
    #echo "ROOT real-time plotter disabled"
#fi

# We check whether the LMF home-directory variable has been set
# If that's the case, we assume that the LMF library is installed on this system and enable 
# the LMF data output
if [ ${LMF_HOME} ] ; then
  # Enable the use of the LMF output file
  # Comment this line if you want to disable this output (to speed-up the simulations for instance)
    export GATE_USE_LMF=1 
fi
#if [ ${GATE_USE_LMF} ] ; then
    #echo "LMF data output enabled"
#else
    #echo "LMF data output disabled"
#fi


# We check wheter the ECAT7 home-directory variable has been set
# If that's the case, we assume that the ECAT7 library is installed on this
# system and enable the ECAT7 data output
if [ ${ECAT7_HOME} ] ; then
    if [ -d ${ECAT7_HOME} ] ; then
    # Enable the use of the ECAT7 output file
	export GATE_USE_ECAT7=1
    else
	#echo "WARNING: the ECAT7 home directory ${ECAT7_HOME} does not exist in your system"  
	if [ ${GATE_USE_ECAT7} ] ; then
	    unset GATE_USE_ECAT7
	fi
    fi
fi  
#if [ ${GATE_USE_ECAT7} ] ; then
    #echo "ECAT7 data output enabled"
#else
    #echo "ECAT7 data output disabled"
#fi

# Enable the use of ntuples 
# This line probably is obsolete, as this variable does not seem to be used anywhere
export G4ANALYSIS_USE_NTUPLE=1

# $GATEHOME
# By setting this variable, Gate can be run from any directory
if [ ${GATEHOME} ] ; then
    #echo "GATEHOME is set to ${GATEHOME}"
    if [ -d ${GATEHOME} ] ; then
	#echo "Checking your path variable..."
	#echo $path | grep ${GATEHOME}/bin/${G4SYSTEM} > /dev/null
	if [ $status ] ; then
	    #echo " ==> OK: ${GATEHOME}/bin/${G4SYSTEM} added to your path variable"
	    export path=${GATEHOME}/bin/${G4SYSTEM}:$path
#	else
	    #echo " ==> OK: ${GATEHOME}/bin/${G4SYSTEM} is already in your path variable"
	fi
    else
	#echo "WARNING: your GATEHOME variable refers to a non-existent directory"
	unset GATEHOME
    fi
#else
    #echo "WARNING: variable GATEHOME is not set"
fi

if [ ${G4V} == "4.0" ] ; then 
    export G4VERSION4=1
    unset G4VERSION5_1
    unset G4VERSION5_2
else
    if [ ${G4V} == "4.1" ] ; then
	export G4VERSION4=1
	unset G4VERSION5_1
	unset G4VERSION5_2
    else
	if [ ${G4V} == "5.0" ] ; then
	    unset G4VERSION4 
	    unset G4VERSION5_1
	    unset G4VERSION5_2
	else
	    if [ ${G4V} == "5.1" ] ; then
		unset G4VERSION4
		export G4VERSION5_1=1
		unset G4VERSION5_2
	    else
		if [ ${G4V} == "5.2" ] ; then
		    unset G4VERSION4
		    export G4VERSION5_1=1
		    export G4VERSION5_2=1
		else
		    #echo "ERROR: unsupported Geant4 release number ${G4V}"
		    #echo "Aborting"
		    exit
		fi
	    fi
	fi
    fi
fi

# $G4VERSION4
# by setting this variable before the compilation, GATE is compatible 
# with Geant4.4.0 / Geant4.4.1
# by un-setting this variable before the compilation, GATE is compatible 
# with Geant4.5.0 and higher
# NB: to switch from one G4 version to the other, it is suggested to 
# - open a new terminal (to avoid problems with former environment variable settings)
# - set the G4INSTALL and G4VERSION variables to the new one
# - source env_gate.csh (this should source also the new G4 env.csh)
# - recompile the complete GATE package
#if [ ${G4VERSION4} ] ; then
    #echo "G4VERSION4 is set: GATE will use the code compatible with Geant4 releases 4.0 / 4.1"
#else
    #echo "G4VERSION4 is not set: GATE will use the code compatible with Geant4 releases >= 5.0 "
#fi

# $G4VERSION5_1
# by setting this variable before the compilation, GATE is compatible 
# with Geant4.5.1 and higher
# by un-setting this variable before the compilation, GATE is compatible 
# with Geant4.4.X and Geant4.5.0 
# NB: to switch from one G4 version to the other, it is suggested to 
# - open a new terminal (to avoid problems with former environment variable settings)
# - set the G4INSTALL and G4VERSION variables to the new one
# - source env_gate.csh (this should source also the new G4 env.csh)
# - recompile the complete GATE package
#if [ ${G4VERSION5_1} ] ; then
    #echo "G4VERSION5_1 is set: GATE will use the run manager compatible with Geant4 releases >= 5.1"
#else
    #echo "G4VERSION5_1 is not set: GATE will use the run manager compatible with Geant4 releases 4.0 / 4.1 / 5.0"
#fi

# $G4VERSION5_2
# by setting this variable before the compilation, GATE is compatible 
# with Geant4.5.2
# by un-setting this variable before the compilation, GATE is compatible 
# with Geant4.4.X, Geant4.5.0, and Geant4.5.1 
# NB: to switch from one G4 version to the other, it is suggested to 
# - open a new terminal (to avoid problems with former environment variable settings)
# - set the G4INSTALL and G4VERSION variables to the new one
# - source env_gate.csh (this should source also the new G4 env.csh)
# - recompile the complete GATE package
#if [ ${G4VERSION5_2} ] ; then
    #echo "G4VERSION5_2 is set: GATE is compatible with the Geant4 release 5.2"
#else
    #echo "G4VERSION5_2 is not set: GATE is compatible with the G4 releases 4.0 / 4.1 / 5.0 / 5.1"
#fi

#echo ""
#echo "Done"
#echo ""
