#!/bin/csh
############################################################################
#
#  gemenv.csh
#
#  This source file sets up the N-AWIPS environment.
#
##
# Log:
# T. Piper/SAIC		01/08	Created from .cshrc
# T. Piper/SAIC		11/07	HP only:  Added -lXp and -lXext to XLIBS
# T. Piper/SAIC		11/07	All:  Moved $OS_BIN to the head of $path
# S. Jacobs/NCEP	12/07	Added options for GCC4/GFORTRAN
# T. Piper/SAIC		01/08	Removed $OS_LIB/<>.a environment variables
# T. Piper/SAIC		01/08	Removed GEMEXE and GEMOLB
# T. Piper/SAIC		03/08	Modified NA_OS to include word size on Linux
############################################################################
#
#  IMPORTANT:  The system environment variable NAWIPS must be
#		set in the site's .cshrc startup file.
#
#========================================================================
#
#  Set the operating system environment variable.
#  /bin/uname is available on most UNIX systems.
#
if ( -e /bin/uname ) then
    setenv OS `/bin/uname`
else
    echo
    echo "What type of workstation are you using?"
    echo
    echo "Find the command uname, and insert the correct"
    echo "information in this file."
    echo
endif

#
#  Set the OS version, OS_VER, and the OS release, OS_REL.
#
setenv OS_VER ""
setenv OS_REL ""

switch ( $OS )
    case "AIX":
# IBM
	setenv OS_VER	`uname -v`
	breaksw

    case "HP-UX":
# Hewlett-Packard
	unsetenv OS
	setenv OS	HPUX
	setenv OS_VER	`uname -r | cut -f2 -d.`
	breaksw

    case "IRIX":
    case "IRIX64":
# Silicon Graphics
	setenv OS_VER	`uname -r | cut -f1 -d.`
	setenv OS_REL	`uname -r | cut -f2 -d.`

# Fix for IRIX64
	if  ( $OS == "IRIX64" )  then
	    setenv OS	IRIX
	endif
	breaksw

    case "Linux":
# Linux
	setenv OS_VER	`uname -r | cut -f1 -d.`
	setenv OS_REL	`uname -r | cut -f2 -d.`
        set MTCHECK = `echo $MACHTYPE | cut -c1-6`
	if  ( $MTCHECK == x86_64 )  then
	    setenv OS_BIT	64
	else
	    setenv OS_BIT	32
	endif
	set entrp = `uname -r | awk -F. '{print $NF}'| tr "[A-Z]" "[a-z]"`
	if  ( $entrp == "el" || $entrp == "elsmp" )  then
	    setenv OS_REL	`echo $OS_REL`el
	endif
	breaksw

    case "SunOS":
# Sun Micro Systems
	setenv OS_VER	`uname -r | cut -f1 -d.`
	breaksw

    default:
	echo "What type of UNIX do you have?"
	echo
	echo "Find the command uname, and insert the correct"
	echo "information in the .cshrc file."
	echo
	breaksw
endsw

#
#  Set NA_OS to the lowercase equivalent of OS.
#  Add the Version number to the name and for Linux, also add the release number.
#
if ( $OS == "Linux" ) then
    setenv NA_OS	`echo $OS | tr "[A-Z]" "[a-z]"``echo $OS_VER`.`echo ${OS_REL}$OS_BIT`
else
    setenv NA_OS	`echo $OS | tr "[A-Z]" "[a-z]"``echo $OS_VER`
endif

#
#========================================================================
#  Set N-AWIPS system environment variables.
#
setenv GEMPAK	$NAWIPS/gempak

setenv OS_ROOT	$NAWIPS/os/$NA_OS
setenv OS_BIN	$OS_ROOT/bin
setenv OS_INC	$OS_ROOT/include
setenv OS_LIB	$OS_ROOT/lib

