# Define correct temp. dir. depending on env. vars.

set TMP = $GENESIS_TMP

set exitstatus = 0

set PKAOI = "$cwd/aoiProfile.pl"


if ($?JOB == 0) then

   echo "--> Error! You have to open any job. Cannot continue."

   exit

endif


DO_INFO -t job -e $JOB -d FORMS_LIST

if ($gFORMS_LIST == "") then

   echo "--> Error! The job $JOB does not have any priform. Cannot continue."

   exit

endif


set myForm = $gFORMS_LIST[1]

if ($myForm == "priform3") then

   set CAMTEK_OUT = "v:/sys/scripts3/camtek_output3"

   # CAMTEK_CREATE does not exists in the priform3

   # set CAMTEK_CREATE = "v:/sys/scripts3/camtek_create"    

else if ($myForm == "priform4") then

   set CAMTEK_OUT = "v:/sys/scripts4/camtek_output4"

   set CAMTEK_CREATE = "v:/sys/scripts4/camtek_create4"

else if ($myForm == "priform5") then

   set CAMTEK_OUT = "v:/sys/scripts5/camtek_output"

   set CAMTEK_CREATE = "v:/sys/scripts5/camtek_create"

endif


set hostname = "192.168.100.212"


# Set the INFO alias and the tmp INFO file.

set INFO = $TMP/info

alias DO_INFO 'COM info,out_file=$INFO,write_mode=replace,args=\!:*;source $INFO; rm $INFO'


# Set up gui data and response files.

set GUI_DATA = $TMP/gui_data.$$

set GUI_RESP = $TMP/gui_resp.$$


# Check to see if $GENESIS_EDIR is local path or absolute. Set "EDIR_PATH" accordingly).

if ($GENESIS_EDIR =~ /* || $GENESIS_EDIR =~ ?:*) then

   set EDIR_PATH = ($GENESIS_EDIR)

else

   set EDIR_PATH = ($GENESIS_DIR/$GENESIS_EDIR)

endif


# Get full path of job, and set control file path.

COM read_form, job=$JOB, form=$myForm, elem=job_path

set JOB_PATH = `echo "$COMANS"`

if (! -e $JOB_PATH) then

   set JOB_PATH = `$EDIR_PATH/misc/dbutil path jobs $JOB`

endif


# Source form info. file.

source $JOB_PATH/forms/$myForm/def/form_info.source

source $JOB_PATH/user/info.source


# Set date for log file entries.

set DATE = `date '+%H:%M - %d %b. %y'`


# Find out the user name.

COM get_user_name

set USER = `echo "$COMANS"`


if ($PAN == 0) then

   PAUSE Panel-step er ikke lavet

   set exitstatus = 1

   goto abort

else

   set STEP = "panel"

endif


if ($?JOB) then

   set JOBNAME = $JOB

endif


# here we call the Perl script

perl.exe $PKAOI -prepareProfile $JOBNAME

set result_file = "$GENESIS_TMP/result_csh.txt"

set myResult = (`cat $result_file`)

if ( $myResult < 0 ) then

   echo "Error!"

   exit

endif


# returns AOI set: cmtk

DO_INFO_MM -t layer -e $JOB/panel/top -d AOISETS_LIST


# Update last saved time in forms.

source $JOB_PATH/forms/$myForm/def/save_time


# here we call the Perl script

perl.exe $PKAOI -readOrgProfile $JOBNAME

set result_file = "$GENESIS_TMP/result_csh.txt"

set myResult = (`cat $result_file`)

if ( $myResult < 0 ) then

   PAUSE "--> Error!"

   exit

endif


exit