#-------------------------------------------
#
# Name: UPDATE  (Loads the update file containing changes from the default CDHS settings.
#
# Syntax:
#       run UPDATE -debug -upd:upddir
#
# Description:
#       The -debug option may be used to provide diagnostic output.
#       The -upd option may be used to specify directory for files.
#       Loops through each line of the update file and interprets as
#       either scripts or commands. These are then sent directly to the SC.
#
#       The format of the update.dt file allows both scripts and commands to 
#       be sent without knowing without the IDL program writing the file
#       needing to know which they are. Each command is contained within a single
#       line so it can be interpreted on a line by line basis. 
#
#       NOTE!!!
#       =======
#       Commands must not span more than one line.
#       In the update file commands are written in the forms
#
#               COMMAND 1 2 3 4 ...    
#
#               SCRIPT cb2hval.dt    
#
#               SCRIPT 1 2 3 4 5 .... (21 params) 
#
#      and processed line-by-line into mlb's.
#
# Calls : getpar.
#
# Modification History:
#
#   0.0	26/5/94   : Martin Carter : Adapted from DFLOAD
#   0.1 22/11/95  : MKC : Removed use of getarg and modified loadmlb.
#
# Version : 0.1
#
#-------------------------------------------------------------

# libraries

require "param.pl";
require "cpt/cplib.pl";

# global variable : $debugging, $mnemonic

# local variables

local ( $name )    = "UPDATE";                # routine name
local ( $updfile ) = "update.dt";             # input file name
local ( $upddir )  = "";                      # directory for update files
local ( $maxmlbwords ) = 29;    # Maximum no. of command words in mlb

local ( @inputs ) ;              # parameter inputs
local ( @temp );                 # temporary array for processing 
local ( $comm ) ;                # command/script name for current line
 
# check for options

$debugging = 0;

foreach $arg ( @ARGV ) {

  if ( $arg eq "-debug" ) { 
       $debugging = 1; 
  }  elsif ( $arg =~ s/^-upd:// ) { 
       $upddir = $arg;
       print "UPD directory = $upddir \n";
  } else { 
       push ( @inputs, $arg) ; 
  }
    
}

# check for correct arguments

if ( $#inputs ge 0) { die("Error $name : No arguments accepted");}

# process file

# specify directory for embedded script files 

if ( $upddir eq "" ) { $mnemonic = $name; } else { $mnemonic = $upddir;}

# Specify file for update file

$updfile  = &ModifyFilename ( $updfile );

# Open the input data file

if (!open(INPUTFILE, '<'.$updfile)) {
  die ( "Error $name : Couldn't open file '$updfile'");
}

# Loop through lines in the file

while (<INPUTFILE>) {

   # split line into list of items

   @temp = &getarg() ;

   # check if blank line or comment

   next if ($#temp==-1);

   print "Argument list is $#temp : @temp \n";

}






