#-----------------------------------------------------------------------------
# IRACproc: IRAC Post-BCD Processing v4.3 SETUP
#-----------------------------------------------------------------------------
(c) 2005 Mike Schuster, Massimo Marengo (mmarengo@cfa.harvard.edu)
(c) 2005 SAO - Smithsonian Astrophysical Observatory

Harvard-Smithsonian Center for Astrophysics
Smithsonian Astrophysical Observatory

10 Dec 2008

Once your system has the required configuration (see System requirements), 
this software suite should only take a few minutes to install, as very little 
is needed to configure IRACproc to run. We happen to use pico as our text 
editor in the examples, though you may use your preferred text editor instead.

#-----------------------------------------------------------------------------
# Step #1 - System requirements
#-----------------------------------------------------------------------------
It is assumed that the following are installed on your system:

REQUIRED
--------
MOPEX (ver. 18.1.5 or newer) 
Perl (ver. 5.6 or newer)
PDL(v2.4.x or newer w/ bad values support enabled)
Perl modules (available from search.cpan.org):
    Astro::FITS::Header
    Astro::FITS::CFITSIO

Note that Perl is normally available in all Unix Systems. PDL is also 
pre-installed by in most Linux systems, but often is compiled without 
bad value support (required). Instructions on how to install MOPEX are 
given below.


OPTIONAL
--------
SAOimage DS9 [our preference for image display]
IRAF [optional features - automated image inspection and photometry package]


PDL, or Perldl, is a development environment much like IDL or MATLAB, that is 
based on Perl and is distributed freely.

The software has been tested on the Linux 32 and 64 bit platform, and on 
the MacOSX 5.x Intel platform. The software can run on both cshell (tcsh) 
and bash shells. 


IRACproc may also work under Solaris, but... no guaranties.

#-----------------------------------------------------------------------------
# Setup #2  - Download and Unpack the IRACproc distribution
#-----------------------------------------------------------------------------
Download the following files from 
http://www.cfa.harvard.edu/~mmarengo/IRACproc:

    * IRACproc-4.3.tar.gz: main IRACproc distribution
    * IRAC_psfs-2.0.tar.gz: PSF files 

In the directory where the files are downloaded, run the following 
commands:

