#!/bin/csh -f

# General script to start PIA - Version >= 8.0
# Orig: Carlos GABRIEL (ESA/VILSPA-SAI)
#
# This command file contains the environment variables needed to
# start the PHT-IA under UNIX, looks for a user environment variables
# file to overwrite some of the default values and finally starts IDL
# with the PIA startup procedure.
#
# There is NOTHING to be changed by the installation:
# The main PIA tree finds itself


if(`ls -F $0|egrep @|wc -l` == 1 ) then
  set install_dir=`ls -l $0 | awk '{print $NF}'| awk -F\/ '{for(i=1;i<NF;i++) printf("%s/", $i)}'`
  set install_dir = `cd $install_dir;echo $PWD`
else if(`ls -l $0|grep /|wc -l` == 1 ) then
  set install_dir=`echo $0 | awk -F\/ '{for(i=1;i<NF;i++) printf("%s/", $i)}'`
  set install_dir = `cd $install_dir;echo $PWD`
else
  set pia = `which $0`
  set install_dir=`echo $pia | awk -F\/ '{for(i=1;i<NF;i++) printf("%s/", $i)}'`
endif

setenv PIA_LOC_GEN $install_dir

set PIA_DATAP = $PWD/

# Source the general environment variables
source $PIA_LOC_GEN/envi.pia

# Source the user's environment variables: look first in start directory,
# then in the user's pia directory

if (-f pia_envi) then
 source pia_envi
else
 if ! $?PIA_LOC_IND  set PIA_LOC_IND = '~/pia'

 if (-f $PIA_LOC_IND/pia_envi) then
  source $PIA_LOC_IND/pia_envi
 endif
endif

# Add these lines for being able to run different IDL versions via the IDL_DIR
# environment variable
if $?IDL_DIR then
 alias idl $IDL_DIR/bin/idl
endif

cd $PIA_LOC_GEN
 idl pia_start.scr
cd $PIA_DATAP