setenv GEMDATA	$GEMPAK/data
setenv GEMERR	$GEMPAK/error
setenv GEMHLP	$GEMPAK/help
setenv GEMINC	$GEMPAK/include
setenv GEMMAPS	$GEMPAK/maps
setenv GEMNTS	$GEMPAK/nts
setenv GEMPARM	$GEMPAK/parm
setenv GEMPDF	$GEMPAK/pdf
setenv GEMTBL	$GEMPAK/tables
setenv GEMPTXT	$GEMPAK/txt/programs
setenv GEMGTXT	$GEMPAK/txt/gemlib

setenv MEL_BUFR_TABLES	$GEMPAK/tables/melbufr
setenv NMAP_RESTORE	$GEMNTS/nmap/restore

#
#========================================================================
#  Set X/Motif search paths.
#
setenv XMICONSEARCHPATH		$NAWIPS/icons/%N/%B
setenv XUSERFILESEARCHPATH	./%N:$HOME/%N:$HOME/Resource/%N:$NAWIPS/resource/%N

#
#  Set operating system specific path and MANPATH.
#
switch ( $OS )
    case "AIX":
	set path = ($path /usr/vac/bin /usr/ucb )
	setenv MANPATH "/usr/man:/usr/share/man:/usr/vac/man/%L:/usr/vacpp/man/%L"
	setenv MANPATH "$MANPATH/:$OS_ROOT/man:$OS_ROOT/share/man"
	breaksw

    case "HPUX":
	set path = ( $path /usr/contrib/bin/X11 /usr/contrib/bin /opt/imake/bin )
	set autologout=0
	breaksw

    case "IRIX":
	set path = ( $path /usr/bsd )
# X-Windows Resource Path
	if  ( $OS_VER == "5" || $OS_VER == "6" )  then
	    setenv XUSERFILESEARCHPATH  $HOME/.desktop-`hostname`/%N:./%N:$HOME/%N:$HOME/Resource/%N:$NAWIPS/resource/%N
	else
	    setenv XUSERFILESEARCHPATH  ./%N:$HOME/%N:$HOME/Resource/%N:$NAWIPS/resource/%N
	endif
	breaksw

    case "Linux":
	set autologout=0
	breaksw

    case "SunOS":
	set path = ( $path /usr/ccs/bin /usr/ucb /usr/openwin/bin )
        setenv MANPATH "/opt/SUNWspro/man:/usr/openwin/man:/usr/man"
	setenv MANPATH "$MANPATH:$OS_ROOT/man:$OS_ROOT/share/man"
	breaksw

    default:
	echo
	echo "WARNING..."
	echo
	echo "The path has not been set properly."
	echo
	breaksw
endsw

set path = ( . $OS_BIN $path $NAWIPS/bin )
set path = ( $path $NAWIPS/scripts/ez $NAWIPS/scripts/nawips )
set path = ( $path $NAWIPS/scripts/prnt )

#
#========================================================================
#  Set compilation and link flags for C and FORTRAN.
#
setenv AR	"ar"
setenv CC	"cc"
setenv FC	"f77"
setenv LD	"ld"
setenv RM	"rm -f"
setenv ARFLAGS	"crv"
setenv BUFRFLAGS "-O"
setenv LDFLAGS	"-L$OS_LIB -s"
setenv INCLUDES	"-I$GEMINC -I$NAWIPS/os/$NA_OS/include"

switch ( $OS )
    case "AIX":
	setenv CC	"cc -qlanglvl=extc99"
	setenv CFLAGS	"$INCLUDES -D$OS"
	setenv FFLAGS	"$INCLUDES -qsuppress=1501-510"
	setenv XLIBS	"-lXm -lXt -lX11"
	setenv BUFRFLAGS "-O -D_SYS_TYPES_H"
	setenv OBJECT_MODE "32"
	breaksw

    case "HPUX":
	setenv FC	"f90"
	setenv CFLAGS	"$INCLUDES -D$OS +DA1.1"
	setenv FFLAGS	"$INCLUDES +DA1.1 -w"
	setenv LDFLAGS	"$LDFLAGS +DA1.1"
	setenv XLIBS	"-lXm -lXt -lX11 -lXp -lXext -lmalloc"
	breaksw

    case "IRIX":
	setenv CFLAGS	"$INCLUDES -D$OS -DUNDERSCORE -I/usr/Motif-2.1/include"
	setenv FFLAGS	"$INCLUDES -I/usr/Motif-2.1/include"
	setenv LDFLAGS	"$LDFLAGS -L/usr/Motif-2.1/lib32 -Wl,-woff,85"
	setenv XLIBS	"-lXm -lXt -lX11 -lPW"
	breaksw

    case "Linux":
	setenv CC	"gcc"
	setenv FC	"g77"
