#!/bin/sh
# Copyright (C) 1996 Hughes and Applied Research Corporation
#
# Permission to use, modify, and distribute this software and its documentation 
# for any purpose without fee is hereby granted, provided that the above 
# copyright notice appear in all copies and that both that copyright notice and 
# this permission notice appear in supporting documentation.
#
#-----------------------------------------------------------------------------
# filename:	
# 	INSTALL-HDFEOS
#
# description:
# 	This script handles the installation of HDFEOS.
#
# usage:
# 	1) Set directory to HDFEOS top level directory.
# 	2) Type:
# 
# 	       bin/INSTALL-HDFEOS [-dbug] [-sgi32 | -sgi64] [-i<incdir>] [-l<libdir>] [-szi<SZincdir>] [-szl<SZlibdir>]
#              bin/INSTALL-HDFEOS [-cc_path <path/compiler_name>]
# 	       bin/INSTALL-HDFEOS [-h]
# 
# 	   Where (optional) flags are:
#
# 	      -dbug    : build debug version of HDF-EOS
# 	      -sgi32   : build in -n32 mode (SGI Power Challenge only)
# 	      -sgi64   : build in -64  mode (SGI Power Challenge only)
#             -cc_path : set the path of the C compiler to <path/compiler_name>
# 	      -i       : set HDF include directory to <libdir>
# 	      -l       : set HDF library directory to <libdir>
# 	      -h       : display this help message and exit
# 	      -szi     : set SZIP include directory to <libdir>
# 	      -szl     : set SZIP library directory to <libdir>
#
#
# 	3) Enter requested information when prompted.
# 
# notes:
# 	1) This script is compatible with the following platforms:
# 	   Sun, SGI, HP-9000, IBM RS-6000 and DEC Alpha.
# 	   It automatically figures out which platform you are on,
# 	   and sets environment variables accordingly.
#
# author:
# 	Mike Sucher / A.R.C.
#
# history:
#	18-Jun-1996 MES  Initial version 
# 	27-Sep-1996 MES  Add -i and -l options
#	17-Apr-1997 DaW  Added support for old 32-bit compiling on SGI
#			 Power Challenge
#       15-Sep-2003 PTN  Added -cc_path option
#       17_Feb-2004 PTN  Modified for Linux 64
#       09-Nov-2005 TR   Added i686 (cygwin on Pentium)
#-----------------------------------------------------------------------------

this_script="`basename $0`"

#
# Function to output error message
#

WriteError()
{
    echo ""
    echo "${this_script}: Error: $*"  >&2
}


#
# Function prompt for user response
#

UserPrompt()
{
    if [ "$BRAND" = "linux" ] || [ "$BRAND" = "linux32" ] || [ "$BRAND" = "linux64" ] ; then
	/bin/echo "$* \c" > /dev/tty
    else
	echo "$* \\c" > /dev/tty
    fi
    read user_response
}


#
# Function to output help message and exit
#

Help()
{
    sed -n '/filename:/,/author:/p' $0 | grep -v "author:" | cut -c3-300 | more
    #this line must be here because it contains the string: "author:"
    exit
}


#
# Function to output a startup banner
#

Banner()
{
    echo ""
    echo "-----------------------------------------------------------------------"
    echo "$this_script: Installation script for HDFEOS"
    echo ""
    echo "    Installing HDFEOS on host $HOST running $OSTYPE"
    echo "    HDFEOS home directory is: $HDFEOS_HOME"
    echo ""
    echo "    Starting HDFEOS installation at `date`"
    echo ""
    echo "-----------------------------------------------------------------------"
    echo ""
}

#
# Function to handle error exit
#

ErrorExit()
{
    echo ""
    echo "${this_script}: Fatal error running command: $*"  >&2
    echo ""

    echo "-----------------------------------------------------------------------"
    echo ""
    echo "    HDFEOS installation ending with errors at `date`"
    echo ""
    echo "-----------------------------------------------------------------------"

    exit 1
}


#
# Functions to check HDF environment variables for validity
#

ValidHDFLIB()
{
    if [ "$HDFLIB" = "" ] ; then
        WriteError "No HDF library directory specified"
        exit 1
    else
        if [ ! -f "$HDFLIB/libdf.a" ] ; then
            WriteError "HDF library not found in: $HDFLIB"
            exit 1
        fi
    fi
}

ValidHDFINC()
{
    if [ "$HDFINC" = "" ] ; then
        WriteError "No HDF include directory specified"
        exit 1
    else
        if [ ! -f "$HDFINC/hdf.h" ] ; then
            WriteError "HDF header file not found in: $HDFINC"
            exit 1
        fi
    fi
}

#
# Functions to check SZIP environment variables for validity
#

ValidSZIPLIB()
{
    if [ "$SZIPLIB" = "" ] ; then
        WriteError "No SZIP library directory specified"
        exit 1
    else
        if [ ! -f "$SZIPLIB/libsz.a" ] ; then
            WriteError "SZIP library not found in: $SZIPLIB"
            exit 1
        fi
    fi
}

ValidSZIPINC()
{
    if [ "$SZIPINC" = "" ] ; then
        WriteError "No SZIP include directory specified"
        exit 1
    else
        if [ ! -f "$SZIPINC/szlib.h" ] ; then
            WriteError "SZIP header file not found in: $SZIPINC"
            exit 1
        fi
    fi
}

#
# Function to set up the HDF environment variables HDFINC and HDFLIB 
# The values are set via the following priority scheme:
#
#     (1) command line override, via the -l and -i flags
#     (2) loaded from the saved HDF environment file
#     (3) user prompt or inherited from the environment.
# 
# The user will be prompted to override inherited values, except in
# case (1).
#

GetHdfEnv()
{
    #
    # If HDFINC or HDFLIB has not been specified on the command line. 
    # first look for them in the saved HDF environment file
    #

    hdf_env_file=$HDFEOS_BIN/.hdf_env

    if [ -f $hdf_env_file ] ; then

        if [ $lib_flag = 0 ] ; then
            echo "Getting HDFLIB from $hdf_env_file"
            HDFLIB=`head -1 $hdf_env_file`
        fi

        if [ $inc_flag = 0 ] ; then
            echo "Getting HDFINC from $hdf_env_file"
            HDFINC=`tail -1 $hdf_env_file`
        fi

    fi

    #
    # If HDFINC or HDFLIB is undefined at this point, then prompt for them
    # Otherwise ask if they should be accepted, unless specified via the
    # command line.  Check them in any case !
    #

    if [ $lib_flag = 0 ] ; then
        if [ "$HDFLIB" = "" ] ; then
            UserPrompt "Please enter the HDF library files directory: "
        else
            echo "Current value of the HDF library directory is: $HDFLIB"
            UserPrompt "New value (or Return to accept):"
        fi
        if [ "$user_response" != "" ] ; then
            HDFLIB="$user_response"
        fi
    fi

    ValidHDFLIB 	# make sure it's valid before proceeding
    

    if [ $inc_flag = 0 ] ; then
        if [ "$HDFINC" = "" ] ; then
            UserPrompt "Please enter the HDF include files directory: "
        else
            echo "Current value of the HDF include directory is: $HDFINC"
            UserPrompt "New value (or Return to accept):"
        fi
        if [ "$user_response" != "" ] ; then
            HDFINC="$user_response"
        fi
    fi

    ValidHDFINC  	# make sure it's valid before proceeding


    echo ""
    echo "HDF include files in: $HDFINC"
    echo "HDF library files in: $HDFLIB"


    cat /dev/null > $hdf_env_file
    echo $HDFLIB >> $hdf_env_file
    echo $HDFINC >> $hdf_env_file
    
    export HDFLIB HDFINC

}

#
# Function to set up the SZIP environment variables SZIPINC and SZIPLIB 
# The values are set via the following priority scheme:
#
#     (1) command line override, via the -szl and -szi flags
#     (2) loaded from the saved SZIP environment file
#     (3) user prompt or inherited from the environment.
# 
# The user will be prompted to override inherited values, except in
# case (1).
#

