# Version June 11, 2026
# ----------------------------------------------------------------------
# This file is called by .profile to initialize environment variables
# and set up the path.

################################################################
#                     PLATFORM-SPECIFIC SETTINGS               #
################################################################

# BIRCH_DEBUG = 1 will cause each successive profile.source, platform.profile.source
# etc. to each print progress messages.
BIRCH_DEBUG=0
if [ $BIRCH_DEBUG -eq 1 ]  
   then
      echo Running profile.source
fi

##*******************************************************
## LOCATION OF BIRCH. The following line that sets the BIRCH
## environment variable is generated during installation and
## updating. This file should never be edited manually.
## All local changes should  be made in $BIRCH/local/admin
##*******************************************************

BIRCH=/home/birch/BIRCH
export BIRCH


# Get critical platform-specific settings, which will
# govern how other settings are made. If you have additional
# commands that you want to override commands in this file,
# put them in $BIRCH/local/admin/local.profile.source, which is called
# at the end of this file.
. $BIRCH/local/admin/platform.profile.source



################################################################
#                         GLOBAL SETTINGS                      #
################################################################

#----------------- BIRCH ENVIRONMENT VARIABLES ---------------------
#useful environment variables for sequence work
# both upper and lowercase equivalents are permitted

birch=$BIRCH
LOCAL=$BIRCH/local
local=$LOCAL

# Documentation and data directories
DOC=$BIRCH/doc
doc=$DOC
DAT=$BIRCH/dat
dat=$DAT
TUTORIALS=$BIRCH/tutorials
tutorials=$TUTORIALS

# Databases
GENBANK=$BIRCH/GenBank
genbank=$GENBANK
GB=$GENBANK
gb=$GENBANK
PIR=$BIRCH/PIR
pir=$PIR
RE=$BIRCH/REBASE
BLASTDB=$GENBANK #databases used by standalone blast

# BIRCHLIBS - libraries for Python scripts
BIRCHPYLIB=$BIRCH/script/birchpylib

export birch dat DOC doc TUTORIALS tutorials GENBANK \
   genbank GB gb PIR pir RE BLASTDB BIRCHPYLIB
#------------------------------------------------


# Use this for a more diverse server cluster
# Platform-specific setup commands
# BIRCH_BIN - location of BIRCH binaries
# RM_CMD - file to use for 'rm' command
BIRCHLIBS=""

# Apple is transitioning from the Intel architecture to ARM64.
# We want to put bin-macos-arm64 (BIRCH_BIN) first in the PATH, so that
# native arm64 binaries are found first. If a program is not
# available for arm64, the shell will search for it in 
# bin-osx-x86_64 (BIRCH_BIN_ALT). The Intel binaries in that directory
# will be run in emulated mode by Rosetta2.
BIRCH_BIN_ALT=""
case "$BIRCH_PLATFORM" in
  solaris-sparc)
    BIRCH_BIN=bin-solaris-sparc
    RM_CMD=/usr/bin/rm
    ;;
  solaris-amd64)
    BIRCH_BIN=bin-solaris-amd64
    RM_CMD=/usr/bin/rm
    ;;
  linux-intel)
    BIRCH_BIN=bin-linux-intel
    RM_CMD=/bin/rm
    ;;
  linux-x86_64)
    BIRCH_BIN=bin-linux-x86_64
    RM_CMD=/bin/rm
    ;;    
  linux-arm64)
    BIRCH_BIN=bin-linux-arm64
    BIRCH_BIN_ALT=bin-linux-x86_64    
    RM_CMD=/bin/rm
    ;;    
  osx-x86_64)
    BIRCH_BIN=bin-osx-x86_64
    RM_CMD=/bin/rm
    ;;
  macos-arm64)
    BIRCH_BIN=bin-macos-arm64
    BIRCH_BIN_ALT=bin-osx-x86_64
    RM_CMD=/bin/rm
    ;;
  win7-64)
    BIRCH_BIN=bin-win7-64
    RM_CMD=/bin/rm
    ;; 
  *) 
    BIRCH_BIN=bin-linux-x86_64
    RM_CMD=/usr/bin/rm
    ;;
esac

export BIRCH_BIN RM_CMD


