Hi
I am trying to use a perl script , basically a file format converter, and regardless of the instance i throw at it, it always ends with a kill after all available memory has been taken...
this is the script...
#!/usr/bin/perl
# use strict;
# Felde Roland <felderoland@chello.hu>
# 2005.09.04 Bugfixed
# 2006.07.12 Add versioncheck: can convert acis version 4 and version
+7
# 2006.11.08. Can convert sat files with sequence-nr. New sequence det
+ection.
# 2007.07.12 Add version 16
my $nr = 0; # Z�hler f�r die acis sequensen
my $mod = 0;
my $lines;
my @satseq;
@satfile = <STDIN>;
$satlength = @satfile;
# Aufbereitung der satfile #######################
$satseq[0]=$satfile[0];
$satseq[1]=$satfile[1];
$satseq[2]=$satfile[2];
$sorsz=3;
for ($i=3; $i<$satlength;$i++){
$ln = $satfile[$i];
chomp($ln);
if ( $ln =~ /\#/ ) {
$satseq[$sorsz] = $satseq[$sorsz].$ln;
$sorsz++;
}else{
$satseq[$sorsz] = $satseq[$sorsz].$ln;
}
}
$sorsz=0;
foreach $ln (@satseq) {
$ln =~ s/\s+/ /g;
$satseq[$sorsz] = $ln;
# print $sorsz."-".$satseq[$sorsz]."\n";
while ( ($listfaces[$sat_hash{next_face}{$mv}]) ne "\$-1" ) {
$faces[$nr] = @satseq[&cut($listfaces[$sat_hash{next_face}
+{$mv}])];
(@listfaces) = split (/ /, $faces[$nr]);
$nr++;
}
&faceexport;
# Ki�r�ti a @faces t�mb�t
@faces="";
# Nachdem die face-s schon konvertiert sind wird das
# komplette body zusammengestellt
$bodyszam = "B".&number($bodynr).$bodynr;
print "GBOD ",$bodyszam," NORM",$surfacelist,"\n";
$bodynr++;
}
}
sub faceexport {
my @coedge;
my @surfs;
my @listcoedge;
my @listloop;
# Exportiert eine face in eine GSUR
$felsz = 0;
foreach $face ( @faces ) {
# Sucht die zu einem face geh�rigen coedge-s zusammen
@listface = split(/ /, $face);
$loop = @satseq[&cut($listface[$sat_hash{loop}{$mv}])];
(@listloop) = split(/ /, $loop);
$firstcoedge = &cut($listloop[$sat_hash{first_coedge}{$mv}]);
$coedge[0] = $satseq[&cut($listloop[$sat_hash{first_coedge}{$m
+v}])];
(@listcoedge) = split(/ /, $coedge[0]);
$nr=1;
# Die werden im @coedge gespeichert
while ( &cut($listcoedge[$sat_hash{next_coedge}{$mv}]) != $fir
+stcoedge ){
$coedge[$nr] = $satseq[&cut($listcoedge[$sat_hash{next_coe
+dge}{$mv}])];
(@listcoedge) = split(/ /, $coedge[$nr]);
$nr++;
}
$sorszam = 0;
#
$linelist = "";
foreach $cedge ( @coedge ) {
(@listcoedge) = split(/ /, $cedge);
$edge = $satseq[&cut($listcoedge[$sat_hash{list_coedge}{$m
+v}])];
(@listedge) = split(/ /, $edge);
# Stellt die richtung einer linie ein
# print "irany:".$listcoedge[$sat_hash{edge_sign}{$mv}]."\n"
+;
if ($listcoedge[$sat_hash{edge_sign}{$mv}] eq 'forward') {
$sign[$sorszam] = " + ";
} else {
$sign[$sorszam] = " - ";
}
# Sucht die Punkte zusammen
$vertex1 = $satseq[&cut($listedge[$sat_hash{vert1}{$mv}])]
+;
$vertex2 = $satseq[&cut($listedge[$sat_hash{vert2}{$mv}])]
+;
$edgetyp = $satseq[&cut($listedge[$sat_hash{etyp}{$mv}])];
(@point3) = split(/ /, $edgetyp);
&points;
#print "vonalfajta:".$point3[0]."\n";
if ($point3[0] eq "straight-curve") {
$vonalsz[$sorszam] = "L".&number($linenr).$linenr;
$vonalsz[$sorszam] = &linehash(&cut($listcoedge[$sat_h
+ash{list_coedge}{$mv}]),$vonalsz[$sorszam],$vonalp1,$vonalp2);
} elsif ($point3[0] eq "ellipse-curve") {
$vonalp3 = "P".&number($pointnr).$pointnr;
print "PNT ",$vonalp3," ",$point3[$sat_hash{point}{$mv
+}]," ",$point3[($sat_hash{point}{$mv})+1]," ",$point3[($sat_hash{poin
+t}{$mv})+2],"\n";
$pointnr++;
$vonalsz[$sorszam] = "L".&number($linenr).$linenr;
$vonalsz[$sorszam] = &ellipsehash(&cut($listcoedge[$sa
+t_hash{list_coedge}{$mv}]),$vonalsz[$sorszam],$vonalp1,$vonalp2,$vona
+lp3);
} else {
$vonalsz[$sorszam] = "L".&number($linenr).$linenr;
$vonalsz[$sorszam] = &linehash(&cut($listcoedge[$sat_h
+ash{list_coedge}{$mv}]),$vonalsz[$sorszam],$vonalp1,$vonalp2);
}# if vege
$linelist = $linelist.$sign[$sorszam].$vonalsz[$sorszam];
$sorszam++;
}#foreach $coedge
# Ki�r�ti a @coedge t�mb�t
@coedge="";
# Besz�mozza a fel�letet �s ki�rja
+ az �llom�nyba
$surfsz[$felsz] = "S".&number($surfnr).$surfnr;
$surfacelist = $surfacelist." + ".$surfsz[$felsz];
print "GSUR ",$surfsz[$felsz]," + BLEND",$linelist,"\n";
$linelist="";
$surfnr++;
$felsz++;
}#foreach $face
}#faceexport
sub cut {
# Lev�gja a $ jelet a seq sorsz�mr�l, �
+;s hozz�ad egyet,
# mert a geometria le�r�sa a harmadik sorban kezd
+5533;d�tt
$seq = $_[0];
$seq =~ s/\$//;
$seq = $seq + 3;
return $seq;
}
sub number {
if (length($_[0]) == 1) {
$p = "00";
}
if (length($_[0]) == 2) {
$p = "0";
}
if (length($_[0]) == 3) {
$p = "";
}
return $p;
}
sub pointhash {
# Pr�ft ob der Punkt schon exportiert wurde, wenn ja wird i
+hre Nummer f�r
# die aktuelle LINE benutzt.
if ($points[$_[0]]) {
$retp = $points[$_[0]];
} else {
$points[$_[0]]= $_[1];
$retp = $_[1];
print "PNT ",$_[1]," ",$_[2]," ",$_[3]," ",$_[4],"\n";
$pointnr++
}
return $retp;
}
sub linehash {
# Pr�ft ob die Linie schon exportiert wurde, wenn ja wird i
+hre Nummer f�r
# die aktuelle GSURF benutzt.
if ($lines[$_[0]]) {
$retp = $lines[$_[0]];
} else {
$lines[$_[0]]= $_[1];
$retp = $_[1];
print "LINE ",$_[1]," ",$_[2]," ",$_[3]," 102\n";
$linenr++
}
return $retp;
}
sub ellipsehash {
# Pr�ft ob der Bogen schon exportiert wurde, wenn ja wird s
+eine Nummer f�r
# die aktuelle GSURF benutzt.
if ($lines[$_[0]]) {
$retp = $lines[$_[0]];
} else {
$lines[$_[0]]= $_[1];
$retp = $_[1];
print "LINE ",$_[1]," ",$_[2]," ",$_[3]," ",$_[4]," 104\n";
$linenr++
}
return $retp;
}
sub points {
# Exportiert die zu eine Linie geh�rende Punkte (Endpunkte)
+
(@listvert1) = split(/ /, $vertex1);
(@listvert2) = split(/ /, $vertex2);
$ppoint1 = $satseq[&cut($listvert1[$sat_hash{listpoint}{$mv}])];
$ppoint2 = $satseq[&cut($listvert2[$sat_hash{listpoint}{$mv}])];
(@point1) = split(/ /, $ppoint1);
(@point2) = split(/ /, $ppoint2);
$vonalp1 = "P".&number($pointnr).$pointnr;
$vonalp1 = &pointhash(&cut($listvert1[$sat_hash{vertpoint}{$mv}]),
+$vonalp1,$point1[$sat_hash{point}{$mv}],$point1[($sat_hash{point}{$mv
+})+1],$point1[($sat_hash{point}{$mv})+2]);
$vonalp2 = "P".&number($pointnr).$pointnr;
$vonalp2 = &pointhash(&cut($listvert2[$sat_hash{vertpoint}{$mv}]),
+$vonalp2,$point2[$sat_hash{point}{$mv}],$point2[($sat_hash{point}{$mv
+})+1],$point2[($sat_hash{point}{$mv})+2]);
}
sub hashdefine {
%sat_hash = (
"lump" => { "4" => "2", "7" => "4", "16" => "5"},
"shell" => { "4" => "3", "7" => "5", "16" => "6"},
"first_face" => { "4" => "4", "7" => "6", "16" => "7"},
"next_face" => { "4" => "2", "7" => "4", "16" => "5"},
"loop" => { "4" => "3", "7" => "5", "16" => "6"},
"first_coedge" => { "4" => "3", "7" => "5", "16" => "6"},
"next_coedge" => { "4" => "2", "7" => "4", "16" => "5"},
"list_coedge" => { "4" => "5", "7" => "7", "16" => "8"},
"edge_sign" => { "4" => "6", "7" => "8", "16" => "9"},
"vert1" => { "4" => "2", "7" => "4", "16" => "5"},
"vert2" => { "4" => "3", "7" => "6", "16" => "7"},
"etyp" => { "4" => "5", "7" => "9", "16" => "10"},
"listpoint" => { "4" => "3", "7" => "5", "16" => "6"},
"point" => { "4" => "2", "7" => "4", "16" => "5"},
"vertpoint" => { "4" => "3", "7" => "5", "16" => "6"}
)
}
sub hashdefine_nr {
%sat_hash = (
"lump" => { "4" => "3", "7" => "5", "16" => "6"},
"shell" => { "4" => "4", "7" => "6", "16" => "7"},
"first_face" => { "4" => "5", "7" => "7", "16" => "8"},
"next_face" => { "4" => "3", "7" => "5", "16" => "6"},
"loop" => { "4" => "4", "7" => "6", "16" => "7"},
"first_coedge" => { "4" => "4", "7" => "6", "16" => "7"},
"next_coedge" => { "4" => "3", "7" => "5", "16" => "6"},
"list_coedge" => { "4" => "6", "7" => "8", "16" => "9"},
"edge_sign" => { "4" => "7", "7" => "9", "16" => "10"},
"vert1" => { "4" => "3", "7" => "5", "16" => "6"},
"vert2" => { "4" => "4", "7" => "7", "16" => "8"},
"etyp" => { "4" => "6", "7" => "10", "16" => "11"},
"listpoint" => { "4" => "4", "7" => "6", "16" => "7"},
"point" => { "4" => "3", "7" => "5", "16" => "6"},
"vertpoint" => { "4" => "4", "7" => "6", "16" => "7"}
)
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.