GetSzipEnv()
{
    #
    # If SZIPINC or SZIPLIB has not been specified on the command line. 
    # first look for them in the saved SZIP environment file
    #

    szip_env_file=$HDFEOS_BIN/.szip_env

    if [ -f $szip_env_file ] ; then

        if [ $szlib_flag = 0 ] ; then
            echo "Getting SZIPLIB from $szip_env_file"
            SZIPLIB=`head -1 $szip_env_file`
        fi

        if [ $szinc_flag = 0 ] ; then
            echo "Getting SZIPINC from $szip_env_file"
            SZIPINC=`tail -1 $szip_env_file`
        fi

    fi

    #
    # If SZIPINC or SZIPLIB is undefined at this point, then prompt for them
    # Otherwise ask if they should be accepted, unless specified via the
    # command line.  Check them in any case !
    #

    if [ $szlib_flag = 0 ] ; then
        if [ "$SZIPLIB" = "" ] ; then
            UserPrompt "Please enter the SZIP library files directory: "
        else
            echo "Current value of the SZIP library directory is: $SZIPLIB"
            UserPrompt "New value (or Return to accept):"
        fi
        if [ "$user_response" != "" ] ; then
            SZIPLIB="$user_response"
        fi
    fi

    ValidSZIPLIB 	# make sure it's valid before proceeding
    

    if [ $szinc_flag = 0 ] ; then
        if [ "$SZIPINC" = "" ] ; then
            UserPrompt "Please enter the SZIP include files directory: "
        else
            echo "Current value of the SZIP include directory is: $SZIPINC"
            UserPrompt "New value (or Return to accept):"
        fi
        if [ "$user_response" != "" ] ; then
            SZIPINC="$user_response"
        fi
    fi

    ValidSZIPINC  	# make sure it's valid before proceeding


    echo ""
    echo "SZIP include files in: $SZIPINC"
    echo "SZIP library files in: $SZIPLIB"


    cat /dev/null > $szip_env_file
    echo $SZIPLIB >> $szip_env_file
    echo $SZIPINC >> $szip_env_file
    
    export SZIPLIB SZIPINC

}


#
# Function to set up architecture-dependent environment scripts
#

SetupEnvScripts()
{

echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "Setting up installation-dependent scripts"
echo ""
echo "-----------------------------------------------------------------------"
echo ""

cd $HDFEOS_BIN

if [ -f ../tmp/hdfeos_env.ksh.tmp ] ; then

    echo "    Setting up Korn shell (ksh) script 'hdfeos_env.ksh' "
    echo "    Korn shell users may call this file from their .profile "
    echo "    file via the the line:"
    echo "    "
    echo "        . $HDFEOS_BIN/hdfeos_env.ksh  "
    echo "    "
    echo "    It sets up machine-specific environment variables needed "
    echo "    by the HDFEOS makefiles for compilation and linking."
    echo "    "

    echo "# " > hdfeos_env.ksh

    echo '# Clear all conditional flags'  	>> hdfeos_env.ksh
    echo 'sgi_mode=""'  	>> hdfeos_env.ksh
    echo 'hdfeos_f90_comp=""' 	>> hdfeos_env.ksh
    echo 'hdfeos_nag_flag=""' 	>> hdfeos_env.ksh
    if [ "`uname -m`" = "x86_64" ] || [ "`uname -m`" = "ia64" ] || [ "`uname -m`" = "i386" ] || [ "`uname -m`" = "i686" ] ; then
	if [ "$MACINTEL_COMP_FLAG" = "-m32" ] ; then
	    echo 'MACINTEL_COMP_FLAG="-m32"' 	>> hdfeos_env.ksh
	    echo "MAC_BRAND=macintel32		# set MACINTEL for -32 mode" >> hdfeos_env.ksh
	else
	    echo 'MACINTEL_COMP_FLAG="-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -fPIC -arch x86_64"' 	>> hdfeos_env.ksh
	    echo "MAC_BRAND=macintel64		# set MACINTEL for -64 mode" >> hdfeos_env.ksh
	fi
    fi

    if [ "`uname -m`" = "x86_64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		echo 'LNX_COMP_FLAG="-m32"' 	>> hdfeos_env.ksh
		echo "LINUX_BRAND=linux32		# set LINUX for -32 mode" >> hdfeos_env.ksh
	else
		echo 'LNX_COMP_FLAG=""' 	>> hdfeos_env.ksh
		echo "LINUX_BRAND=linux64		# set LINUX for -64 mode" >> hdfeos_env.ksh
	fi
    elif [ "`uname -m`" = "ia64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		echo 'LNX_COMP_FLAG="-m32"' 	>> hdfeos_env.ksh
		echo "LINUX_BRAND=linux32		# set LINUX for -32 mode" >> hdfeos_env.ksh
	else
		echo 'LNX_COMP_FLAG=""' 	>> hdfeos_env.ksh
		echo "LINUX_BRAND=linux64		# set LINUX for -64 mode" >> hdfeos_env.ksh
	fi
    else
	echo 'LNX_COMP_FLAG=""' 	>> hdfeos_env.ksh
	echo "LINUX_BRAND=linux		# set LINUX for -32 mode" >> hdfeos_env.ksh
    fi

    echo " " >> hdfeos_env.ksh
    echo "# set the HDFEOS home directory and HDF variables" >> hdfeos_env.ksh
    echo "# HDFEOS installation done on `date` " >> hdfeos_env.ksh
    echo "# " >> hdfeos_env.ksh
    echo " " >> hdfeos_env.ksh

    echo "HDFEOS_HOME=$HDFEOS_HOME	# the HDFEOS home directory" >> hdfeos_env.ksh
    echo "HDFHONE=$HDFHOME 		# the HDF home directory" >> hdfeos_env.ksh
    echo "HDFBIN=$HDFBIN 		# the HDF bin directory" >> hdfeos_env.ksh
    echo "HDFLIB=$HDFLIB 		# the HDF lib directory" >> hdfeos_env.ksh
    echo "HDFINC=$HDFINC 		# the HDF include directory" >> hdfeos_env.ksh
    echo "SZIPLIB=$SZIPLIB 		# the SZIP lib directory"  >> hdfeos_env.ksh
    echo "SZIPINC=$SZIPINC 		# the SZIP include directory" >> hdfeos_env.ksh
    echo "ZLIBLIB=$ZLIBLIB 		# the ZLIB lib directory"  >> hdfeos_env.ksh
    echo "ZLIBINC=$ZLIBINC 		# the ZLIB include directory" >> hdfeos_env.ksh
    echo "JPEGLIB=$JPEGLIB 		# the JPEG lib directory"  >> hdfeos_env.ksh
    echo "JPEGINC=$JPEGINC 		# the JPEG include directory" >> hdfeos_env.ksh
    case "$sgi_mode" in
      64 ) echo "sgi_mode=64 		# SGI for -64 mode" >> hdfeos_env.ksh
        ;;
      n32 ) echo "sgi_mode=n32 		# SGI for -n32 mode" >> hdfeos_env.ksh
        ;;
      * ) echo "sgi_mode=64 		# SGI for standard mode" >> hdfeos_env.ksh
        ;;
    esac


    if [ "$f90_flag" = "1" ] ; then	 	#  do FORTRAN-90 setup

        echo "hdfeos_f90_comp='$F77' 		# f90 compiler" >> hdfeos_env.ksh

        if [ "$nag_flag" = "1" ] ; then 	#  using NAG f90
            echo "hdfeos_nag_flag=1		# using NAG f90" >> hdfeos_env.ksh
        fi

    fi

    echo "opt_flag='$opt_flag'		# set compiler optimization level" >> hdfeos_env.ksh

    echo " " >> hdfeos_env.ksh

    echo "ext_cc_flags='$EXT_CC_FLAGS'	  # set compiler extra C flags" >> hdfeos_env.ksh

    echo " " >> hdfeos_env.ksh

    echo "ext_fc_flags='$EXT_FC_FLAGS'	  # set compiler extra fC flags" >> hdfeos_env.ksh

    echo " " >> hdfeos_env.ksh

    sed "s^LNX_CMP_FLAG^$LNX_COMP_FLAG^" ../tmp/hdfeos_env.ksh.tmp >> hdfeos_env.ksh.1

    cat hdfeos_env.ksh.1 >> hdfeos_env.ksh
    /bin/rm -f hdfeos_env.ksh.1
    
    sleep 3

fi

echo "                -----------------------------------"
echo ""