# Uncomment the following for GCC4/GFORTRAN
#	setenv CC	"gcc4"
#	setenv FC	"gfortran"

	setenv BUFRFLAGS "-DNO_MSG_IPC -ansi $BUFRFLAGS"
	setenv CFLAGS	"$INCLUDES -D$OS -DUNDERSCORE -I/usr/X11R6/include"
	setenv FFLAGS	"$INCLUDES -fno-second-underscore"
# Uncomment the following for GCC4/GFORTRAN
#	setenv FFLAGS	"$INCLUDES -fno-second-underscore -fdlines-as-comments -ffixed-line-length-none"

	setenv XLIBS	"-lXm -lXt -lX11 -lSM -lICE -lXp -lXext -lXmu"

	if ( $OS_BIT == "32" )  then
	    setenv LDFLAGS  "$LDFLAGS -L/usr/X11R6/lib"
	else
	    setenv CFLAGS   "$CFLAGS -DG_64BIT"
	    setenv LDFLAGS  "$LDFLAGS -L/usr/X11R6/lib64"
	endif
	breaksw

    case "SunOS":
	setenv CFLAGS	"$INCLUDES -D$OS -DUNDERSCORE"
	setenv FFLAGS	"$INCLUDES -silent"
	setenv XLIBS	"-lXm -lXt -lX11"
	breaksw

    case "OSF1":
	setenv CFLAGS	"$INCLUDES -D$OS -DUNDERSCORE"
	setenv FFLAGS	"$INCLUDES -O0"
	setenv XLIBS	"-lXm -lXt -lX11"
	breaksw

    case "ULTRIX":
	setenv CFLAGS	"$INCLUDES -D$OS -DUNDERSCORE"
	setenv FFLAGS	"$INCLUDES"
	setenv XLIBS	"-lXm -lXt -lX11"
	breaksw

    default:
	echo
	echo "WARNING..."
	echo
	echo "No compiler options have been set."
	echo
	breaksw
endsw

#
#========================================================================
#  Set printer variables.
#
setenv NPRINTER		""
setenv NLPDEST		""

switch ( $OS )
    case "AIX":
	setenv LP		"lpr"
	setenv LPFLAG		"-P"
	setenv LPAODT		"mpage -lo1 -z$LP -Z$LPFLAG"
	setenv LPAODTFLAG	"-P"
	breaksw
    case "HPUX":
	setenv LP		"lp"
	setenv LPFLAG		"-d"
	setenv LPAODT		"mpage -lo1 -z$LP -Z$LPFLAG"
	setenv LPAODTFLAG	"-P"
	breaksw
    case "IRIX":
	setenv LP		"lpr"
	setenv LPFLAG		"-P"
	setenv LPAODT		"mpage -lo1 -z$LP -Z$LPFLAG"
	setenv LPAODTFLAG	"-P"
	breaksw
    case "Linux":
	setenv LP		"lpr"
	setenv LPFLAG		"-P"
	setenv LPAODT		"mpage -lo1 -z$LP -Z$LPFLAG"
	setenv LPAODTFLAG	"-P"
	breaksw
    case "SunOS":
	setenv LP		"lpr"
	setenv LPFLAG		"-P"
	setenv LPAODT		"mpage -lo1 -z$LP -Z$LPFLAG"
	setenv LPAODTFLAG	"-P"
	breaksw
    default:
	echo
	echo "WARNING..."
	echo
	echo "The print command has not been set properly."
	echo
	breaksw
endsw
