#!/bin/sh
#
#***************************************************************************
#       $HOME/.lcmodel/execution-scripts/make-batch  (18 January 2012)
#
#     This script can avoid overloading slow computers with many simultaneous 
# LCModel analyses.  It produces a batch file for successive LCModel analyses.
#
#     You prepare these with LCMgui as usual, clicking "Run LCModel" and then
# preparing the next analysis.  You start the analyses by entering the
# following from your Unix shell:
#
#   $HOME/.lcmodel/bin/run-batch &
#
# The analyses are then executed one after another, with one starting only 
# after the preceding one is finished.
#***************************************************************************
#
#----------------------------------------------------------------------------
#      LCMgui executes this script in background with 3 or 4 arguments.  
# They are $1--$4:
#
# $1: absolute path of temporary directory produced by LCMgui.
#
# $2: For the N'th run started from an LCMgui session, 
#     $2 = N*5 + <your default "nice" value> (but with $2 <= 19).
#     This provides a crude way to assign successive runs lower priorities, 
#     but the method of this script is better.
#
# $3: absolute path of the Output Script that will print out your results 
#     and save files.  This Output Script is automatically produced by LCMgui.
#
# $4: absolute path of the directory where your results will be saved, if you 
#     elected in the LCMgui "Save Files" menu to have files saved.
#     If you did not elect to have files saved, then $4 is missing.
#----------------------------------------------------------------------------
#
mkdir  -p  $HOME/.lcmodel/temp
touch  $HOME/.lcmodel/temp/batch
chmod  750  $HOME/.lcmodel/temp/batch
#
#-----------------------------------------------
#echo "/usr/bin/nice -9  $HOME/.lcmodel/bin/lcmodel  <$1/control  2>>$HOME/.lcmodel/temp/batch-messages"  >> $HOME/.lcmodel/temp/batch
#
#     Remove the "#" from the "echo ..." command above, and insert a "#" in 
# column 1 of the "echo ..." command below to run your batch runs at a lower 
# priority.  You can only do this if the file /usr/bin/nice is on your system.
#
echo "$HOME/.lcmodel/bin/lcmodel  <$1/control"  2>>$HOME/.lcmodel/temp/batch-messages  >> $HOME/.lcmodel/temp/batch
#-----------------------------------------------
#
echo "$3
mkdir  $1/done"  >>  $HOME/.lcmodel/temp/batch