if [ -f ../tmp/hdfeos_env.csh.tmp ] ; then

    echo "    Setting up C-shell (csh) script 'hdfeos_env.csh' "
    echo "    This file may be called from your .cshrc file via the the line:"
    echo "    "
    echo "        source $HDFEOS_BIN/hdfeos_env.csh  "
    echo "    "
    echo "    It sets up machine-specific environment variables needed "
    echo "    by the HDFEOS makefiles for compilation and linking."
    echo "    "

    echo "# " > hdfeos_env.csh


    if [ "`uname -m`" = "x86_64" ] || [ "`uname -m`" = "ia64" ] || [ "`uname -m`" = "i386" ] || [ "`uname -m`" = "i686" ] ; then
	if [ "$MACINTEL_COMP_FLAG" = "-m32" ] ; then
	    echo 'setenv MACINTEL_COMP_FLAG "-m32"' 	>> hdfeos_env.csh
	    echo "set MAC_BRAND=macintel32		# set MACINTEL for -32 mode" >> hdfeos_env.csh
	else
	    echo 'setenv MACINTEL_COMP_FLAG "-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -fPIC -arch x86_64"' 	>> hdfeos_env.csh
	    echo "set MAC_BRAND=macintel64		# set MACINTEL for -64 mode" >> hdfeos_env.csh
	fi
    fi

    if [ "`uname -m`" = "x86_64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		echo 'setenv LNX_COMP_FLAG "-m32"' 	>> hdfeos_env.csh
		echo "set LINUX_BRAND=linux32		# set LINUX for -32 mode" >> hdfeos_env.csh
	else
		echo 'setenv LNX_COMP_FLAG ""' 	        >> hdfeos_env.csh
		echo "set LINUX_BRAND=linux64		# set LINUX for -64 mode" >> hdfeos_env.csh
	fi
    elif [ "`uname -m`" = "ia64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		echo 'setenv LNX_COMP_FLAG "-m32"' 	>> hdfeos_env.csh
		echo "set LINUX_BRAND=linux32		# set LINUX for -32 mode" >> hdfeos_env.csh
	else
		echo 'setenv LNX_COMP_FLAG ""' 	>> hdfeos_env.csh
		echo "set LINUX_BRAND=linux64		# set LINUX for -64 mode" >> hdfeos_env.csh
	fi
    else
	echo 'setenv LNX_COMP_FLAG ""' 	>> hdfeos_env.csh

	echo "set LINUX_BRAND=linux		# set LINUX for -32 mode" >> hdfeos_env.csh
    fi

    echo '# Clear all conditional flags'  	>> hdfeos_env.csh
    echo "unset sgi_mode" 	>> hdfeos_env.csh
    echo "unset hdfeos_f90_comp" 	>> hdfeos_env.csh
    echo "unset hdfeos_nag_flag" 	>> hdfeos_env.csh

    echo " " >> hdfeos_env.csh
    echo "# set the HDFEOS home directory and HDF variables" >> hdfeos_env.csh
    echo "# HDFEOS installation done on `date` " >> hdfeos_env.csh
    echo "# " >> hdfeos_env.csh
    echo " " >> hdfeos_env.csh

    echo "setenv HDFEOS_HOME $HDFEOS_HOME	# the HDFEOS home directory" >> hdfeos_env.csh
    echo "setenv HDFHOME $HDFHOME 		# the HDF home directory" >> hdfeos_env.csh
    echo "setenv HDFBIN $HDFBIN 		# the HDF bin directory" >> hdfeos_env.csh
    echo "setenv HDFLIB $HDFLIB 		# the HDF lib directory" >> hdfeos_env.csh
    echo "setenv HDFINC $HDFINC 		# the HDF include directory" >> hdfeos_env.csh
    echo "setenv SZIPLIB $SZIPLIB 		# the SZIP lib directory" >> hdfeos_env.csh
    echo "setenv SZIPINC $SZIPINC  		# the SZIP include directory" >> hdfeos_env.csh
    echo "setenv ZLIBLIB $ZLIBLIB 		# the ZLIB lib directory" >> hdfeos_env.csh
    echo "setenv ZLIBINC $ZLIBINC 		# the ZLIB include directory" >> hdfeos_env.csh
    echo "setenv JPEGLIB $JPEGLIB 		# the JPEG lib directory" >> hdfeos_env.csh
    echo "setenv JPEGINC $JPEGINC 		# the JPEG include directory" >> hdfeos_env.csh

    case "$sgi_mode" in
      64 ) echo "set sgi_mode=64 		# SGI for -64 mode" >> hdfeos_env.csh
        ;;
      n32 ) echo "set sgi_mode=n32 		# SGI for -n32 mode" >> hdfeos_env.csh
        ;;
      * ) echo "set sgi_mode=64 		# SGI for standard mode" >> hdfeos_env.csh
        ;;
    esac


    if [ "$f90_flag" = "1" ] ; then 		# do FORTRAN-90 setup

        echo "hdfeos_f90_comp='$F77' 		# f90 compiler" >> hdfeos_env.csh

        if [ "$nag_flag" = "1" ] ; then 	# check if using NAG f90
            echo "hdfeos_nag_flag=1		# using NAG f90" >> hdfeos_env.csh
        fi

    fi

    echo "set opt_flag='$opt_flag'		# set compiler optimization level" >> hdfeos_env.csh

    echo " " >> hdfeos_env.csh

    echo "set ext_cc_flags='$EXT_CC_FLAGS'	# set compiler extra C flags" >> hdfeos_env.csh

    echo " " >> hdfeos_env.csh
    
    echo "set ext_fc_flags='$EXT_FC_FLAGS'	# set compiler extra fc flags" >> hdfeos_env.csh

    echo " " >> hdfeos_env.csh

    sed "s^LNX_CMP_FLAG^$LNX_COMP_FLAG^" ../tmp/hdfeos_env.csh.tmp >> hdfeos_env.csh.1
    cat hdfeos_env.csh.1 >> hdfeos_env.csh
    /bin/rm -f hdfeos_env.csh.1

    sleep 3

fi


}


#
# Get parameters from command line
#

sgi_mode=64		# by default, SGI mode is standard 64-bit
pgs_f90_comp="" 	# by default, no FORTRAN-90 compiler
pgs_nag_flag=0		# by default, not using NAG FORTRAN-90
inc_flag=0		# HDFINC override flag
lib_flag=0		# HDFLIB override flag
szinc_flag=0		# SZIPINC override flag
szlib_flag=0		# SZIPLIB override flag
opt_flag=-O		# compiler optimization level
fc_path=""
cc_path=""
ext_cc_flags=""
ext_fc_flags=""

while [ "$1" != "" ]
do

    case $1 in

      -h | -he  | -hel  | -help  ) Help ;;	# help

      -sgi32) sgi_mode=n32 ;;
      -sgio32) sgi_mode=o32 ;;

      -sgi64) sgi_mode=64 ;;

      -dbug) opt_flag=-g ;;

      -fc_path ) fc_path="$2" ; shift ;;
      -cc_path ) cc_path="$2" ; shift ;;

      -i) HDFINC=$2 ; inc_flag=1; shift ;;
      -l) HDFLIB=$2 ; lib_flag=1; shift ;;

      -szi) SZIPINC=$2 ; szinc_flag=1; shift ;;
      -szl) SZIPLIB=$2 ; szlib_flag=1; shift ;;

      -i*) HDFINC=`echo $1 | cut -c3-` ; inc_flag=1 ;;
      -l*) HDFLIB=`echo $1 | cut -c3-` ; lib_flag=1 ;;

      -szi*) SZIPINC=`echo $1 | cut -c5-` ; szinc_flag=1 ;;
      -szl*) SZIPLIB=`echo $1 | cut -c5-` ; szlib_flag=1 ;;

      -*)
        echo "Invalid option: $1"
        Help
        ;;

      *) 				# default
        value1="$1"
        ;;

    esac

    shift

done



# set path to a base subset of directories, allowing startup on unknown host
# note: once the host has been determined the path is appropriately customized

PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/bin/X11
export PATH 

# get operating system type, login name
# special cases: SCO and Cray  - uname works differently,

MACHINE="`uname -m | awk '{print $1}'`"	# needed on Cray & SCO
temp_ostype=`uname`

