#! /usr/bin/perl

open(F, "wing_showrocs|") || die "Can not execute wing_showrocs.";

while( <F> ) {
    chop;
    if( /(L\dC\d_\d\d\d)\s+(dcs\d\d\d\d)\s+(\d+)\s+(\d)\s+(\d)/ ) {
	($CHAMBER, $DCS, $SM, $STACK, $LAYER) = ( $1, $2, $3, $4, $5 );
    }
    @POS_LIST_1 = ( @POS_LIST_1, $SM."_".$STACK."_".$LAYER );
    @POS_LIST_2 = ( @POS_LIST_2, "\"".$SM."_".$STACK."_".$LAYER."\"" );
}
close F;

open(F, ">_setup.sh" ) || die "Can not open _setup.sh as write mode.";
open(G, ">_setup.pl" ) || die "Can not open _setup.pl as write mode.";

# sort by layer/stack







printf(F "# source me\n");
printf(F "POS_LIST=\"%s\"\n", join( " ", sort( @POS_LIST_1 ) ) );

printf(G "# require me\n");
printf(G "\@POS_LIST=( %s );\n", join( ", ", sort( @POS_LIST_2 ) ) );

close F;
close G;

printf("%d chambers are found.\n", $#POS_LIST_1 + 1 );
