#!/bin/sh
#==============================================================
#
#  Abs:  LCLS ArchiveViewer script
#
#  Name: lclsarch 
#
#  Rem:  This script may be executed to bring up the ArchiveViewer for
#        plotting LCLS archiver PVs. 
#
#  Usage: This script should be in the users path.
#
#  Facility: SLAC/LCLS
#
#  Auth: 23-Jan-2007, Bob Hall   (RDH)
#  Rev:  dd-mmm-yyyy, Reviewer's Name    (USERNAME)
#--------------------------------------------------------------
#
#  Mod:
#        08-Mar-2010, Bob Hall (RDH)
#           Change to support setting the default printer to
#           physics-lclslog for "File => Print...".  To do this
#           added JVM arg -Dsun.java2d.print.polling=false
#           as a workaround to a bug in some versions of Java 1.5
#           that cause intermittent crashes when calling
#           PrinterJob.lookupPrintServices().  See bug 6835077
#           and 6604107 on http://bugs.sun.com.
#        29-May-2009, Bob Hall (RDH)
#           Changed default printer to physics-lclslog for
#           right click of plot area.
#        27-May-2009, Bob Hall (RDH)
#           Changed location where Archive Viewer jar file is
#           located from tools/javalib to $EPICS_EXTENSIONS/javalib.
#        06-Dec-2008, Bob Hall (RDH)
#           Added the capability to process an argument that
#           specifies an Archive Viewer configuration file.
#        25-Oct-2006, Bob Hall (RDH)
#           Added JVM arg -Dsun.java2d.pmoffscreen=false for
#           performance improvement when run over Remote X (ssh). 
#        05-04-2007, Jingchen Zhou (JINGCHEN) 
#           Modifed to use the comman config and data area defined for LCLS
#           via two environment variables: ARCHCONFIGFILES and ARCHDATAFILES
#        05-07-2008, Judy Rock (JROCK)
#           Updated to support both AFS based dev and NFS based prod
#==============================================================
#
# After the sourcing of epicsReset.bash, the environment variable
# EPICS_PR_LIST will be set.
#
if [ -d /afs/slac/g/lcls ]; then
    source /afs/slac/g/lcls/epics/setup/epicsReset.bash
    cd $EPICS_EXTENSIONS/javalib
else
    source /usr/local/lcls/epics/setup/epicsReset.bash
    cd $EPICS_EXTENSIONS/javalib
fi

#
# Set the default (first) printer displayed (when right clicking
# the plot window) to physics-lclslog.  This is done by setting
# the first item in EPICS_PR_LIST to physics-lclslog.  First,
# prefix the EPICS_PR_LIST environment variable with ":" and then
# remove ":physics-lclslog" from EPICS_PR_LIST (prefixing this
# string with ":" ensures that the string "physics-lclslog" will
# be removed if this string is the first item in EPICS_PR_LIST).
# Then prefix the  EPICS_PR_LIST environment variable with
# the string "physics-lclslog". 
#
first_printer=physics-lclslog

new_list=:${EPICS_PR_LIST}

after_removal=${new_list//:$first_printer/}

export EPICS_PR_LIST=$first_printer${after_removal}

#
# Java version 1.5 (rather than the default Java version 1.4.2) is needed for 
# the SNS Archive Viewer.
#
export JAVAVER=1.5

#
# Invoke the Archive Viewer with the list of local printers specified
# in environment variable EPICS_PR_LIST.
#

if [ -n "$1" ]; then
    java -Dlocalprinters=$EPICS_PR_LIST -Dsun.java2d.pmoffscreen=false -Dsun.java2d.print.polling=false -Xms512m -Xmx512m -jar archiveviewer.jar -u http://lcls-archsrv/cgi-bin/ArchiveDataServer.cgi -d $ARCHCONFIGFILES -e $ARCHDATAFILES -f $1>& /dev/null

else
    java -Dlocalprinters=$EPICS_PR_LIST -Dsun.java2d.pmoffscreen=false -Dsun.java2d.print.polling=false -Xms512m -Xmx512m -jar archiveviewer.jar -u http://lcls-archsrv/cgi-bin/ArchiveDataServer.cgi -d $ARCHCONFIGFILES -e $ARCHDATAFILES >& /dev/null

fi

# End of script