case "$MACHINE" in
    i386) OSTYPE=sco386 ;;		# SCO box
    i686) OSTYPE=sco686 ;;      # Pentium
    CRAY) OSTYPE=UNICOS ;;		# CRAY
    *) OSTYPE="`uname`"	;;		# everybody else
esac
   
CYGPL="`uname | awk -F_ '{print $1}'`"  
       
# Intel Macintosh is also i386 or i686 (?) machine

    if [ "$MACHINE" = "i386" ] ; then
	if [ "$temp_ostype" = "Darwin" ] ; then 
	    OSTYPE=DarwinIntel
	    echo "MAC_BRAND = $MAC_BRAND"
	    if [ "$MAC_BRAND" = "" ] ; then 
		echo " Error: In 64-bit MAC platform the env. variable MAC_BRAND must be set to mac32 or mac64 before running this script."
		exit 1
	    fi
	fi
	if [ "$CYGPL" = "CYGWIN" ] ; then 
	    OSTYPE=Cygwin
	fi
    fi
    if [ "$MACHINE" = "i686" ] ; then
	if [ "$temp_ostype" = "Darwin" ] ; then 
	    OSTYPE=DarwinIntel
	    echo "MAC_BRAND = $MAC_BRAND"
	    if [ "$MAC_BRAND" = "" ] ; then 
		echo " Error: In 64-bit MAC platform the env. variable MAC_BRAND must be set to mac32 or mac64 before running this script."
		exit 1
	    fi
	fi
	if [ "$CYGPL" = "CYGWIN" ] ; then 
	    OSTYPE=Cygwin
	fi
    fi
    if [ "$MACHINE" = "x86_64" ]  || [ "$machine" = "ia64" ] ; then
	if [ "$temp_ostype" = "Darwin" ] ; then
	    OSTYPE=DarwinIntel
	    echo "MAC_BRAND = $MAC_BRAND"
	    if [ "$MAC_BRAND" = "" ] ; then 
		echo " Error: In 64-bit MAC platform the env. variable MAC_BRAND must be set to mac32 or mac64 before running this script."
		exit 1
	    else
		if [ "$MAC_BRAND" = "macintel32" ] ; then
		    if [ "$MACINTEL_COMP_FLAG" = ""  ] ; then
			MACINTEL_COMP_FLAG="-m32"
		    fi
		fi
		if [ "$MAC_BRAND" = "macintel64" ] ; then
		    if [ "$MACINTEL_COMP_FLAG" = ""  ] ; then
			MACINTEL_COMP_FLAG="-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -fPIC -arch x86_64"
		    fi
		fi
	    fi
	elif [ "$temp_ostype" = "Linux" ] ; then
	    if [ "$LINUX_BRAND" = "" ] ; then 
		echo " Error: In 64-bit linux platform the env. variable LINUX_BRAND must be set to linux32 or linux64 before running this script."
		exit 1
	    else
		if [ "$LINUX_BRAND" = "linux32" ] ; then
		    if [ "$LNX_COMP_FLAG" = ""  ] ; then
			LNX_COMP_FLAG="-m32"
		    fi
		fi
	    fi
	fi
    fi

user=`id | cut -d\( -f2 | cut -d\) -f1`

if [ "$LOGNAME" != "$user"  ] ; then
        LOGNAME=$user
        export LOGNAME
fi
if [ "$USER" != "$LOGNAME"  ] ; then
        LOGNAME=$LOGNAME
        export USER
fi


# set machine-dependent environment variables:
# 	HOST   the host name of this machine
# 	BRAND  used by other achitecture-specific code
# 	PATH   the execution search path 

case "$OSTYPE" in

  AIX) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/bin/X11:/usr/sbin
    HOST="`hostname`"
    BRAND="ibm"
    ;;

  HP-UX) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/bin/X11
    HOST="`hostname`"
    BRAND="hp"
    ;;

  IRIX) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/bsd:/usr/sbin
    HOST="`hostname`"
    if [ `uname -r | awk -F. '{print $2}'` = "5" ] ; then
       OS_VERSION="5"                  # release V6.5 IRIX
       echo IRIX 6.5 platform
       case $sgi_mode in
          64 ) BRAND=sgi64 ;;
          n32) BRAND=sgi32 ;;
          *  ) BRAND=sgi64 ;;  # just in case
       esac
    fi
    if [ `uname -r | awk -F. '{print $2}'` = "2" ] ; then
       OS_VERSION="2"                  # release V6.2 IRIX
       echo IRIX 6.2 platform
       case $sgi_mode in
          64 ) BRAND=sgi64 ;;
          n32) BRAND=sgi32 ;;
          *  ) BRAND=sgi64 ;;  # just in case
       esac
    else
       BRAND="sgi"
    fi
    ;;

  IRIX64) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/bsd:/usr/sbin
    HOST="`hostname`"
    case $sgi_mode in
      64 ) BRAND=sgi64 ;;
      n32) BRAND=sgi32 ;;
      o32) BRAND=sgio32 ;;
      32 ) BRAND=sgi ;;
      *  ) BRAND=sgi64 ;;  # just in case
    esac
    ;;

  Linux )
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/X11/bin
    HOST=`hostname`
    BRAND=linux
    if [ "$LINUX_BRAND" = "linux64" ] ; then
	BRAND=linux64
    elif [ "$LINUX_BRAND" = "linux32" ] ; then
	BRAND=linux32
    fi
    if [ "$LNX_COMP_FLAG" = "-m32"  ] ; then
        export LNX_COMP_FLAG
    else
	LNX_COMP_FLAG=""
	export LNX_COMP_FLAG
    fi
    ;;

  Darwin)
    PATH=/bin:/sbin:/usr/bin:/usr/sbin
    pgs_host=`hostname`
    BRAND=macintosh
    ;;

  DarwinIntel)
    PATH=/bin:/sbin:/usr/bin:/usr/sbin
    pgs_host=`hostname`
    BRAND=macintel32
    if [ "$MAC_BRAND" = "macintel64" ] ; then
	BRAND=macintel64
    elif [ "$MAC_BRAND" = "macintel32" ] ; then
	BRAND=macintel32
    fi
    if [ "$MACINTEL_COMP_FLAG" = "-m32"  ] ; then
        export MACINTEL_COMP_FLAG
    else
	MACINTEL_COMP_FLAG="-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -fPIC -arch x86_64"
	export MACINTEL_COMP_FLAG
    fi
    ;;

  Cygwin)
    PATH=/bin:/sbin:/usr/bin:/usr/sbin
    pgs_host=`hostname`
    BRAND=cygwin
    ;;

  OSF1) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/bin/X11:/usr/sbin
    HOST="`hostname -s`"
    BRAND="dec"
    ;;

  sco386 ) 
    if [ "`uname`" = "Linux" ] ; then
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/X11/bin
	HOST="`hostname`"
	BRAND=linux
	if [ "$LINUX_BRAND" = "linux64" ] ; then
	    BRAND=linux64
	elif [ "$LINUX_BRAND" = "linux32" ] ; then
	    BRAND=linux32
	fi
    elif [ "`uname`" = "Darwin" ] ; then
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/X11/bin
	HOST="`hostname`"
	BRAND=macintel32
	if [ "$MAC_BRAND" = "macintel64" ] ; then
	    BRAND=macintel64
	elif [ "$MAC_BRAND" = "macintel32" ] ; then
	    BRAND=macintel32
	fi
    else
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/bin/X11
	HOST="`hostname -s`"
	BRAND="sco"
    fi
    ;;

  sco686 ) 
    if [ "`uname`" = "Linux" ] ; then
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/X11/bin
	HOST="`hostname`"
	BRAND=linux
	if [ "$LINUX_BRAND" = "linux64" ] ; then
	    BRAND=linux64
	elif [ "$LINUX_BRAND" = "linux32" ] ; then
	    BRAND=linux32
	fi
    elif [ "`uname`" = "Darwin" ] ; then
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/X11/bin
	HOST="`hostname`"
	BRAND=macintel32
	if [ "$MAC_BRAND" = "macintel64" ] ; then
	    BRAND=macintel64
	elif [ "$MAC_BRAND" = "macintel32" ] ; then
	    BRAND=macintel32
	fi
    else
	PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/bin/X11
	HOST="`hostname`"
	BRAND="winnt98"
    fi
    ;;

  SunOS) 
    # distinguish between SunOS 5.x and 4.x versions
    if [ `uname -r | awk -F. '{print $1}'` = "5" ] ; then
	if [ `uname -r | awk -F. '{print $2}'` = "11" ] ; then
	    BRAND="sun5.11"			# release V5.x SunOS
	    PATH=/usr/local/bin:/opt/SUNWspro/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/bin:/usr/openwin/demo:/usr/sbin:/usr/ccs/bin
	elif [ `uname -r | awk -F. '{print $2}'` = "10" ] ; then
	    BRAND="sun5.10"			# release V5.x SunOS
	    PATH=/usr/local/bin:/opt/SUNWspro/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/bin:/usr/openwin/demo:/usr/sbin:/usr/ccs/bin
	elif [ `uname -r | awk -F. '{print $2}'` = "9" ] ; then
	    BRAND="sun5.9"			# release V5.x SunOS
	    PATH=/usr/local/bin:/opt/SUNWspro/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/bin:/usr/openwin/demo:/usr/sbin:/usr/ccs/bin
	elif [ `uname -r | awk -F. '{print $2}'` = "8" ] ; then
	    BRAND="sun5.8"			# release V5.x SunOS
	    PATH=/usr/local/bin:/opt/SUNWspro/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/bin:/usr/openwin/demo:/usr/sbin:/usr/ccs/bin
	else                                
	    BRAND="sun5"
	    PATH=/usr/local/bin:/opt/SUNWspro/bin:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/bin:/usr/openwin/demo:/usr/sbin:/usr/ccs/bin 
	fi
    fi
    if [ "`uname -r | awk -F. '{print $1}'`" = "4" ] ; then
	BRAND="sun4"			# release V4.x SunOS
        PATH=/usr/local/bin:/usr/local/lang:/usr/lang:/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/usr/openwin/demo
    fi
    HOST="`hostname`"
    ;;

  UNICOS) 
    PATH=/usr/local/bin:/bin:/usr/bin:/etc:/usr/bin/X11
    HOST="`hostname`"
    BRAND="cray"
    ;;

  *)	
    echo "Operating system: $OSTYPE not supported"
    echo "This release of HDFEOS supports: "
    echo "   Sun SGI HP-9000 IBM-6000 and DEC-Alpha "
    ;;

