#! /usr/bin/perl
#
# Usage: robpos2robsn.pl ROC_SN Position

$FIND_ROC_SN   = $ARGV[0];
$FIND_POSITION = $ARGV[1];

# printf("$FIND_ROC_SN $FIND_POSITION\n" );

$ROB_POS_DB = "db/rob_pos.tbl";

open( F_ROB_POS, $ROB_POS_DB ) or die "Can not open Data Base File.\n";

$FOUND = -1;

while( <F_ROB_POS> ) {
    if( /^\s*(\S+)\s+(\d+)\s+(\d+)/ ) {
	$ROC_SN = $1;
	$POS    = $2;
	$ROB_SN = $3;
	# printf("ROC_SN = %s, POS = %d, ROB_SN = %d\n", $ROC_SN, $POS, $ROB_SN );

	if( $ROC_SN eq $FIND_ROC_SN && $POS == $FIND_POSITION ) {
	    $FOUND = $ROB_SN;
	}
    }
}

printf("$FOUND\n");

# EOF
