# Usage : perl ipmap.pl NODE1,NODE2,.. filename 
#        e.g. perl ipmap.pl 2,6,11 gastrocnemius >> creates gastrocnemius.ipmap
#
# Note  : This script creates an *.ipmap (e.g. gastrocnemius.ipmap) for specified 
#         nodes numbers (e.g. 2,6,11) at the command line. It assumes that the 
#         specified nodes have only TWO VERSIONS.
#
# Author: Kumar Mithraratne. 20th Nov. 2006.	 


$nodes = $ARGV[0]; $file_name = $ARGV[1];	
chomp $nodes;                     #print "$nodes\n";
@numbers = split (/,/,$nodes);    #print "$numbers[0] $numbers[1]\n";
$total = $#numbers + 1;           #print "$total\n";


######################## CREATING IPMAP FILE ##############################

open (IPMAP, ">$file_name.ipmap") || die ("CAN'T CREATE $file_name.ipmap");

print IPMAP " CMISS Version 2.1  ipmap File Version 1\n";
print IPMAP " Heading: $file_name - $nodes\n";
print IPMAP " \n"; 
print IPMAP " Define node position mapping [N]? Y\n";
print IPMAP " The number of nodes with special mappings is [    $total]: $total\n";

for ($n = 0; $n < $total; $n++)
    {
     print IPMAP " \n";
     print IPMAP " Node number [    $numbers[$n]]: $numbers[$n]\n"; 
     for ($j = 1; $j < 4; $j++)
        {
     print IPMAP " For the Xj($j) coordinate:\n";
     print IPMAP " For version number 1:\n";
     print IPMAP " Is the nodal position mapped out [N]? N\n";
     print IPMAP " Is the derivative wrt direction 1 is mapped out [N]? N\n";
     print IPMAP " Is the derivative wrt direction 2 is mapped out [N]? N\n";
     print IPMAP " Is the derivative wrt directions 1 & 2 is mapped out [N]? N\n";
     print IPMAP " For version number 2:\n";
     print IPMAP " Is the nodal position mapped out [N]? Y\n";
     print IPMAP " Enter node, version, direction, derivative numbers to map to [1,1,1,1]: $numbers[$n],1,$j,1\n";
     print IPMAP " Enter the mapping coefficient [1]: 1.0\n";
     print IPMAP " Is the derivative wrt direction 1 is mapped out [N]? Y\n";
     print IPMAP " Enter node, version, direction, derivative numbers to map to [1,1,1,1]: $numbers[$n],1,$j,2\n";
     print IPMAP " Enter the mapping coefficient [1]: 1.0\n";
     print IPMAP " Is the derivative wrt direction 2 is mapped out [N]? Y\n";
     print IPMAP " Enter node, version, direction, derivative numbers to map to [1,1,1,1]: $numbers[$n],1,$j,3\n";
     print IPMAP " Enter the mapping coefficient [1]: -1.0\n";
     print IPMAP " Is the derivative wrt directions 1 & 2 is mapped out [N]? Y\n";
     print IPMAP " Enter node, version, direction, derivative numbers to map to [1,1,1,1]: $numbers[$n],1,$j,4\n";
     print IPMAP " Enter the mapping coefficient [1]: -1.0\n";
        }

    }