esac

export PATH HOST BRAND


#
# Flag IRIX 6.2 because this may impact on makefiles
#

irix53=0
case $BRAND in
  sgi ) 
    if [ "$OSTYPE" = "IRIX" ] ; then
        irix53=1 
    fi
    ;;
esac
export irix53


# set machine-dependent compilers and compilation switches:
#
#

NSL_FLAG="" 			# this is nil on all but Sun platforms
NSL_LIB="" 			# this is nil on all but Sun platforms
AR="ar r"			# command to build library
RANLIB=touch			# default for platforms that don't need ranlib
RANLIBSUN4=touch		# default for platforms that don't need ranlib

case "$BRAND" in

    cray)
	CC=cc 			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS"	# default C flags (optimize, ansi)
	C_CFH="-DCRAYFortran"   # C/cfortran.h called from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=cf77		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main 
	HDFSYS=UNICOS		# system type as defined by HDF
	MACHINE=CRAY		# system type as defined by HDFEOS
	;;

    dec)
	CC=cc 			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -std"	# default C flags (optimize, ansi)
	C_CFH="-DDECFortran"	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH -Dmain=MAIN__" # calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=f77 		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH "   # calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=DEC_ALPHA	# system type as defined by HDF
	MACHINE=DEC		# system type as defined by HDFEOS
	;;

    hp)
	CC=cc			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -Ae" 	# default C flags (optimize, ansi)
	C_CFH="" 		# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main 
	F77=fort77		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=HP9000		# system type as defined by HDF
	MACHINE=HP		# system type as defined by HDFEOS
	;;

    ibm)
	CC=cc 			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -qlanglvl=ansi" # default C flags (optimize, ansi)
	C_CFH="" 		# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main  FORTAN
	F77=xlf 		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH="" 		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=IBM6000		# system type as defined by HDF
	MACHINE=IBM		# system type as defined by HDFEOS
	;;

     linux | linux32 | linux64)
	#CC="gcc -m32"  	# C compiler
	CC="gcc $LNX_COMP_FLAG"  		# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
	C_CFH="-Df2cFortran"	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	#F77="g77 -m32"		# FORTRAN compiler
	F77="g77 $LNX_COMP_FLAG"		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
        if [ "`uname -m`" = "x86_64" ] ; then
	    if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		HDFSYS=LINUX	# system type as defined by HDF
	    else
		HDFSYS=LINUX64  # Only for 64 bit linux
	    fi
	elif [ "`uname -m`" = "ia64" ] ; then
	    if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		HDFSYS=LINUX	# system type as defined by HDF
	    else
		HDFSYS=IA64     #Only for IA64
	    fi
        else
	   HDFSYS=LINUX		# system type as defined by HDF
	fi
	MACHINE=LINUX		# system type as defined by HDFEOS
	;;

    macintosh)
        CC=gcc                  # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77=g77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB=""            # C lib called by FORTRAN main
        RANLIB=ranlib		# activate the ranlib command
        HDFSYS=MACINTOSH        # system type as defined by HDF
        MACHINE=MACINTOSH       # system type as defined by HDFEOS
        ;;

    macintel)
        CC="gcc $MACINTEL_COMP_FLAG"                 # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77="gfortran $MACINTEL_COMP_FLAG"           # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB=""            # C lib called by FORTRAN main
        RANLIB=ranlib		# activate the ranlib command
	HDFSYS=MACINTEL         # system type as defined by HDF
        MACHINE=MACINTEL        # system type as defined by HDFEOS
        ;;

    macintel32)
        CC="gcc $MACINTEL_COMP_FLAG"                 # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77="gfortran $MACINTEL_COMP_FLAG"           # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB=""            # C lib called by FORTRAN main
        RANLIB=ranlib		# activate the ranlib command
	HDFSYS=MACINTEL         # system type as defined by HDF
        MACHINE=MACINTEL        # system type as defined by HDFEOS
        ;;

    macintel64)
        CC="gcc $MACINTEL_COMP_FLAG"                 # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77="gfortran $MACINTEL_COMP_FLAG"           # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB=""            # C lib called by FORTRAN main
        RANLIB=ranlib		# activate the ranlib command
	HDFSYS=MACINTEL         # system type as defined by HDF
        MACHINE=MACINTEL        # system type as defined by HDFEOS
        ;;

    cygwin)
        CC=gcc                  # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -ansi" # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77=g77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB=""            # C lib called by FORTRAN main
        RANLIB=ranlib		# activate the ranlib command
	HDFSYS=CYGWIN           # system type as defined by HDF
        MACHINE=CYGWIN          # system type as defined by HDFEOS
        ;;

    sco)
	CC=cc  			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -posix" # default C flags (optimize, ansi)
	C_CFH="-Df2cFortran"	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=""			# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=SCO		# system type as defined by HDF
	MACHINE=SCO		# system type as defined by HDFEOS
	;;

    sgi)
	if [ $OSTYPE = "IRIX64" ]
        then
		CC="cc -32"	# C compiler (32 bit)
		F77="f77 -32"	# FORTRAN compiler (32 bit)
        else
		CC=cc 		# C compiler
		F77=f77		# FORTRAN compiler
        fi
	CFLAGS="$opt_flag $EXT_CC_FLAGS -xansi -D_POSIX_SOURCE"	# default C flags (optimize, ansi)
	C_CFH=""	 	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB="-lI77 -lU77 -lF77" # FORTRAN lib called by C main
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=IRIS4		# system type as defined by HDF
	MACHINE=SGI		# system type as defined by HDFEOS
	;;

    sgi32)
	CC="cc -n32"		# C compiler (new-style 32 bit)
	F77="f77 -n32"		# FORTRAN compiler (new-style 32 bit)
	CFLAGS="$opt_flag $EXT_CC_FLAGS -xansi -D_POSIX_SOURCE"	# default C flags (optimize, ansi)
	C_CFH=""	 	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB="-lI77 -lU77 -lF77" # FORTRAN lib called by C main
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=IRIS4		# system type as defined by HDF
	MACHINE=SGI		# system type as defined by HDFEOS
	;;

    sgio32)
	CC="cc -32 -mips2"	# C compiler (old-style 32 bit)
	F77="f77 -32 -mips2"	# FORTRAN compiler (old-style 32 bit)
	CFLAGS="$opt_flag $EXT_CC_FLAGS -xansi -D_POSIX_SOURCE"	# default C flags (optimize, ansi)
	C_CFH=""	 	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB="-lI77 -lU77 -lF77" # FORTRAN lib called by C main
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=IRIS4		# system type as defined by HDF
	MACHINE=SGI		# system type as defined by HDFEOS
	;;

    sgi64)
	cpu_type=`hinv | fgrep CPU | head -1 | cut -d' ' -f3 | cut -b2`
	if [ "$cpu_type" = "4" ] ; then
	    CC="cc -64 -mips3"		# C compiler (R4?00 chip)
	    F77="f77 -64 -mips3"	# FORTRAN compiler (R4?00 chip)
        else
            CC="cc -64 -mips4"      	# C compiler
            F77="f77 -64 -mips4"    	# FORTRAN compiler
        fi
	CFLAGS="$opt_flag $EXT_CC_FLAGS -xansi -D_POSIX_SOURCE"	# default C flags (optimize, ansi)
	C_CFH=""	 	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB="-lI77 -lU77 -lF77" # FORTRAN lib called by C main
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH"	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB=""		# C lib called by FORTRAN main
	HDFSYS=IRIS4		# system type as defined by HDF
	MACHINE=SGI		# system type as defined by HDFEOS
	;;

    sun4)
	CC=acc			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -Xa" 	# default C flags (optimize, ansi)
	C_CFH="-DsunFortran"	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=f77 		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH" 	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB="-lm" 	# C lib called by FORTRAN main
	HDFSYS=SUN		# system type as defined by HDF
	MACHINE=SUN4		# system type as defined by HDFEOS
	NSL_FLAG="-lnsl"	# this is nil on all but Sun platforms
	NSL_LIB="/usr/lib/libnsl.a"	# this is nil on all but Sun platforms
        RANLIB=ranlib		# activate the ranlib command
        RANLIBSUN4=ranlib
	;;

    sun5)
	CC=cc			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS -Xa" 	# default C flags (optimize, ansi)
	C_CFH="-DsunFortran"	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=f77 		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH" 	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB="-lm" 	# C lib called by FORTRAN main
	HDFSYS=SUN		# system type as defined by HDF
	MACHINE=SUN5		# system type as defined by HDFEOS
	NSL_FLAG="-lnsl"	# this is nil on all but Sun platforms
	NSL_LIB="/usr/lib/libnsl.a"	# this is nil on all but Sun platforms
	;;

 sun5.8)
        CC=cc                   # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -Xa"  # default C flags (optimize, ansi)
        C_CFH="-DsunFortran -DSUNOS58X"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77=f77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB="-lm"         # C lib called by FORTRAN main
        HDFSYS=SUN              # system type as defined by HDF
        MACHINE=SUN8            # system type as defined by HDFEOS
        NSL_FLAG="-lnsl"        # this is nil on all but Sun platforms
        NSL_LIB="/usr/lib/libnsl.a"     # this is nil on all but Sun platforms
        ;;

 sun5.9)
        CC=cc                   # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -Xa"  # default C flags (optimize, ansi)
        C_CFH="-DsunFortran -DSUNOS59X"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77=f77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB="-lm"         # C lib called by FORTRAN main
        HDFSYS=SUN              # system type as defined by HDF
        MACHINE=SUN9            # system type as defined by HDFEOS
        NSL_FLAG="-lnsl"        # this is nil on all but Sun platforms
        NSL_LIB="/usr/lib/libnsl.a"     # this is nil on all but Sun platforms
        ;;


 sun5.10)
        CC=cc                   # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -Xa"  # default C flags (optimize, ansi)
        C_CFH="-DsunFortran -DSUNOS510X"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77=f77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB="-lm"         # C lib called by FORTRAN main
        HDFSYS=SUN              # system type as defined by HDF
        MACHINE=SUN10            # system type as defined by HDFEOS
        NSL_FLAG="-lnsl"        # this is nil on all but Sun platforms
        NSL_LIB="/usr/lib/libnsl.a"     # this is nil on all but Sun platforms
        ;;


 sun5.11)
        CC="gcc -m32"                  # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS "  # default C flags (optimize, ansi)
        C_CFH="-DsunFortran -DSUNOS511X"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        C_F77_CFH="$C_CFH"      # calling FORTRAN
        C_F77_LIB=""            # FORTRAN lib called by C main
        F77="gfortran -m32"     # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        F77_CFH=""              # FORTRAN callable from C w/ cfortran.h
        F77_C_CFH="$F77_CFH"    # calling C w/ cfortran.h
        CFH_F77="$F77_C_CFH"    # old version of F77_C_CFH
        F77_C_LIB="-lm"         # C lib called by FORTRAN main
        HDFSYS=SUN              # system type as defined by HDF
        MACHINE=SUN11           # system type as defined by HDFEOS
        NSL_FLAG="-lnsl"        # this is nil on all but Sun platforms
        NSL_LIB="/usr/lib/libnsl.a"     # this is nil on all but Sun platforms
        ;;

  winnt98 )
        CPP=CC                  # C++ compiler
        CC=gcc                  # C compiler
        CFLAGS="$opt_flag $EXT_CC_FLAGS -O3 -Wall -W -Wundef -Wno-switch"     # default C flags (optimize, ansi)
        C_CFH="-Df2cFortran"    # C w/ cfortran.h callable from FORTRAN
        CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
        CPPFLAGS="$EXT_CPP_FLAGS -g -ansi"     # default C ++ flags (optimize, ansi)
        CPP_CFH="-Df2cFortran"  # C ++ w/ cfortran.h callable from FORTRAN
        CPPFHFLAGS="$CPPFLAGS $CPP_CFH" # CFLAGS + C_CFH for C++
        F77=g77                 # FORTRAN compiler
        F77FLAGS="$opt_flag $EXT_FC_FLAGS"    # common FORTRAN flags
        HDFSYS=CYGWIN           # system type as defined by HDF
        ;;
       
    *)
	CC=cc			# C compiler
	CFLAGS="$opt_flag $EXT_CC_FLAGS" 	# default C flags (optimize)
	C_CFH=""	# C w/ cfortran.h callable from FORTRAN
	CFHFLAGS="$CFLAGS $C_CFH" # CFLAGS + C_CFH
	C_F77_CFH="$C_CFH"	# calling FORTRAN
	C_F77_LIB=""		# FORTRAN lib called by C main
	F77=f77 		# FORTRAN compiler
	F77FLAGS="$opt_flag $EXT_FC_FLAGS"	# common FORTRAN flags
	F77_CFH=""		# FORTRAN callable from C w/ cfortran.h
	F77_C_CFH="$F77_CFH" 	# calling C w/ cfortran.h
	CFH_F77="$F77_C_CFH"	# old version of F77_C_CFH
	F77_C_LIB="-lm" 	# C lib called by FORTRAN main
	HDFSYS=unknown		# system type as defined by HDF
	MACHINE=unknown		# system type as defined by HDFEOS
	;;
