[ return ]

parse.pl



############################################################
#
#  file: parse.pl
#
#
#  Data file parser.
#

sub scan_to_next
{
    while(($_ = ) && ($_ =~ /^\s*\#/ || $_ =~ /^\s*\n/))
    {};
    return $_;
};

#
#  sub parse_gspec
#
#  Parse the grasp spec file.
#
#

sub parse_gspec
{
    local($fname) = @_;
    local($i, $name);
				# Open the input file
    open(FP, "<$fname") || die "parse_gspec(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^gspec\b/ || die "parse_gspec(): Incorrect header (line $.):\n$_";


    $i = 0;			# Grasp counter

    while($_)			# Loop for each grasp.
    {
				# Grasp name
	&scan_to_next || last;
	/\s*name\s+([^\s\#]+)/
	    || die "parse_gspec(): parse error (line $.), name:\n$_\n";
	$name = $grasp{"name", $i} = $1;
	$grasp{"index", $1} = $i;

				# Grasp type
	&scan_to_next() || last;
	/\s*type\s+([^\s\#]+)/
	    || die "parse_gspec(): parse error (line $.), type, $name:\n$_";
	$grasp{"type", $i} = $1;

	&member($1, @GRASP_TYPES)
	    || die "parse_gspec(): illegal grasp type (line $.):\n$_";
	    
				# Grasp aperture
	&scan_to_next() || last;
	/\s*aperture\s+([\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), aperture, $name, $_\n";
	$grasp{"aperture", $i} = $1;

				# Map from type and aperture to grasp ID
				#  but first check for uniqueness.

	if(defined $grasp{"index", $grasp{"type", $i}, $grasp{"aperture", $i}})
	{
				# In general uniqueness won't hold, but
				#  we have to force it right now.

	    die "parse_gspec(): Error - non-unique type and aperture found (line $.), $_\n";
	};

	$grasp{"index", $grasp{"type", $i}, $grasp{"aperture", $i}} = $i;

				# Thumb position spec
	&scan_to_next() || last;
	/\s*thumb\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), thumb pos, $name, $_\n";
	$grasp{"final pos", $i, "t0"} = $1;
	$grasp{"final pos", $i, "t1"} = $2;
	$grasp{"final pos", $i, "t2"} = $3;

				# Index position spec
	&scan_to_next() || last;
	/\s*index\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), index pos, $name, $_\n";
	$grasp{"final pos", $i, "i0"} = $1;
	$grasp{"final pos", $i, "i1"} = $2;
	$grasp{"final pos", $i, "i2"} = $3;

				# Middle position spec
	&scan_to_next() || last;
	/\s*middle\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), middle pos, $name, $_\n";
	$grasp{"final pos", $i, "m0"} = $1;
	$grasp{"final pos", $i, "m1"} = $2;
	$grasp{"final pos", $i, "m2"} = $3;

				# Ring position spec
	&scan_to_next() || last;
	/\s*ring\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), ring pos, $name, $_\n";
	$grasp{"final pos", $i, "r0"} = $1;
	$grasp{"final pos", $i, "r1"} = $2;
	$grasp{"final pos", $i, "r2"} = $3;

				# Little position spec
	&scan_to_next() || last;
	/\s*little\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), little pos, $name, $_\n";
	$grasp{"final pos", $i, "l0"} = $1;
	$grasp{"final pos", $i, "l1"} = $2;
	$grasp{"final pos", $i, "l2"} = $3;



				# Thumb preshape spec
	&scan_to_next() || last;
	/\s*thumb\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), thumb preshape pos, $name, $_\n";
	$grasp{"preshape pos", $i, "t0"} = $1;
	$grasp{"preshape pos", $i, "t1"} = $2;
	$grasp{"preshape pos", $i, "t2"} = $3;

				# Index preshape spec
	&scan_to_next() || last;
	/\s*index\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), index preshape pos, $name, $_\n";
	$grasp{"preshape pos", $i, "i0"} = $1;
	$grasp{"preshape pos", $i, "i1"} = $2;
	$grasp{"preshape pos", $i, "i2"} = $3;

				# Middle preshape spec
	&scan_to_next() || last;
	/\s*middle\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), middle preshape pos, $name, $_\n";
	$grasp{"preshape pos", $i, "m0"} = $1;
	$grasp{"preshape pos", $i, "m1"} = $2;
	$grasp{"preshape pos", $i, "m2"} = $3;

				# Ring preshape spec
	&scan_to_next() || last;
	/\s*ring\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), ring preshape pos, $name, $_\n";
	$grasp{"preshape pos", $i, "r0"} = $1;
	$grasp{"preshape pos", $i, "r1"} = $2;
	$grasp{"preshape pos", $i, "r2"} = $3;

				# Little preshape spec
	&scan_to_next() || last;
	/\s*little\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), little preshape pos, $name, $_\n";
	$grasp{"preshape pos", $i, "l0"} = $1;
	$grasp{"preshape pos", $i, "l1"} = $2;
	$grasp{"preshape pos", $i, "l2"} = $3;



				# Jacobian
				# Thumb preshape spec
	&scan_to_next() || last;
	/\s*thumb\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), thumb preshape pos, $name, $_\n";
	$grasp{"jacobian", $i, "t0"} = $1;
	$grasp{"jacobian", $i, "t1"} = $2;
	$grasp{"jacobian", $i, "t2"} = $3;
				# Index preshape spec
	&scan_to_next() || last;
	/\s*index\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), index jacobian, $name, $_\n";
	$grasp{"jacobian", $i, "i0"} = $1;
	$grasp{"jacobian", $i, "i1"} = $2;
	$grasp{"jacobian", $i, "i2"} = $3;

				# Middle preshape spec
	&scan_to_next() || last;
	/\s*middle\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), middle jacobian, $name, $_\n";
	$grasp{"jacobian", $i, "m0"} = $1;
	$grasp{"jacobian", $i, "m1"} = $2;
	$grasp{"jacobian", $i, "m2"} = $3;

				# Ring preshape spec
	&scan_to_next() || last;
	/\s*ring\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), ring jacobian, $name, $_\n";
	$grasp{"jacobian", $i, "r0"} = $1;
	$grasp{"jacobian", $i, "r1"} = $2;
	$grasp{"jacobian", $i, "r2"} = $3;

				# Little preshape spec
	&scan_to_next() || last;
	/\s*little\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), little jacobian, $name, $_\n";
	$grasp{"jacobian", $i, "l0"} = $1;
	$grasp{"jacobian", $i, "l1"} = $2;
	$grasp{"jacobian", $i, "l2"} = $3;



				# Thumb tactile spec
	&scan_to_next() || last;
	/\s*thumb\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), thumb tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "t0"} = $1;

				# Side index tactile spec
	&scan_to_next() || last;
	/\s*sindex\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), sindex tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "s0"} = $1;

				# Index preshape spec
	&scan_to_next() || last;
	/\s*index\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), index tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "i0"} = $1;
	$grasp{"tactile mask", $i, "i1"} = $2;
	$grasp{"tactile mask", $i, "i2"} = $3;

				# Middle preshape spec
	&scan_to_next() || last;
	/\s*middle\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), middle tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "m0"} = $1;
	$grasp{"tactile mask", $i, "m1"} = $2;
	$grasp{"tactile mask", $i, "m2"} = $3;

				# Ring preshape spec
	&scan_to_next() || last;
	/\s*ring\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), ring tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "r0"} = $1;
	$grasp{"tactile mask", $i, "r1"} = $2;
	$grasp{"tactile mask", $i, "r2"} = $3;

				# Little preshape spec
	&scan_to_next() || last;
	/\s*little\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)/
	    || die "parse_gspec(): parse error (line $.), little tactile spec, $name, $_\n";
	$grasp{"tactile mask", $i, "l0"} = $1;
	$grasp{"tactile mask", $i, "l1"} = $2;
	$grasp{"tactile mask", $i, "l2"} = $3;

				# Get object center
	&scan_to_next() || last;
	/\s*center\s+(\w+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+(-?[\d\.]+)\s+/ || die "parse_gspec(): parse error (line $.), object center, $name, $_\n";
	$grasp{"object center", $i, "constraint"} = $1;
	$grasp{"object center", $i, "r11"} = $2;
	$grasp{"object center", $i, "r21"} = $3;
	$grasp{"object center", $i, "r31"} = $4;
	$grasp{"object center", $i, "r12"} = $5;
	$grasp{"object center", $i, "r22"} = $6;
	$grasp{"object center", $i, "r32"} = $7;
	$grasp{"object center", $i, "r13"} = $8;
	$grasp{"object center", $i, "r23"} = $9;
	$grasp{"object center", $i, "r33"} = $10;
	$grasp{"object center", $i, "r14"} = $11;
	$grasp{"object center", $i, "r24"} = $12;
	$grasp{"object center", $i, "r34"} = $13;

	++$i;
	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "Grasp: $name\n";
	};
    };

    print "$i grasps found.\n";

    $grasp{"num"} = $i;
    close FP;
};


