#!/data/oir/IRAF2.14.1/iraf/bin.redhat/ecl.e -f
# This script runs IRAF RVSAO.XCSAO from a Unix command line
# Replace the path in the first line with one appropriate to
# the architecture of your machine

# March 31, 2009
# By Doug Mink

string uprm, hm, tempcom

# Set machine type appropriately
set arch=".redhat"

# Set the terminal type.
if (envget("TERM") == "sun") {
    stty gterm
} else if (envget("TERM") == "xterm") {
    stty xterm
} else if (envget("TERM") == "network") {
    stty vt100
} else {
    stty xterm
}

# Set the IRAF home and parameter directories
if (defvar("irafhome")) {
    hm = envget("irafhome")
    i = strlen(hm)
    if (substr(hm, i, i) == "/")  
        set (home = hm)
    else
        set (home = hm // "/")
    set uparm = "home$uparm/"
    }
else {
    hm = envget ("HOME")
    set (home = hm // "/IRAF/")
    set uparm = "home$uparm/"
    }

if (defvar("UPARM")) {
    uprm = envget("UPARM")
    i = strlen(uprm)
    if (substr(uprm, i, i) == "/")  
        set (uparm = uprm)
    else
        set (uparm = uprm // "/")
  }

# Set the user name which may appear on graphical output
if (envget("USER") != "") {
    set user = envget("USER")
    }

if (args == "") {
    print ("XCSAO: Cross-correlate a spectrum against a set of templates")
    print ("usage: xcsao spectrum [templates=xxx][other arguments]")
    print ("       xcsao help  for IRAF help")
    print ("       xcsao dpar  to dump parameters")
    print ("       xcsao epar  to edit parameters")
    print ("       xcsao lpar  to list parameters")
    }
else if (args == "help") {
    tempcom = mktemp ("tempxcsao")
    print ("help xcsao", > tempcom)
    cl (< tempcom)
    delete (tempcom)
    }

# Edit xcsao parameters using epar
else if (args == "epar") {
    tempcom = mktemp ("tempxcsao")
    print ("rvsao motd-\nepar xcsao", > tempcom)
    cl (< tempcom)
    delete (tempcom)
    }

# Dump xcsao parameters using dpar
else if (args == "dpar") {
    tempcom = mktemp ("tempxcsao")
    print ("rvsao motd-\ndpar xcsao", > tempcom)
    cl (< tempcom)
    delete (tempcom)
    }

# List xcsao parameters using lpar
else if (args == "lpar") {
    tempcom = mktemp ("tempxcsao")
    print ("rvsao motd-\nlpar xcsao", > tempcom)
    cl (< tempcom)
    delete (tempcom)
    }

# Execute xcsao using the arguments on the command line
else {
    tempcom = mktemp ("tempxcsao")
    printf ("rvsao motd-\nxcsao %s\n", args, > tempcom)
    cl (< tempcom)
    delete (tempcom)
    }
logout

