#! /usr/bin/perl

$Q_POS = $ARGV[0];
$QUERY = $ARGV[1];

open(F, "wing_showrocs|") || die "Can not execute wing_showrocs.";
while( <F> ) {
    chop;
    if( /L(\d)C(\d)_(\d\d\d)\s+(dcs\d\d\d\d)\s+(\d+)\s+(\d)\s+(\d)/ ) {
	($L, $C, $S, $DCS, $SM, $STACK, $LAYER) = ( $1, $2, $3, $4, $5, $6, $7 );
	$CHAMBER = "L".$L."C".$C."_".$S;
	# printf("$CHAMBER, $DCS, $SM, $STACK, $LAYER\n");
	$POS = $SM."_".$STACK."_".$LAYER;
	if( $Q_POS eq $POS ) { 
	    if( $QUERY eq "dcs"       ) { printf("$DCS\n"); }
	    if( $QUERY eq "rocname"   ) { printf("$CHAMBER\n"); }
	    if( $QUERY eq "sm"        ) { printf("$SM\n"); }
	    if( $QUERY eq "layer"     ) { printf("$LAYER\n"); }
	    if( $QUERY eq "stack"     ) { printf("$STACK\n"); }
	    if( $QUERY eq "ctype"     ) { printf("$C\n"); }
	    if( $QUERY eq "rocserial" ) { printf("$S\n"); }
	    exit(0);
	}
    }
}
exit(1);