# $BIRCH/script is for scripts that work on all platforms
# $BIRCH_BIN is a bin directory, chosen in profile.source,
# with platform-specific binaries


# Check the current path for $BIRCH_BIN. Since one shell can
# launch another shell, we don't want to keep adding $BIRCH_BIN each
# time a new shell is spawned.
COUNT=`echo $PATH | grep -c $BIRCH/$BIRCH_BIN`
if [ "$COUNT" -eq "0" ] 
   then
      case "$BIRCH_PLATFORM" in
          macos-arm64 | linux-arm64  )         
              PATH=$BIRCH/local/script\:$BIRCH/local/$BIRCH_BIN\:$BIRCH/local/$BIRCH_BIN_ALT\:$PATH\:$BIRCH/script\:$BIRCH/$BIRCH_BIN:$BIRCH/$BIRCH_BIN_ALT      
              ;;
          * )
              PATH=$BIRCH/local/script\:$BIRCH/local/$BIRCH_BIN\:$PATH\:$BIRCH/script\:$BIRCH/$BIRCH_BIN
      esac
fi
export PATH


# Set Manual path
case "$BIRCH_PLATFORM" in
  solaris-*)
	if [ -z "$MANPATH" ] 
	   then
	      MANPATH=$BIRCH\:$BIRCH/local
	   else
	      COUNT=`echo "$MANPATH" | grep -c $BIRCH`
              if [ "$COUNT" -eq "0" ] 
                 then
	            MANPATH=$MANPATH\:$BIRCH\:$BIRCH/local
	      fi
	fi
	export MANPATH
    ;;
# On Debian Linux, man -w doesn't work, and there is no alternative
# switch that works for linux distributions. For now the workaround
# is just to check the $MANPATH variable.
#  linux-*)
#	MANPATH=`man -w`\:$BIRCH\:$BIRCH/local
#	export MANPATH
#    ;;
  *)
        # This is probably safest when we don't know how
	# man works on a system.If you try setting MANPATH
	# on a system that uses /etc/man.config, you clobber
	# all manual pages other than the BIRCH pages.
	if [ ! -z "$MANPATH" ] 
	   then
	      COUNT=`echo "$MANPATH" | grep -c $BIRCH`
              if [ "$COUNT" -eq "0" ] 
                 then
	            MANPATH=$MANPATH\:$BIRCH\:$BIRCH/local
	      fi	   
	fi
        export MANPATH
    ;;
esac

#------------------------ BIRCH SETTINGS --------------

# Get values of environment variables
if [ -f $BIRCH/admin/birch_settings_Bourne.source ]
   then
      . $BIRCH/admin/birch_settings_Bourne.source
fi

BIRCH_PROMPT="Y"
# Personal setting for prompt overrides all other settings.
if [ -f $HOME/.config/BIRCH/BIRCHsettings.source ]
then
    result=`grep 'BIRCH_PROMPT=N' $HOME/.config/BIRCH/BIRCHsettings.source`
    if [ "$result" != "" ]
    then
        BIRCH_PROMPT="N"
    fi
fi
export BIRCH_PROMPT

if [ "$BIRCH_PROMPT" = "Y" ]
then
    if [ -f $BIRCH/local/admin/set_birch_prompt_Bourne.source ]
    then  # Local settings override default settings
        . $BIRCH/local/admin/set_birch_prompt_Bourne.source
    else # default
        . $BIRCH/admin/set_birch_prompt_Bourne.source
    fi
fi

#------------------------ TEMPORARY DIRECTORIES --------------
# This variable may be changed in local.profile.source,
# telling where temporary files may be written for some
# scripts which run programs that generate very large
# temporary files.
# It looks like BIRCH_TMP isn't currently used in BIRCH, but
# we'll keep it for now until we can be absolutely sure.
# It will probably reappear as a setting that can be changed
# in birchadmin.
BIRCH_TMP=""
export BIRCH_TMP


#---------------------------- OTHER SETTINGS -----------------
# noclobber must be off so that files can be overwritten
# unset noclobber
# unset noclobber appeears not to work on some linux systems,
# so we do it this way.
set +o noclobber

# Limit core files to 0 bytes
ulimit -c 0

