#!/bin/sh
#
# $HOME/.lcmodel/other/bin2raw               (7 March 2003)

#     If you want to modify this file, use this file as a template only; copy 
# it to my-bin2raw (in the same directory as bin2raw), and then edit 
# my-bin2raw.
#     LCMgui always first attempts to execute my-bin2raw.  If LCMgui cannot 
# find my-bin2raw, then it executes bin2raw.
#     bin2raw will be overwritten by LCMgui updates, but your my-bin2raw will 
# not be overwritten.

#
#============================================================================
#      LCMgui executes this script and supplies 3 arguments to it, i.e., it 
# executes
#   $HOME/.lcmodel/other/bin2raw  $1  $2  $3
#----------------------------------------------------------------------------

#      The 3 arguments supplied by LCMgui are:

# $1 = the absolute pathname of the data file that you selected to be 
#      analyzed.

# $2 = the absolute pathname (with a "/" at the end) of the temporary 
#      directory where you must put the output from this script.

# $3 = met if the data file contains your water-suppressed data (or if the 
#          data file contains both your water-suppressed data and your 
#          unsuppressed water reference data for eddy-current correction).
#    = h2o if the data file contains only the unsuppressed water reference 
#          data.
#      
# (C programs can access $3 as argv[3], etc.)
#----------------------------------------------------------------------------
#
#     This script must output the following files:

# $2$3/RAW = LCModel RAW file.

# $2h2o/RAW = LCModel RAW file of the unsuppresed water reference data for
#             eddy-current correction. 
#                  This is only possible if your data file contains both the
#             unsuppressed and suppressed data.  In this case, $3 = "met", and 
#             you output both $2$3/RAW and $2h2o/RAW.
#                  If the unsuppressed and suppressed are in different files,
#             then you only output $2$3/RAW, first when $3 = "met", and later 
#             LCMgui calls this script again with another $1 and with 
#             $3 = "h2o"

# $2$3/cpStart : sets any default Control Parameters (which you can later 
#                  modify in LCMgui) that can be obtained from (the headers 
#                  of) your data file.
#                The format is illustrated below.

# $2$3/extraInfo : This is used internally by LCMgui and is seldom output by 
#                    this script.
#                  $HOME/.lcmodel/philips/bin2raw defines and illustrates this 
#                    output more completely.

# $2$3/error : Error messages on aborts should go here.  They will then be 
#                displayed by LCMgui, PROVIDED that you then exit with 
#                "exit 0"; i.e., a "successful" exit.  It is essential that 
#              ALL exits (successful and error exits) be with "exit 0".
#              From a C program, you must also always exit with "exit(0)".

#============================================================================
#
#                       Remove old files
#                       ================
#
#      Delete possible old files left over after "Reload Data" button has been 
# clicked.
rm  -f  $2$3/RAW
rm  -f  $2h2o/RAW
rm  -f  $2$3/cpStart
rm  -f  $2$3/extraInfo
rm  -f  $2$3/error
#----------------------------------------------------------------------------
#
#                              RAW file
#                              ========
#      Normally you first have to extract the data from $1 and write it into
# $2$3/RAW as an LCModel RAW file.  In this simple example, it is assumed that 
# $1 already is an LCModel RAW file, and that no conversion has to be done.  
# $1 must then only be copied to $2$3/RAW.
#     Therefore, "cp $1 $2$3/RAW" and "chmod 640 ..." below must always be
# present.  (LCMgui has already created the directory $2$3)

cp  $1  $2$3/RAW

#
# Write permission is necessary below to allow the file to be overwritten in 
#   case the "Reload Data" button is clicked on.
#

chmod 640  $2$3/RAW

#----------------------------------------------------------------------------
#                           cpStart File
#                           ============
#      In this simple example, we only have the LCModel RAW file, no extra
# header information for Control Parameters.  So we do not even make
# $2$3/cpStart.  The Control Parameters can then be entered later manually in 
# LCMgui (or automatically from the Control-Defaults File).
#
#      The cpStart file must have one Control Parameter declaration per line 
# in the following format:
#   <control parameter>=  <value>
# Examples are:
#
# nunfil= 2048
# ppmref(1,2)= 2.01
# title= 'Exam 777-77, ... Head-Coil'
# doecc= T
#
# Note the following strict rules for this file:
# (1) The Control Parameter names must be lower case and contain no whitespace.
# (2) The "=" must immediately follow the Control Parameter name with no
#     whitespace. 
# (3) There must be whitespace between the "=" and the value.
# (4) For logical variables, use "T" instead of ".TRUE." and "F" instead of 
#     ".FALSE." (as in "doecc= T" above).
#
#----------------------------------------------------------------------------
#
# You must always exit this script with "exit 0"
#
exit 0
