Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:05

0001 #!/usr/local/bin/perl
0002 
0003 ## Usage:
0004 ## cat yourtexfile | ./tex2xml > newmaterials.xml  
0005 
0006 while (<>)
0007 {
0008     if(/ Norm. mixture density \[g\/cm\$\^3\$] &\s* ([\d\.]+)\s*/ )
0009   {
0010    $density=$1;
0011     print "\n";
0012     print "  <CompositeMaterial name=\"$material\" density=\"$density*g/cm3\" symbol=\" \" method=\"mixture by weight\">\n";
0013     $i=0;
0014     $tot=0;
0015     while (($compsname, $compsperc) = each(%comps))
0016 #     while($i<$ncomp)
0017     {
0018      print "    <MaterialFraction fraction=\"".$compsperc."\">\n";
0019      print "      <rMaterial name=\"materials:".$compsname."\"/>\n";
0020      print "    </MaterialFraction>\n";
0021      $tot+=$compsperc;
0022      $i++;
0023    }  
0024     print "  </CompositeMaterial>\n";
0025 #    print STDERR "Total fraction is: ".$tot."\n"; 
0026     if(abs($tot-1) > 0.001 ) 
0027     {
0028      die "ERROR: total fraction is ".$tot; 
0029     }
0030    $flushed=1; 
0031  }
0032 
0033 if(/Material name:\s*([\w\\]+)/) #new mixture
0034 # OLD:    if(/Material name: ([\w\\]+)/) #new mixture
0035   {
0036     $flushed=0;
0037    # @compsname = ();
0038     %comps = ();
0039     $ncomp =0;
0040     $material = $1; 
0041     $material =~ s/\\//g;
0042     #print "New material: ".$material."\n";
0043     $inmaterial=1;
0044   }
0045   if(/^(\s*[0-9]+\s*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)&(.*)/)
0046   {
0047     $compsname = $3;
0048     $compsperc = $7;
0049     $compsperc =~ s/\s*//g;
0050     $compsperc /= 100;
0051     $compsname =~ s/^\s*//;
0052     $compsname =~ s/\s*$//;
0053     $compsname =~ s/\\//g;
0054     $comps{$compsname} += $compsperc;
0055      $ncomp++;
0056  }
0057   if(/\\end{tabular}/)
0058   { 
0059    $inmaterial=0;
0060    $density=-1;
0061   }
0062  
0063 
0064 }