#!/bin/tcsh -f

# This script can be used to generate a new B-field map for the
# GlueX solenoid. This was developed to work on Mac OS X using Wine
# to run the windows programs from the Poisson/Superfish suite.
#
# The Windows executables themselves can be found in the subversion
# repository here:
#
#  https://halldsvn.jlab.org/repos/trunk/home/davidl/bfield_poisson/Poisson_OSX/LANL.tgz
# 
# Unpack the LANL.tgz tarball and set your LANL environment variable
# to point to it.
#
# You will also need the poisson2calibDB.pl script which should be
# in the same directory as this script. Set your POISSON2CALIBDB
# environment variable to point to the script if you are running
# from a different directory.
#
# You'll need to provide Automesh (.am) and grid (.IN7) files
# to specify the map.
#
# Finally, edit this file to include the proper settings for your
# system and the map you are generating.


# Date and Amperage part of file name
set today=20140520
set current=1200A
set config=${today}_${current}

# Location of wine executable
if ( ! $?WINE ) then
	setenv WINE /usr/local/wine/1.6.1/bin/wine
endif

# Location of LANL directory containing Windows executables
if ( ! $?LANL ) then
	setenv LANL ${HOME}/HallD/subsystems/Solenoid/Poisson_OSX/LANL
endif

# Location of poisson2calibDB.pl script
if ( ! $?POISSON2CALIBDB ) then
	setenv POISSON2CALIBDB ./poisson2calibDB.pl
endif

#---------------------------------------------------------------
#             shouldn't need to edit below here

set cmd="$WINE $LANL/AUTOMESH.EXE gluex_sol_${config}.am"
echo $cmd
$cmd

set cmd="$WINE $LANL/POISSON.EXE GLUEX_SOL_${config}.t35"
echo $cmd
$cmd

set cmd="$WINE $LANL/SF7.EXE gluex_sol_${config}.IN7"
echo $cmd
$cmd

set cmd="$POISSON2CALIBDB OUTSF7.TXT"
echo $cmd
$cmd

# The poisson2calibDB.pl script always writes a file named
# solenoid_1500_poisson so we need to rename it.
mv solenoid_1500_poisson solenoid_${current}_poisson_${today}

