Index: /issm/trunk-jpl/etc/environment.sh
===================================================================
--- /issm/trunk-jpl/etc/environment.sh	(revision 24084)
+++ /issm/trunk-jpl/etc/environment.sh	(revision 24085)
@@ -1,4 +1,10 @@
-#ISSM_DIR and ISSM_ARCH should have been defined already in your shell settings file (.bashrc, .cshrc, etc ...)
-
+# Modifies path-related envrionment variables based on which external packages 
+# have been installed.
+#
+# ISSM_DIR and ISSM_ARCH should have been defined already in your shell 
+# settings file (i.e. .bashrc, .cshrc).
+
+## Functions
+#
 pathprepend(){ #{{{
 	if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
@@ -22,50 +28,73 @@
 } #}}}
 libpathprepend(){ #{{{
-	if [ -d "$1" ] && [[ ":$LD_LIBRARY_PATH:" != *":$1:"* ]]; then
-		export LD_LIBRARY_PATH="$1:$LD_LIBRARY_PATH"
-	fi
-	if [ -d "$1" ] && [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
-		export LD_RUN_PATH="$1:$LD_RUN_PATH"
+	if [ -d "$1" ]; then
+		if [ -z $LD_LIBRARY_PATH ]; then
+			export LD_LIBRARY_PATH="$1"
+		elif [[ ":$LD_LIBRARY_PATH:" != *":$1:"* ]]; then
+			export LD_LIBRARY_PATH="$1:$LD_LIBRARY_PATH"
+		fi
+		if [ -z $LD_RUN_PATH ]; then
+			export LD_RUN_PATH="$1"
+		elif [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
+			export LD_RUN_PATH="$1:$LD_RUN_PATH"
+		fi
 	fi
 } #}}}
 libpathappend(){ #{{{
-	if [ -d "$1" ] && [[ ":$LD_LIBRARY_PATH:" != *":$1:"* ]]; then
-		export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$1"
-	fi
-	if [ -d "$1" ] && [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
-		export LD_RUN_PATH="$LD_RUN_PATH:$1"
+	if [ -d "$1" ]; then
+		if [ -z $LD_LIBRARY_PATH ]; then
+			export LD_LIBRARY_PATH=$1
+		elif [[ ":$LD_LIBRARY_PATH:" != *":$1:"* ]]; then
+			export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$1"
+		fi
+		if [ -z $LD_RUN_PATH ]; then
+			export LD_RUN_PATH=$1
+		elif [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
+			export LD_RUN_PATH="$LD_RUN_PATH:$1"
+		fi
 	fi
 } #}}}
 dylibpathprepend(){ #{{{
-	if [ -d "$1" ] && [[ ":$DYLD_LIBRARY_PATH:" != *":$1:"* ]]; then
-		export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
-	fi
-	if [ -d "$1" ] && [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
-		export LD_RUN_PATH="$1:$LD_RUN_PATH"
+	if [ -d "$1" ]; then
+		if [ -z $DYLD_LIBRARY_PATH ]; then
+			export DYLD_LIBRARY_PATH=$1
+		elif [[ ":$DYLD_LIBRARY_PATH:" != *":$1:"* ]]; then
+			export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
+		fi
+		if [ -z $LD_RUN_PATH ]; then
+			export LD_RUN_PATH=$1
+		elif [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
+			export LD_RUN_PATH="$1:$LD_RUN_PATH"
+		fi
 	fi
 } #}}}
 dylibpathappend(){ #{{{
-	if [ -d "$1" ] && [[ ":$DYLD_LIBRARY_PATH:" != *":$1:"* ]]; then
-		export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$1"
-	fi
-	if [ -d "$1" ] && [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
-		export LD_RUN_PATH="$LD_RUN_PATH:$1"
-	fi
-} #}}}
-
-#FIXME: during installation packages are installed one by one but environment.sh was sourced
-#before so new packages are NOT in the path.
-#may resource environment.sh with:
-#if [ -z $(echo "$PATH" | grep "$MATLAB_DIR") ]; then export $PATH...; fi
-
-#Windows compilers: 
+	if [ -d "$1" ]; then
+		if [ -z $DYLD_LIBRARY_PATH ]; then
+			export DYLD_LIBRARY_PATH=$1
+		elif [[ ":$DYLD_LIBRARY_PATH:" != *":$1:"* ]]; then
+			export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$1"
+		fi
+		if [ -z $LD_RUN_PATH ]; then
+			export LD_RUN_PATH=$1
+		elif [[ ":$LD_RUN_PATH:" != *":$1:"* ]]; then
+			export LD_RUN_PATH="$LD_RUN_PATH:$1"
+		fi
+	fi
+} #}}}
+
+# FIXME: during installation packages are installed one by one but 
+# environment.sh was sourced before so new packages are NOT in the path. May 
+# source environment.sh again with:
+# 	if [ -z $(echo "$PATH" | grep "$MATLAB_DIR") ]; then export $PATH...; fi
+
+# Windows compilers:
 if [[ "$ISSM_ARCH" == "cygwin-intel" ]]; then
 	source $ISSM_DIR/externalpackages/windows/windows_environment.sh
 fi
 
-#Load ISSM scripts
+# Load ISSM scripts
 pathappend "$ISSM_DIR/scripts"
 
-#GMT 
 GMT_DIR="$ISSM_DIR/externalpackages/gmt/install"
 if [ -d "$GMT_DIR" ]; then
