#!/bin/csh

# Genographer 1.6 requires that a genograph.cfg
# be in the directory in which it is launched.
# Curse you Microsoft, for inflicting this idiotic
# mindset on the whole world! 


#------------------------------------
# We need to get around the
# requirement that genograph.cfg must be present in every directory
# in which genographer will be run. The solution is to create a lock file
# for every instance of genographer. When a genographer job terminates,
# the lock file is removed. If no more lock files remain,
# genographer removes genograph.cfg.

# RM_CMD - command to be used for removing files and directories
if (-e /usr/bin/rm) then
   set RM_CMD = /usr/bin/rm
else
   if (-e /bin/rm) then
      set RM_CMD = /bin/rm
   else
      set RM_CMD = rm
   endif
endif


set LOCK = genographer.lock.$$
echo  "This file is created when an instance of genographer is running." > $LOCK
echo  "It should automatically be removed when genographer terminates. " >> $LOCK

if !(-e genograph.cfg) cp $birch/java/genographer/genograph.cfg ./genograph.cfg

java -cp $birch/java/genographer genographer $birch/java/genographer $argv

$RM_CMD $LOCK
set COUNT = `ls -1 | grep -c genographer.lock`
if ($COUNT == "0") $RM_CMD genograph.cfg