setup_parfile (version 2.1)

You can also look at:
#! /usr/bin/perl

##############################################################################
#
# SYNTAX: setup_parfile parfile_path param=value param=value...
#
# DESCRIPTION: This utility copies a parfile into the working directory,
# DESCRIPTION: resets all parameters from asking mode to hidden mode,
# DESCRIPTION: and sets parameter values as specified.
#
# VERSION: 2.1
#
# HISTORY: 0.0 -> 1.0 10/9/96
# HISTORY: Also change ,q, and ,ql, modes to ,h,
# HISTORY: 1.0 -> 1.1 5/20/97
# HISTORY: Added some sed commands to remove leading and trailing spaces in
# HISTORY: parfile fields. This is necessary for the ghkcurve parfile,
# HISTORY: which has a number of spaces in it for readability.
# HISTORY: 
# HISTORY: 1.1 -> 2.0 1999-05-07
# HISTORY: Converted from ksh to perl
# HISTORY: 
# HISTORY: 2.0 -> 2.1 2000-02-25
# HISTORY: added a cludge to account for the new parfile location in 
# HISTORY: FTOOLS 5.0 and later
#
# CALLS: $UTIL/exit_test
# CALLS: $UTIL/set_parameter
#
##############################################################################
#$DEBUG = 1;

$input_par_path = $ARGV[0];
$output_parfile = $input_par_path;
$output_parfile =~ s/^.*\///;

$UTIL = $ENV{"UTIL"};

###########################################################################
# in FTOOLS 5.0 the parfiles moved from the bin directory to the
# syspfiles directory. So instead of changing every call to setup_parfile
# to give this new path we will try to cludge this here
###########################################################################
if($input_par_path =~ /ftools/ ) {
    $input_par_path =~ s|/bin/|/syspfiles/|;
}

###################
# Debugging output
###################
if ( $DEBUG ) {
    print "setup_parfile: ARGV=@ARGV\n";
    print "setup_parfile: input_par_path=$input_par_path\n";
    print "setup_parfile: output_parfile=$output_parfile\n";
}


###################################################################
# Copy over the par file and reset from asking mode to hidden mode
###################################################################
unlink $output_parfile;
open(INPUT_PAR_PATH, "<$input_par_path") or `$UTIL/exit_test $! $0 1 "Opening $input_par_path for input"`;
open(OUTPUT_PARFILE, ">>$output_parfile") or `$UTIL/exit_test $! $0 1 "Opening $output_parfile for output"`;

while ( <INPUT_PAR_PATH> ) {
    s/, */,/g;
    s/ *,/,/g;
    s/,a,/,h,/;
    s/,q,/,h,/;
    s/,ql,/,h,/;
    print OUTPUT_PARFILE;
}
close OUTPUT_PARFILE;

############################################
# Loop through arguments and set parameters
############################################
shift;
while ( $nextarg = shift ) {
    ($param, $value) = ($nextarg =~ /^(\w*)=(.*)$/);

    ###################
    # Debugging output
    ###################
    if ( $DEBUG ) {
        print "setup_parfile: nextarg=$nextarg\n";
        print "setup_parfile: param=$param\n";
        print "setup_parfile: value=$value\n";
    }

    `$UTIL/set_parameter ./${output_parfile} $param "$value"`;
}


exit 0