user_name][ cp IRAC*.tar.gz <IRACproc_install_path>
user_name][ cd <IRACproc_install_path>
user_name][ tar xzvf IRACproc-<VER>.tar.gz

user_name][ cd IRACproc/
user_name][ tar xzvf ../IRAC_psfs-<VER>.tar.gz

where <IRACproc_install_path> is the directory, with full path, where 
IRACproc will be installed.

Documentation can be found in IRACproc/docs/. Follow the instructions given 
in SETUP (this document), HOWTOs, etc.


#-----------------------------------------------------------------------------
# Setup #3 - Download and Install MOPEX
#-----------------------------------------------------------------------------
Grab the latest distribution of MOPEX for your platform from the Spitzer 
Space Center (SSC) web site, at the address:

http://ssc.spitzer.caltech.edu/postbcd/download-mopex.html

Follow the instructions given by the SSC, and first run the GUI. Set the 
checkbox to automatically check for updates in the GUI menu, to obtain the 
latest version of the software. Once the software is updated, close the 
GUI and setup the software to enable running the command-lime MOPEX which 
is used by IRACproc:

1 If you are running cshell (tcsh) edit the file mopex-script-env.csh to
make sure that the following variables are set as shown (use the actual
<mopex_install_path> where you have installed MOPEX):

user_name][ pico mopex-script-env.csh

setenv MOPEX_INSTALLATION <mopex_install_path>/mopex
setenv SIRTF_QA ./
setenv SIRTF_CDF ./
unsetenv SIRTF_CAL

2 If you are running bash (default for MacOSX and some Linux 
distributions) copy the file mopex-script-env.sh from the 
<IRACproc_install_path> directory into the <mopex_install_path>/mopex 
directory and edit the path of your MOPEX installation in the first 
line:

user_name][ cp <IRACproc_install_path>/mopex-script-env.sh <mopex_install_path>/.

export MOPEX_INSTALLATION=<mopex_install_path>/mopex

3 There is a bug in the MOPEX script "simulate" that prevents IRACproc 
from processing data sets larger than 1000 BCD images. The bug is still 
present in the newest version of MOPEX (v18.2 w/ GUI). Replace the MOPEX 
simulate script with the one provided with IRACproc (make a copy first). 

user_name][ cd /<mopex_install_path>/mopex/bin/
user_name][ mv simulate.pl simulate.pl.orig
user_name][ cp /<IRACproc_install_path>/IRACproc/simulate.pl .
user_name][ chmod +x simulate.pl



#-----------------------------------------------------------------------------
# Setup #4 - Shell Resource Control File [.cshrc]
#-----------------------------------------------------------------------------
You need to modify your shell control resource file (.cshrc if you are 
using cshell or tcsh, and .bashrc if you are using bash) to set up the 
correct paths to IRACproc and MOPEX.

1 If you are running cshell, copy the file irac_procrc.csh into your home
directory, with the name .irac_procrc, and edit the file to replace the
<IRACproc_install_path> with your installation path for IRACproc:

user_name][ cp <IRACproc_install_path>/IRACproc/irac_procrc.csh ~/.irac_procrc
user_name][ pico ~/.irac_procrc

setenv IRAC_PROC /<IRACproc_install_path>/IRACproc

2 If you are running bash, copy the file irac_procrc.sh into your home 
directory, with the name .irac_procrc, and edit the file to replace the 
<IRACproc_install_path> with your installation path for IRACproc:

user_name][ cp <IRACproc_install_path>/IRACproc/irac_procrc.sh ~/.irac_procrc
user_name][ pico ~/.irac_procrc

export IRAC_PROC=/<IRACproc_install_path>/IRACproc

3 Edit your .cshrc (if you are using cshell or tcsh) to add the following
lines:

user_name][ pico .cshrc

# IRACproc software
source <mopex_install_path>/mopex/mopex-script-env.csh
source $HOME/.irac_procrc

4 Edit your .bashrc (if you are using bash) to add the following lines:

user_name][ pico .cshrc

# IRACproc software
source <mopex_install_path>/mopex/mopex-script-env.sh
source $HOME/.irac_procrc

5 Make sure to execute the edited .cshrc file in all your open terminals:

user_name][ source ~/.cshrc


#-----------------------------------------------------------------------------
# Setup #5 - PDL Resource Control File [.perldlrc]
#-----------------------------------------------------------------------------
Copy the PDL control resource file from the IRACproc distribution to your 
home directory:

user_name][ cp $IRAC_PROC/perldlrc ~/.perldlrc

Note the "." in the destination filename, which is critical. At this point 
you can test PDL running the PDL shell and some of the demos:

user_name][ perldl
perldl> demo
perldl> demo pdl
perldl> demo_pgplot

When starting PDL, you may receive the following message:

Unable to find PDL/pdldoc.db in...

This is because you either do not have the online documentation installed 
(module PDL::Doc::Perldl can be downloaded at search.cpan.org - see your 
System Administrator), or it is installed incorrectly.

You can work around this issue by commenting out (with a hash "#") a line 
in the .perldlrc file:

user_name][ pico ~/.perldlrc

# use PDL::Doc::Perldl; # online docs module



#-----------------------------------------------------------------------------
# Setup #6 - IRAF - for optional features (photometry and image inspection)
#-----------------------------------------------------------------------------
If you already have a loginuser.cl file, you will need to modify it. This 
file is usually located in ~/iraf/.

user_name][ pico ~/iraf/loginuser.cl

Now paste the following into the loginuser.cl file (Replace 
<IRACproc_install_path> with the installation path for IRACproc.):

# LOGINUSER.CL -- User login file for the IRAF command language.

reset stdimage = imt512
reset imtype   = "fits"

# IRAC Processing
set IRACproc = "<IRACproc_install_path>/IRACproc/"
 
task mkbpm       = IRACproc$source/mkbpm.cl
task inspect     = IRACproc$source/inspect.cl
 
task do_nsfind   = IRACproc$source/do_nsfind.cl
task psort_xy    = IRACproc$source/psort_xy.cl
task pdump_xy    = IRACproc$source/pdump_xy.cl
task do_nsphot   = IRACproc$source/do_nsphot.cl
task pdump_xymag = IRACproc$source/pdump_xymag.cl
task do_wcsctran = IRACproc$source/do_wcsctran.cl
task run_nsphot  = IRACproc$source/run_nsphot.cl

# Load packages that will be used for processing

images
immatch
imutil
tv

lists

stsdas
tables
analysis
dither

noao
digiphot
apphot
ptools

keep

------------------
There is a sample loginuser.cl file located in the IRACproc directory. If you 
do not already have a loginuser.cl file, copy the template provided into your 
IRAF directory.

user_name][ cp $IRAC_PROC/loginuser.cl ~/iraf/