esac

export NSL_FLAG NSL_LIB AR RANLIB RANLIBSUN4

export CC CFLAGS C_CFH CFHFLAGS C_F77_CFH C_F77_LIB F77
export F77FLAGS F77_CFH F77_C_CFH CFH_F77 F77_C_LIB HDFSYS


#
# Verify that this is the HDFEOS home directory before proceeding
# If OK, then set the value of HDFEOS_HOME, else quit.

dirs="bin include lib obj src"
ok=1

for dir in $dirs ; do

    if [ ! -d $dir ] ; then
        ok=0
        break
    fi

done

if [ $ok = 1 ] ; then

    HDFEOS_HOME=`pwd`

else

    WriteError "You must first go to the HDFEOS home directory."
    Help

fi

dirs="bin lib obj"
for dir in $dirs ; do

    if [ ! -d $dir/$BRAND ] ; then
	mkdir $dir/$BRAND
    fi

done

#
# For linux create soft links for backward compatibility with 
#                 older versions of the hdfeos
#
    if [ "$BRAND" = "linux64" ] ; then
	    
	echo "64-bit structure is the default in this machine. Creating linux as soft link to linux64 in bin, lib, and obj directories."

	dirs="bin lib obj"
	for dir in $dirs ; do
# back up existing linux diretory
	    if [ -d $dir/linux ] ; then
		/bin/mv  $dir/linux $dir/linux_backup
	    fi
	    ln -s ./$BRAND $dir/linux
	done
    fi

    if [ "$BRAND" = "linux" ] ; then

	echo "32-bit structure is the default in this machine. Creating linux32 as soft link to linux in bin, lib, and obj directories."

	dirs="bin lib obj"
	for dir in $dirs ; do
