#!/bin/csh
#
# $Id: meme.txt 3915 2009-07-21 07:10:21Z tbailey $
# $Log$
# Revision 1.8  2005/10/07 05:33:55  nadya
# keep uniform name MEME_LOGS throughout scripts.
#
# Revision 1.7  2005/10/05 06:18:35  nadya
# use full path for "rm". Asssume everybody has /bin/rm.
#
# Revision 1.6  2005/10/02 05:54:33  nadya
# add sourcing meme_config.csh to set all the environment.
# use variables when calling real binaries
#
# Revision 1.5  2005/09/16 22:24:10  nadya
# put temp files in LOGS
#
# Revision 1.4  2005/08/31 04:17:13  nadya
# move usage part to etc/*.doc file
#
# Revision 1.3  2005/08/24 04:16:37  nadya
# add machid
#
# Revision 1.2  2005/08/24 00:31:04  nadya
# set machid during configure step, and user variable for it
#
# Revision 1.1.1.1  2005/07/30 01:19:40  nadya
# Importing from meme-3.0.14, and adding configure/make
#
#

# set the mpi command
set mpicmd = ''

# set the machine/OS type
set machid = linux

# handle interrupts
set exe_status = 0
set usage = /opt/chipster/tools/meme_4.2.0/LOGS/meme.usage.$$.tmp
onintr cleanup

# get input arguments
set memeargs = ""
set bindir = "/opt/chipster/tools/meme_4.2.0/bin"
set exe = "$bindir/meme.bin"
set exe_check = $exe
set exe_args = ""
while ("$1" != "")
  switch ($1)
    case -p:
      shift
      if ($machid == rs6000) then
        set exe = "poe $bindir/meme_p"
        set exe_check = "poe $bindir/meme.bin "
        set exe_args = "-nodes $1 -tasks_per_node 8"
      else 
        set exe = "$mpicmd $1 $bindir/meme_p"
        set exe_check = "$mpicmd 1 $bindir/meme_p"
      endif
      breaksw
    default:
      set memeargs = "$memeargs $1"
  endsw
  shift
end

# print usage message if no arguments left
if ("$memeargs" == "") then
  set memeargs = "$memeargs -h"
endif

# check the syntax
$exe_check $memeargs -check_syntax >& $usage
set exe_status = $status
if ($exe_status) then
  goto usage
endif

$exe $memeargs $exe_args
set exe_status = $status

cleanup:
if (-e $usage) /bin/rm -f $usage
exit $exe_status

# Describe MEME and its output format:
usage:
cat /opt/chipster/tools/meme_4.2.0/etc/meme.doc >> $usage
tty -s                        # see if stdin is a terminal
if ($status == 0) then
  more $usage
else
  cat $usage
endif
goto cleanup