#
#  sub parse_ospec
#
#  Parse the object spec file.
#
#

sub parse_ospec
{
    local($fname) = @_;
    local($i, $name);
				# Open the input file
    open(FP, "<$fname") || die "parse_ospec(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^ospec\b/ || die "parse_ospec(): Incorrect header (line $.):\n$_";


    $i = 0;			# Object counter

    while($_)			# Loop for each object
    {
	&scan_to_next || last;
	/^\s*object/
	    || die "parse_ospec(): parse object header (line $.):\n$_\n";

				# Object name
	&scan_to_next || last;
	/^\s*name\s+([^\s\#]+)/
	    || die "parse_ospec(): parse error (line $.), name:\n$_\n";
	$name = $object{"name", $i} = $1;
	$object{"index", $1} = $i;

	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "Object: $name\n";
	};

				# Object shape
	&scan_to_next() || last;
	/^\s*shape\s+([^\s\#]+)/
	    || die "parse_ospec(): parse error (line $.), shape, $name:\n$_";
	$object{"shape", $i} = $1;

				# Check shape
	&member($1, @SHAPES)
	    || die "parse_ospec(): illegal shape (line $.):\n$_";


				# Object parameters 

	&scan_to_next() || last; # Get the next line

	while($_)
	{
				# Parameter format?
	    /^\s*([^\s\#]+)\s+([^\s\#]+)/
		|| last;	# no - no more parms

	    $object{"parameter", $i, $1} = $2;
	    if($parms{"d"} & $DETAILED_PARSE)
	    {
		print "PARM: $1,$2\n";
	    };
	    $_ = ;		# Parameters must not be separated
				#  by null lines.
	};


	++$i;
    };

    print "$i objects found.\n";

    $object{"num"} = $i;
    close FP;
};


#
#  sub parse_ogmap
#
#  Parse the object/map file
#
#

sub parse_ogmap
{
    local($fname) = @_;
    local($i, $name, $object, $mask);
				# Open the input file
    open(FP, "<$fname") || die "parse_ogmap(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^ogmap\b/ || die "parse_ogmap(): Incorrect header (line $.):\n$_";


    $i = 0;			# Object counter

    while($_)			# Loop for each object
    {
	&scan_to_next || last;
	/^\s*object/
	    || die "parse_ogmap(): parse object header (line $.):\n$_\n";

				# Object name
	&scan_to_next || last;
	/^\s*([^\s\#]+)/
	    || die "parse_ogmap(): parse error (line $.), name:\n$_\n";
	$name = $1;

				# Check object name
	defined($object{"index", $name})
	    || die "parse_ogmap(): undefined object name (line $.):\n$_";

	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "Object in Map: $name\n";
	};

				# List of grasps

	&scan_to_next() || last; # Get the next line

	while($_)
	{
				# Parameter format?
	    /^\s*([^\s\#]+)\s+([\d ]*\d)/
		|| last;	# no - no more grasps

	    $grasp = $1;
	    $mask = $2;

				# Check grasp type
	    defined($grasp{"index", $grasp})
		|| die "parse_ogmap(): undefined grasp (line $.):\n$_";

	    $ogmap{"grasps", $name} .= $grasp . ":";
	    $ogmap{"objects", $grasp} .= $name . ":";

				# List of objects separated by grasp type.
	    $ogmap{"sepobjects",
		   $grasp{"type", $grasp{"index", $grasp}}} .= $name . ":";

				# Parameters
	    $ogmap{"parms", $object, $grasp} .= $mask . ":";

	    if($parms{"d"} & $DETAILED_PARSE)
	    {
		print "OGMAP: $name,$grasp,$mask\n";
	    };
	    $_ = ;		# Mask must not be separated
				#  by null lines.
	};


	++$i;
    };

    print "$i object maps found.\n";

    $ogmap{"num"} = $i;
    close FP;
};

#
#  sub parse_f5spec
#
#  Parse the object/map file
#
#

sub parse_f5spec
{
    local($fname) = @_;
    local($i, $j, $grasp, $object, $mask);
				# Open the input file
    open(FP, "<$fname") || die "parse_f5spec(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^f5spec\b/ || die "parse_f5spec(): Incorrect header (line $.):\n$_";


    $i = 0;			# Object counter

    while($_)			# Loop for each object
    {
	&scan_to_next || last;
	/^\s*cell/
	    || die "parse_f5spec(): parse error, object header (line $.):\n$_\n";
	$j = 0;

	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "CELL $i\n";
	};

	&scan_to_next || last;	# Get next line.

	while($_)
	{
				# Grasp type  and response level
	    /^\s*([^\s\#]+)\s+([\d.]+)/	|| last;
	    $f5{"grasp", $i, $j} = $grasp = $1;
	    $f5{"grasp response", $i, $j} = $2;

				# Check grasp type
	    &member($grasp, @GRASP_TYPES)
		|| die "parse_f5spec(): illegal grasp type (line $.):\n$_";


	    if($parms{"d"} & $DETAILED_PARSE)
	    {
		print "GRASP: $grasp\n";
	    };
	    $_ =  || die "parse_f5spec(): end of file after grasp response:\n$_\n";

				# Grasp aperture
	    /^\s*aperture\s+(-?[\d.]+)/
		|| die "parse_f5spec(): parse error (line $.), grasp aperture:\n$_\n";
	    $f5{"grasp aperture", $i, $j} = $1;
	    $_ =  || die "parse_f5spec(): end of file after grasp aperture:\n$_\n";

				# Phase response
	    /^\s*phase\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/
		|| die "parse_f5spec(): parse error (line $.), grasp phase:\n$_\n";
				# Total phase response
	    $f5{"total phase response", $i, $j} = $1 + $2 + $3 + $4 + $5;

				# 2 things - sets the phase response value
				#  for each phase, and sets phase first
				#  to the first phase which is non-zero.
	    (($f5{"phase response", $i, $j, "release"} = $5) != 0) &&
		($f5{"phase first", $i, $j} = "release");
	    (($f5{"phase response", $i, $j, "hold"} = $4) != 0) &&
		($f5{"phase first", $i, $j} = "hold");
	    (($f5{"phase response", $i, $j, "flexion"} = $3) != 0) &&
		($f5{"phase first", $i, $j} = "flexion");
	    (($f5{"phase response", $i, $j, "extension"} = $2) != 0) &&
		($f5{"phase first", $i, $j} = "extension");
	    (($f5{"phase response", $i, $j, "set"} = $1) != 0) &&
		($f5{"phase first", $i, $j} = "set");

				# Compute last phase...

	    ($f5{"phase response", $i, $j, "set"} != 0) &&
		($f5{"phase last", $i, $j} = "set");
	    ($f5{"phase response", $i, $j, "extension"} != 0) &&
		($f5{"phase last", $i, $j} = "extension");
	    ($f5{"phase response", $i, $j, "flexion"} != 0) &&
		($f5{"phase last", $i, $j} = "flexion");
	    ($f5{"phase response", $i, $j, "hold"} != 0) &&
		($f5{"phase last", $i, $j} = "hold");
	    ($f5{"phase response", $i, $j, "release"} != 0) &&
		($f5{"phase last", $i, $j} = "release");

	    $j++;
	    $_ =  || last;
	};
	$f5{"num", $i} = $j;

	++$i;
    };

    print "$i F5 units found.\n";

    $f5{"num"} = $i;
    $net{"num", "F5"} = $i;
    close FP;
};




#
#  sub parse_aipspec
#
#  Parse the AIP spec file
#
#

sub parse_aipspec
{
    local($fname) = @_;
    local($i, $grasp, $object, $mask);
				# Open the input file
    open(FP, "<$fname") || die "parse_aipspec(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^aipspec\b/ || die "parse_aipspec(): Incorrect header (line $.):\n$_";


    $i = 0;			# Object counter

    while($_)			# Loop for each object
    {
	&scan_to_next || last;
	/^\s*grasp\s+([^\s\#]+)/
	    || die "parse_aipspec(): parse error, grasp  (line $.):\n$_\n";
	$aip{"grasp type", $i} = $grasp = $1;

				# Check grasp type
	&member($grasp, @GRASP_TYPES)
	    || die "parse_aipspec(): illegal grasp type (line $.):\n$_";


	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "GRASP $i: $grasp\n";
	};

	&scan_to_next || last;	# Get next line.
				# Phase
	/^\s*phase\s+([^\s\#]+)/	
	    || die "parse_aipspec(): parse error, phase  (line $.):\n$_\n";
	$aip{"phase", $i} = $1;

				# Check phase spec
	&member($1, @AIP_PHASES)
	    || die "parse_aipspec(): illegal phase spec (line $.):\n$_";

	&scan_to_next || last;	# Get next line.
				# Aperture
	/^\s*aperture\s+([^\s\#]+)/	
	    || die "parse_aipspec(): parse error, aperture (line $.):\n$_\n";
	$aip{"aperture", $i} = $1;

	&scan_to_next || last;	# Get next line.
				# Visual
	/^\s*visual\s+([^\s\#]+)/	
	    || die "parse_aipspec(): parse error, visual (line $.):\n$_\n";
	$aip{"visual", $i} = $1;

	&scan_to_next || last;	# Get next line.
				# Motor
	/^\s*motor\s+([^\s\#]+)/	
	    || die "parse_aipspec(): parse error, motor (line $.):\n$_\n";
	$aip{"motor", $i} = $1;

	++$i;
    };

    print "$i AIP units found.\n";

    $aip{"num"} = $i;
    $net{"num", "AIP"} = $i;
    close FP;
};


#
#  sub parse_mcxspec
#
#  Parse the object/map file
#
#

sub parse_mcxspec
{
    local($fname) = @_;
    local($i, $j, $grasp, $object, $mask);
				# Open the input file
    open(FP, "<$fname") || die "parse_mcxspec(): Can't open input file.  $!\n";

				# Check the header.
    $_ = ;
    /^mcxspec\b/ || die "parse_mcxspec(): Incorrect header (line $.):\n$_";


    $i = 0;			# Object counter

    while($_)			# Loop for each object
    {
				# Get header and cell type
	&scan_to_next || last;
	/^\s*cell\s+\b(\w+)\b/
	    || die "parse_mcxspec(): parse error, object header (line $.):\n$_\n";
	$j = 0;

	$mcx{"type", $i} = $1;

	if($parms{"d"} & $GENERAL_PARSE)
	{
	    print "CELL $i $1\n";
	};
				# Check to make sure that the cell type
				#  is legal.
	&member($1, @MCX_TYPES)
	    || die "parse_mcxspec(): illegal mcx cell type (line $.):\n$_";

	&scan_to_next || last;	# Get next line.

	while($_)
	{
				# Joint, prefered direction, and support level
	    /^\s*([^\s\#]+)\s+(-?[\d.]+)\s+([\d.]+)/  || last;
	    $mcx{"joint", $i, $j} = $1;
	    $mcx{"position", $i, $j} = $2;
	    $mcx{"activity", $i, $j} = $3;
	    $mcx{"index", $i, $1} = $j;
	    $mcx{"index", $1} .= $i . ":";
	    $mcx{"grasp response", $i, $j} = $2;

				# Check joint
	    &member($1, @JOINTS)
		|| die "parse_mcxspec(): illegal joint (line $.):\n$_";


	    if($parms{"d"} & $DETAILED_PARSE)
	    {
		print "MCX: $1,$2,$3\n";
	    };
	    $j++;
	    $_ =  || last;
	};
	$mcx{"num", $i} = $j;

	++$i;
    };

    print "$i MCX units found.\n";

    $mcx{"num"} = $i;
    $net{"num", "Mcx"} = $i;
    close FP;
};


#
#  sub parse_input_files
#
#  Parse all input files
#
#

sub parse_input_files
{
    local($base) = @_;

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing gspec file....\n";
    };
    &parse_gspec($base . ".gspec"); # Grasps

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing ospec file....\n";
    };
    &parse_ospec($base . ".ospec"); # Objects

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing ogmap file....\n";
    };
    &parse_ogmap($base . ".ogmap"); # Object/Grasp Map

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing f5spec file....\n";
    };
    &parse_f5spec($base . ".f5spec"); # F5 unit spec

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing AIPspec file....\n";
    };
    &parse_aipspec($base . ".aipspec"); # AIP unit spec

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing MCXspec file....\n";
    };
    &parse_mcxspec($base . ".mcxspec"); # MCX unit spec
};


#
#  sub parse_mcx_input_files
#
#  Parse input files for determining connections to/from mcx.
#
#

sub parse_mcx_input_files
{
    local($base) = @_;


    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing gspec file....\n";
    };
    &parse_gspec($base . ".gspec"); # Grasp specification

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing f5spec file....\n";
    };
    &parse_f5spec($base . ".f5spec"); # F5 unit spec

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing MCXspec file....\n";
    };
    &parse_mcxspec($base . ".mcxspec"); # MCX unit spec
};



#
#  sub parse_f5_mcx_w
#
#  Imports the foo.f5.mcx.w file that is generated by genmcx.
#  It is assumed that all of the datastructures have been
# initialized.
#

sub parse_f5_mcx_w
{
    local($base) = @_;
    local($f5_unit, $mcx_unit, $w);

    local($fname) = $base . ".f5.mcx.w";

    if($parms{"d"} & $GENERAL_PARSE)
    {
	print "###################################################\n";
	print "Parsing f5.mcx.w file....\n";
    };

				# Open the file
    open(FP, "<$fname") ||
	die "parse_f5_mcx_w(): error opening file ($fname): $!\n";

    $_ = ;			# Get the header and check it
    /^f5.mcx.w/ ||
	die "parse_f5_mcx_w(): error parsing header ($_) (line $.)\n";

    &scan_to_next;

    while($_)			# Loop as long as there are lines
    {
	/^F5.(\d+)\b/ ||
	    die "parse_f5_mcx_w(): error parsing F5 line ($_) (line $.)\n";

	$f5_unit = $1;
				# Check to make sure this is a legal
				#   index.
	if($f5_unit < 0 || $f5_unit >= $f5{"num"})
	{
	    die "parse_f5_mcx_w(): Illegal F5 unit index specified: $f5_unit (expecting between 0 and "
		. ($f5{"num"}-1) . "\n";
	};

#	print "UNIT $1\n";

				# Loop for each MCX connection
	&scan_to_next || last;
	while($_)
	{
				# Pull out connection details
	    /^Mcx.(\d+)\s+([.\d]+)\b/ || last;
	    $mcx_unit = $1;
	    $w = $2;

	    if($mcx_unit < 0 || $mcx_unit >= $mcx{"num"})
	    {
		die "parse_f5_mcx_w(): Illegal MCX unit index specified: $mcx_unit (expecting between 0 and "
		    . ($mcx{"num"}-1) . "\n";
	    };

#	    print "$f5_unit -> $mcx_unit ($w)\n";
#	    $parms{"d"} |= 0x8;
	    &add_connection("F5", $f5_unit,
			    $w,
			    "support connector", "Mcx", $mcx_unit);
	    
#	    $parms{"d"} &= ~0x8;
	    &scan_to_next || last;
	}
    };

    close FP;
};

1;


[ return ]