# back up existing linux32 diretory
	    if [ -d $dir/linux32 ] ; then
		/bin/mv  $dir/linux32 $dir/linux32_backup
	    fi
	    ln -s ./$BRAND $dir/linux32
	done
    fi

#
# For macintel create soft links for backward compatibility with 
#                 older versions of the hdfeos
#
    if [ "$BRAND" = "macintel32" ] ; then
	    
	echo "macintel32 directories will be soft linked to macintel. Creating macintel as soft link to macintel32 in bin, lib, and obj directories."

	dirs="bin lib obj"
	for dir in $dirs ; do
# back up existing macintel diretory
	    if [ -d $dir/macintel ] ; then
		/bin/mv  $dir/macintel $dir/macintel_backup
	    fi
	    ln -s ./$BRAND $dir/macintel
	done
    fi

    if [ "$BRAND" = "macintel" ] ; then

	echo "macintel32 directories will be soft linked to macintel. Creating macintel32 as soft link to macintel in bin, lib, and obj directories."

	dirs="bin lib obj"
	for dir in $dirs ; do
# back up existing macintel32 diretory
	    if [ -d $dir/macintel32 ] ; then
		/bin/mv  $dir/macintel32 $dir/macintel32_backup
	    fi
	    ln -s ./$BRAND $dir/macintel32
	done
    fi

#
# set HDFEOS-related environment variables
# these may be referred to in makefiles and on compiler command lines
#

if [ "$HDFEOS_HOME" != "" ] ; then

# set up base set of HDFEOS directory variables.

    HDFEOS_BIN=${HDFEOS_HOME}/bin/$BRAND	# executable files
    HDFEOS_INC=$HDFEOS_HOME/include		# include header files
    HDFEOS_LIB=${HDFEOS_HOME}/lib/$BRAND  	# library files
    HDFEOS_OBJ=${HDFEOS_HOME}/obj/$BRAND	# object files
    HDFEOS_SRC=$HDFEOS_HOME/src			# HDFEOS source files

    export HDFEOS_HOME HDFEOS_BIN HDFEOS_DAT HDFEOS_INC HDFEOS_LIB 
    export HDFEOS_MSG  HDFEOS_OBJ HDFEOS_RUN HDFEOS_SRC HDFEOS_TST

# update path variables

    PATH=$PATH:$HDFEOS_BIN; export PATH		# add HDFEOS_BIN to path

else

    echo "You must first set the environment variable HDFEOS_HOME"
    exit 1

fi


# 
# set up environment to handle FORTRAN-90 compiler
#

if [ "$pgs_f90_comp" != "" ] ; then		# using FORTRAN-90

    F77="$pgs_f90_comp"

    if [ "$pgs_nag_flag" = "1" ] ; then		# using NAG f90
        C_CFH="$C_CFH -DNAGf90F"
        CFHFLAGS="$CFLAGS $C_CFH"
    fi

    export CFHFLAGS C_CFH F77

fi

#
# Ouput a banner
#

Banner

#
# Get the HDF and SZIP library and include directories from the user
#

GetHdfEnv
GetSzipEnv

#
# Set up the architecture-dependent environment scripts
#

SetupEnvScripts


#
# Run the architecture-dependent installation commands
#

MAKECMD=make; export MAKECMD 		# force use of regular make
					# ClearMake doesn't work with
					# current makefile

: ${MAKECMD:=make}			# the make command defaults to 'make'

					# augment path if using clearmake
if [ "`echo $MAKECMD | grep clearmake`" != "" ] ; then
    echo "$this_script : note : make command is set to clearmake"
    PATH="$PATH:/usr/atria/bin" 
    export PATH
fi

cd $HDFEOS_SRC

echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "Configuring the GCTP library"
echo ""
echo "-----------------------------------------------------------------------"
echo ""

make_file="-f Makefile"		# default makefile

case $BRAND in

  dec)
    echo cp $HDFEOS_LIB/../tmp/geolibDEC.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibDEC.a $HDFEOS_LIB/libGctp.a
    ;;

  hp)
    echo cp $HDFEOS_LIB/../tmp/geolibHP.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibHP.a $HDFEOS_LIB/libGctp.a
    ;;

  ibm)
    echo cp $HDFEOS_LIB/../tmp/geolibIBM.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibIBM.a $HDFEOS_LIB/libGctp.a
    ;;

  sgi)
    if [ $irix53 = 1 ] ; then
        echo cp $HDFEOS_LIB/../tmp/geolibIRIX53.a $HDFEOS_LIB/libGctp.a
        cp $HDFEOS_LIB/../tmp/geolibIRIX53.a $HDFEOS_LIB/libGctp.a
    else
        echo cp $HDFEOS_LIB/../tmp/geolibIRIX62-32.a $HDFEOS_LIB/libGctp.a
        cp $HDFEOS_LIB/../tmp/geolibIRIX62-32.a $HDFEOS_LIB/libGctp.a
    fi
    ;;

  sgi32)
    echo cp $HDFEOS_LIB/../tmp/geolibIRIX62-n32.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibIRIX62-n32.a $HDFEOS_LIB/libGctp.a
    ;;

  sgi64)
    if [ "$cpu_type" = "4" ] ; then
	echo cp $HDFEOS_LIB/../tmp/geolibIRIX62-64mips3.a $HDFEOS_LIB/libGctp.a
	cp $HDFEOS_LIB/../tmp/geolibIRIX62-64mips3.a $HDFEOS_LIB/libGctp.a
    else
	echo cp $HDFEOS_LIB/../tmp/geolibIRIX62-64.a $HDFEOS_LIB/libGctp.a
	cp $HDFEOS_LIB/../tmp/geolibIRIX62-64.a $HDFEOS_LIB/libGctp.a
    fi
    ;;

  sun4)
    echo cp $HDFEOS_LIB/../tmp/geolibSUN4.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSUN4.a $HDFEOS_LIB/libGctp.a
    ;;

  sun5)
    echo cp $HDFEOS_LIB/../tmp/geolibSOL24.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSOL24.a $HDFEOS_LIB/libGctp.a
    ;;

  sun5.8)
    echo cp $HDFEOS_LIB/../tmp/geolibSOL28.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSOL28.a $HDFEOS_LIB/libGctp.a
    ;;

  sun5.9)
    echo cp $HDFEOS_LIB/../tmp/geolibSOL29.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSOL29.a $HDFEOS_LIB/libGctp.a
    ;;

  sun5.10)
    echo cp $HDFEOS_LIB/../tmp/geolibSOL210.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSOL210.a $HDFEOS_LIB/libGctp.a
    ;;

  sun5.11)
    echo cp $HDFEOS_LIB/../tmp/geolibSOL211.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibSOL211.a $HDFEOS_LIB/libGctp.a
    ;;

  linux | linux32 | linux64)
    if [ "`uname -m`" = "x86_64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
	    echo cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
	else
	    echo cp $HDFEOS_LIB/../tmp/geolibLINUX64.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibLINUX64.a $HDFEOS_LIB/libGctp.a
	fi
    elif [ "`uname -m`" = "ia64" ] ; then
	if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
	    echo cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
	else
	    echo cp $HDFEOS_LIB/../tmp/geolibLINUXIA64.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibLINUXIA64.a $HDFEOS_LIB/libGctp.a
	fi
    else
	echo cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
	cp $HDFEOS_LIB/../tmp/geolibLINUX.a $HDFEOS_LIB/libGctp.a
    fi
    ;;

  macintosh)
    echo cp $HDFEOS_LIB/../tmp/geolibMAC.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibMAC.a $HDFEOS_LIB/libGctp.a
    ;;

  macintel | macintel32 | macintel64)
	if [ "$MACINTEL_COMP_FLAG" = "-m32" ] || [ "$MACINTEL_COMP_FLAG" = "" ] ; then
	    echo cp $HDFEOS_LIB/../tmp/geolibMACIntel.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibMACIntel.a $HDFEOS_LIB/libGctp.a
	else
	    echo cp $HDFEOS_LIB/../tmp/geolibMACIntel64.a $HDFEOS_LIB/libGctp.a
	    cp $HDFEOS_LIB/../tmp/geolibMACIntel64.a $HDFEOS_LIB/libGctp.a
	fi
    ;;

  cygwin)
    echo cp $HDFEOS_LIB/../tmp/geolibCYGWIN.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibCYGWIN.a $HDFEOS_LIB/libGctp.a
    ;;

  winnt98)
    echo cp $HDFEOS_LIB/../tmp/geolibCYGWIN.a $HDFEOS_LIB/libGctp.a
    cp $HDFEOS_LIB/../tmp/geolibCYGWIN.a $HDFEOS_LIB/libGctp.a
    ;;

  *)
    echo '!!!!!! WARNING !!!!!! WARNING !!!!!! WARNING !!!!! WARNING !!!!!!'
    echo '"'$BRAND'"' is not officially supported, no GCTP library available
    echo for this mode '"'$BRAND'"'.  HDF-EOS grid routines will not work
    echo without this library.
    ;;

