#
# sub routine often used
#

sub read_setup
{
    my( $TARGET_DIR ) = @_;

    printf("read_setup.pl: $TARGET_DIR\n");

    if( defined( $TARGET_DIR )) {
	$setup_file = "$TARGET_DIR/_setup";
    } else {
	$setup_file = "_current/_setup";
    }

    printf("Reading setup file from $setup_file\n");

    my( $DIR_NAME, $DATE, $ROC_SERIAL, $ROC_LAYER, $ROC_TYPE, $DCS_SERIAL, $WITH_PIPES, $INITIAL, $TRD_FEE );
    my( @lines ) = `cat $setup_file`;
    foreach( @lines ) {
	chop;
	if ( /DIR_NAME=(\S+)$/   ) { $DIR_NAME   = $1; }
	if ( /DATE=(\S+)$/       ) { $DATE       = $1; }
	if ( /ROC_SERIAL=(\S+)$/ ) { $ROC_SERIAL = $1; }
	if ( /ROC_LAYER=(\S+)$/  ) { $ROC_LAYER  = $1; }
	if ( /ROC_TYPE=(\S+)$/   ) { $ROC_TYPE   = $1; }
	if ( /DCS_SERIAL=(\S+)$/ ) { $DCS_SERIAL = $1; }
	if ( /WITH_PIPES=(\S+)$/ ) { $WITH_PIPES = $1; }
	if ( /INITIAL=(\S+)$/    ) { $INITIAL    = $1; }
    }
    my ( @lines ) = `cat _trd_fee`;
    foreach( @lines ) {
	chop;
	if ( /TRD_FEE=(\S+)$/   ) { $TRD_FEE   = $1; }
    }
    return ( $DIR_NAME, $DATE, $ROC_SERIAL, $ROC_LAYER, $ROC_TYPE, $DCS_SERIAL, $WITH_PIPES, $INITIAL, $TRD_FEE );
}

1;