# Printer variables
PSPRINT=ccp
export PSPRINT


################################################################
#              APPLICATION-SPECIFIC SETTINGS                   #
################################################################

#-------------------------- BioLegato programs: eg. birch, bldna, blprotein, blmarker, bltree...

if [ -f $BIRCH/admin/setblenv.profile.$BIRCH_PLATFORM.source ]
   then
      . $BIRCH/admin/setblenv.profile.$BIRCH_PLATFORM.source
fi


#-------------------------- ACEDB
ACEDB=$BIRCH/acedb
ACE_EDIT_COMMAND=$BL_TextEditor
ACE_PDF_COMMAND=$BL_PDFViewer
ACE_PS_COMMAND=$BL_PSViewer
ACE_BITMAP_VIEWER=$BL_ImageViewer
ACE_SPREADSHEET=$BL_Spreadsheet
ACE_DOCUMENT=$BL_Document
export ACE_EDIT_COMMAND ACE_PDF_COMMAND ACE_PS_COMMAND ACE_BITMAP_VIEWER ACE_SPREADSHEET ACE_DOCUMENT

#--------------------------- ABYSS
#alias zsh=$BIRCH/bin-$BIRCH_PLATFORM/zsh

#--------------------------- ARTEMIS
ARTEMIS_HOME=$BIRCH/java/artemis


#-------------------------- CBB
HISAT2_HOME=$BIRCH/lib-$BIRCH_PLATFORM/hisat2

#-------------------------- FASTA
FASTLIBS=$DAT/fasta/fastgbs
export FASTLIBS

#-------------------------- FSAP


#-------------------------- MAPMAKER, GENEHUNTER
MAPM_LIB=$DAT/mapmaker
GH_DIR=$DAT/genehunter
#GS_LIB=$MAPM_LIB/ghostscript
export MAPM_LIB GH_DIR


#-------------------------- NCBI
NCBI=$BIRCH/pkg/NCBI
CN3D_HOME=$NCBI
export NCBI CN3D_HOME


#--------------------------- PRIMER3
PRIMER_BIN=$BIRCH/$BIRCH_BIN
export PRIMER_BIN

#--------------------------- TIGR TM4
# If your system has enough memory, set this to at least 512 or 1024
TMEV_JAVA_MEMORY=256
export TMEV_JAVA_MEMORY


#--------------------------- XYLEM
XYLEM_PLATFORM=$BIRCH_PLATFORM
export XYLEM_PLATFORM

################################################################
#                       SYSTEM STATISTICS                      #
#                                                              #
# Put code here for recording user traffic etc.                #
################################################################
# BIRCH_LOGGING is not currently used in BIRCH, but is
# retained for now until we can check carefully that removing
# it won't break anything. 
BIRCH_LOGGING=0
export BIRCH_LOGGING
 
################################################################
#                     LOCAL EXTENSIONS TO BIRCH                #
################################################################

if [ -f $BIRCH/local/admin/local.profile.source ]
   then
      . $BIRCH/local/admin/local.profile.source
fi

################################################################
#             User Preferences that override defaults          #
################################################################

BIRCHSettingsFile=$HOME/.config/BIRCH/BIRCHsettings.source
if [ -f $BIRCHSettingsFile ]
   then
      . $BIRCHSettingsFile
fi

BLHelperFile=$HOME/.config/BIRCH/BLHelper.source
if [ -f $BLHelperFile ]
   then
      . $BLHelperFile
fi

################################################################
#                  FIRST TIME LOGIN PROCEDURES                 #
# This simulates a .login file for sh and similar shells       #
################################################################
# Only run the login script once.

# This one didn't seem to work.
# We can test this by seeing if BIRCH has been added to the PATH.
#COUNT=`echo $PATH | grep -c $BIRCH`
#if [ "$COUNT" -eq "0" ] 
#   then
#        . $BIRCH/admin/profile.login.source
#fi

# Another approach:
# We can test this by seeing if BIRCH_LOGGEDIN has been set.
if [ -z "$BIRCH_LOGGEDIN" ] 
   then
        BIRCH_LOGGEDIN=1
        export BIRCH_LOGGEDIN
        . $BIRCH/admin/profile.login.source
fi       