esac

if [ -f $HDFEOS_LIB/libGctp.a ] ; then
    chmod u+w $HDFEOS_LIB/libGctp.a
else
    cd ${HDFEOS_HOME}/gctp
    make -f Makefile

    case $BRAND in
	
	dec)
	    cp lib/$BRAND/libgctpdec.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	hp)
	    cp lib/$BRAND/libgctphp.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	ibm)
	    cp lib/$BRAND/libgctpibm.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sgi)
	    cp lib/$BRAND/libgctpsgi32.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sgi32)
	    if [ "$cpu_type" = "4" ] ; then
		cp lib/$BRAND/libgctpsgin32.a $HDFEOS_LIB/libGctp.a
	    else
		cp lib/$BRAND/libgctpsgi65_n32.a $HDFEOS_LIB/libGctp.a
	    fi
	    ;;
	
	sgi64)
	    if [ "$cpu_type" = "4" ] ; then
		cp lib/$BRAND/libgctpsgi64.a $HDFEOS_LIB/libGctp.a
	    else
		cp lib/$BRAND/libgctpsgi65_64.a $HDFEOS_LIB/libGctp.a
	    fi
	    ;;
	
	sun4)
 	    cp lib/$BRAND/libgctpsol24.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sun5)
	    cp lib/$BRAND/libgctpsol25.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sun5.8)
	    cp lib/$BRAND/libgctpsol28.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sun5.9)
	    cp lib/$BRAND/libgctpsol29.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	sun5.10)
	    cp lib/$BRAND/libgctpsol210.a $HDFEOS_LIB/libGctp.a
	    ;;
		
	sun5.11)
	    cp lib/$BRAND/libgctpsol211.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	linux | linux32 | linux64)
	    if [ "`uname -m`" = "x86_64" ] ; then
		if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		    cp lib/$BRAND/libgctplinux.a $HDFEOS_LIB/libGctp.a
		else
		    cp lib/$BRAND/libgctplinux64.a $HDFEOS_LIB/libGctp.a
		fi
	    elif [ "`uname -m`" = "ia64" ] ; then
		if [ "$LNX_COMP_FLAG" = "-m32" ] ; then
		    cp lib/$BRAND/libgctplinux.a $HDFEOS_LIB/libGctp.a
		else
		    cp lib/$BRAND/libgctplinuxia64.a $HDFEOS_LIB/libGctp.a
		fi
	    else
		cp lib/$BRAND/libgctplinux.a $HDFEOS_LIB/libGctp.a
	    fi
	    ;;
	
	macintosh)
	    cp lib/$BRAND/libgctpmacintosh.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	macintel)
	    cp lib/$BRAND/libgctpmacintel.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	macintel32)
	    cp lib/$BRAND/libgctpmacintel32.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	macintel64)
	    cp lib/$BRAND/libgctpmacintel64.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	cygwin)
	    cp lib/$BRAND/libgctpcygwin.a $HDFEOS_LIB/libGctp.a
	    ;;
	
	winnt98)
	    cp lib/$BRAND/libgctpcygwin.a $HDFEOS_LIB/libGctp.a
	    ;;
    esac
fi

cd $HDFEOS_SRC

#
# check to see if valid C compiler path was specified
#
    
cc=""
    
if [ "$cc_path" != ""  ] ; then
    
    if [ -f $cc_path ] ; then
    
            cc=`basename $cc_path`
            cc_path=`echo $cc_path | sed 's%/[^/]*/*$%%'`
	    case "$BRAND" in
		"sgi32" )
		    CC="$cc_path/$cc -n32"
		;;

		"sgi64" )
		    cpu_type=`hinv | fgrep CPU | head -1 | cut -d' ' -f3 | cut -b2`
		    if [ "$cpu_type" == "4" ] ; then
			CC="$cc_path/$cc -64 -mips3"
		    else
			CC="$cc_path/$cc -64 -mips4"
		    fi
		;;

		* )
		    CC="$cc_path/$cc" 
		;; 
	    esac

	    export CC		# user overrides C compiler name
    fi
    
    if [ -d $cc_path ] ; then	# make sure cc_path is now a directory
         PATH=${cc_path}:${PATH} 	# prepend cc_path to search path
         export PATH
    else
         cc_path=""
         echo "Warning: C compiler directory $cc_path not found."
         echo  "HDFEOS build may fail."
    fi
fi

cat /dev/null > ../include/HE2_config.h

echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "Building HDFEOS"
echo ""
echo "-----------------------------------------------------------------------"
echo ""

$MAKECMD $make_file
if [ $? != 0 ] ; then
    ErrorExit "$MAKECMD $make_file"
fi

if [ $BRAND = "macintosh" ] ; then
$RANLIB -s $HDFEOS_LIB/libGctp.a
$RANLIB -s $HDFEOS_LIB/libhdfeos.a
fi

if [ $BRAND = "macintel" ] ; then
$RANLIB -s $HDFEOS_LIB/libGctp.a
$RANLIB -s $HDFEOS_LIB/libhdfeos.a
fi

if [ $BRAND = "macintel32" ] ; then
$RANLIB -s $HDFEOS_LIB/libGctp.a
$RANLIB -s $HDFEOS_LIB/libhdfeos.a
fi

if [ $BRAND = "macintel64" ] ; then
$RANLIB -s $HDFEOS_LIB/libGctp.a
$RANLIB -s $HDFEOS_LIB/libhdfeos.a
fi

if [ $BRAND = "cygwin" ] ; then
$RANLIB $HDFEOS_LIB/libGctp.a
$RANLIB $HDFEOS_LIB/libhdfeos.a
fi

echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "Cleaning up"
echo ""
echo "-----------------------------------------------------------------------"
echo ""

$MAKECMD $make_file clean
if [ $? != 0 ] ; then
    ErrorExit "$MAKECMD $make_file clean"
fi


echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "Building HDFEOS utilities"
echo ""
echo "-----------------------------------------------------------------------"
echo ""

    HDFEOS_UTIL=${HDFEOS_HOME}/util	# utility files
    cd $HDFEOS_UTIL
    make_utilfile="-f makefile"		# default utility makefile
    $MAKECMD $make_utilfile
    if [ $? != 0 ] ; then
	ErrorExit "$MAKECMD $make_utilfile"
    fi

#    cp GDconvert_ij2ll $HDFEOS_BIN/GDconvert_ij2ll
#    /bin/rm $HDFEOS_UTIL/GDconvert_ij2ll
    chmod u+wx $HDFEOS_BIN/GDconvert_ij2ll

# done

echo ""
echo ""
echo "-----------------------------------------------------------------------"
echo ""
echo "    HDFEOS installation ending at `date`"
echo ""
echo "-----------------------------------------------------------------------"















