aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCarpet/CarpetIOASCII/src/util/Carpet2ygraphCat.pl60
1 files changed, 53 insertions, 7 deletions
diff --git a/Carpet/CarpetIOASCII/src/util/Carpet2ygraphCat.pl b/Carpet/CarpetIOASCII/src/util/Carpet2ygraphCat.pl
index 5c312d66f..5608771e3 100755
--- a/Carpet/CarpetIOASCII/src/util/Carpet2ygraphCat.pl
+++ b/Carpet/CarpetIOASCII/src/util/Carpet2ygraphCat.pl
@@ -16,44 +16,90 @@ my $fh = new FileHandle(">$file") || die "Unable to open file \"$file\".";
my %data;
my $time = -1;
my $new = 0;
+my $currentit = -1;
+my $lastit = -1;
+my @datatoprint;
+my $nsets = 1;
+my $maxlength = 0;
+my @lengths;
+
+$lengths[0]=0;
while (<CARPETFILE>)
{
$line = $_;
- if ($line =~ /^#/)
+ if ($line =~ "iteration") {
+ @itline = split(/ +/,$line);
+ $currentit = @itline[2];
+ }
+ elsif ($line =~ /^#/)
{
#Do nothing for headers!
}
elsif ($line =~ /([0-9+-ed.]+)*/)
{
@dataline = split(/ +/,$line);
- if ($dataline[8] - $time > 1.e-10)
+ if ($currentit != $lastit)
{
if ($new)
{
- print $fh "\n\n\"Time = ",$time,"\n";
+ push(@datatoprint,"\n\n\"Time = ".$time."\n");
my @sortedcoords = sort numerically (keys %data);
my $localcoord;
foreach $localcoord (@sortedcoords)
{
- print $fh $localcoord." ".$data{$localcoord};
+ push(@datatoprint, $localcoord." ".$data{$localcoord});
}
+ $maxlength = $maxlength > (scalar @sortedcoords) ? $maxlength : (scalar @sortedcoords);
+ $lengths[$nsets-1]=(scalar @sortedcoords);
+ $nsets++;
+ $lengths[$nsets-1]=0;
+ %data=();
}
$new++;
$time = $dataline[8];
-
+ $lastit = $currentit;
}
my $coord = $dataline[9+$ARGV[0]];
my $val = $dataline[12];
$data{$coord} = $val;
}
}
-print $fh "\n\"Time = ",$time,"\n";
+push(@datatoprint, "\n\"Time = ",$time,"\n");
my @sortedcoords = sort numerically (keys %data);
my $localcoord;
foreach $localcoord (@sortedcoords)
{
- print $fh $localcoord." ".$data{$localcoord};
+ push(@datatoprint, $localcoord." ".$data{$localcoord});
+}
+$maxlength = $maxlength > (scalar @sortedcoords) ? $maxlength : (scalar @sortedcoords);
+$lengths[$nsets-1]=(scalar @sortedcoords);
+$nsets++;
+$lengths[$nsets-1]=0;
+
+my $oldline="";
+$nouts=0;
+my $set=0;
+foreach $line (@datatoprint) {
+ if ($line =~ "Time") {
+ if ($oldline) {
+ for (my $i=$lengths[$set-1]; $i<$maxlength;$i++) {
+ $nouts++;
+ print $fh $oldline;
+ }
+ }
+ $set++;
+ print $fh $line;
+ }
+ else {
+ $nouts++;
+ print $fh $line;
+ $oldline=$line
+ }
+}
+for (my $i=$lengths[$set-1]; $i<$maxlength;$i++) {
+ $nouts++;
+ print $fh $oldline;
}
sub numerically {$a <=> $b;}