#!/bin/csh
#
# $Id: meme.csh.in 5026 2010-10-20 07:00:35Z james_johnson $
# $Log$
#

# set the mpi command
set mpicmd = '@MPICMD@'

# set the machine/OS type
set machid = @MACH_ID@

# handle interrupts
set exe_status = 0
onintr cleanup

# get input arguments
set memeargs = ""
set bindir = "@MEMEDIR@/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 >& /dev/null
set exe_status = $status
if ($exe_status) then
  goto usage
endif

$exe $memeargs $exe_args
set exe_status = $status

cleanup:
exit $exe_status

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