Programma che estrae le misure dai file di dati
Il programma prende come argomento il nome del file da analizzare. All'interno del codice le variabili $tmin e $tmax determinano la durata minima e massima della valanga da estrarre.
Le misure vengono salvate in file il cui nome e' modificato dall'aggiunta di un suffisso:
- -avat.dat Valanghe velocita' vs tempo (valanghe 1)
- -ava.dat Valanghe velocita' vs. spostamento (valanghe 2)
Questi due file contengono 4 colonne. le ultime due sono la variabile (tempo o spostamento) e la velocita'. Le prime due invece sono i corrispondenti valori x e y della valanga normalizzata (x va da 0 a 1 e l'integrale di y rispetto a x fa 1).
- -dursize.dat Tre colonne: Durata, spostamento (normalizzazione valanghe 1), "energia" (normalizzazione valanghe 2)
- -duration.dat Distribuzione (cumulativa) delle durate
- -size.dat Distribuzione (cumulativa) degli spostamenti
- -size2.dat Distribzione (cumulativa) delle "energie"
Codice (perl):
#!/usr/bin/perl
# Usage: ava.pl [datafile]
# Data file contains 3 cols:
# time torque velocity
# The program computes:
# the avalanches of velocities vs time
# the avalanches of velocities versus deplacement
# These paramters set the boundaries of averaged avalanches
$tmin=50;
$tmax=10000;
#
$first=0;
foreach $file (@ARGV)
{
$nava=0;
open(INPFILE,"<$file") || die;
print "# Opening $file-ava.dat\n";
open(AVA,">$file-ava.dat") || die;
print "# Opening $file-avat.dat\n";
open(AVAT,">$file-avat.dat") || die;
while(<INPFILE>){
@line=split(/ /);
if($line[2]>0.0)
{
if($first==1){
# Write separator
print AVA "\n\n";
print AVAT "\n\n";
# reset flag
$first=0;
# $t0=$line[0];
$ti=$line[0];
}
# Load arrays
$s+=$line[2]*($line[0]-$t0);
$s2+=$line[2]*$line[2]*($line[0]-$t0);
$t0=$line[0];
$tf=$line[0];
push @vel, $line[2];
push @pos, $s;
$last=1;
}else{
if($last==1){
# Write data
if(@vel>$tmin && @vel<$tmax)
{
$nava++;
# Compute explicitly the normalization
$norm=0;
$p0=0;
for($i=0; $i<@vel;$i++)
{
$norm+=$vel[$i]*($pos[$i]-$p0)/$s;
$p0=$pos[$i];
}
# printf "norm=%g, s=%g\n",$norm,$s;
# printf "%g, %g, %g\n",$tf-$ti,$#vel,$s;
# Compute max, min, duration and size
$p0=0;
for($i=0; $i<@vel;$i++)
{
printf AVA "%g, %g, %g, %g\n", ($pos[$i]+$p0)/2./$s,$vel[$i]/$norm, $pos[$i],$vel[$i];
printf AVAT "%g, %g, %i, %g\n", $i/$#vel,$vel[$i]/$s*($tf-$ti),$i, $vel[$i];
$p0=$pos[$i];
}
}
push @size, $s;
push @size2, $s2;
push @duration, $#vel;
$last=0;
@vel=();
@pos=();
$s=0;
$s2=0;
}
# Reset flags and vars
$first=1;
$t0=$line[0];
}
}
close(INPFILE);
printf "# Number of avalanche=%g (%d < T < %d)\n",$nava, $tmin, $tmax;
close(AVA);
printf "# File closed\n";
close(AVAT);
printf "# File closed\n";
print "# Opening $file-dursize.dat\n";
open(OUT,">$file-dursize.dat") || die;
for($i=0; $i<@duration;$i++)
{
printf OUT "%g, %g, %g\n", $duration[$i], $size2[$i], $size[$i];
}
close(OUT);
printf "# File closed\n";
print "# Opening $file-size.dat\n";
open(SIZE,">$file-size.dat") || die;
printf "# Sorting array with %d elements...",$#size;
@sorted=();
@sorted=sort {$a <=> $b} @size;
printf "done\n";
for($i=0; $i<@sorted;$i++)
{
printf SIZE "%g %g\n", $sorted[$i], 1.-$i/$#sorted;
}
close(SIZE);
printf "# File closed\n";
print "# Opening $file-size2.dat\n";
open(SIZE,">$file-size2.dat") || die;
printf "# Sorting array with %d elements...",$#size;
@sorted=();
@sorted=sort {$a <=> $b} @size2;
printf "done\n";
for($i=0; $i<@sorted;$i++)
{
printf SIZE "%g %g\n", $sorted[$i], 1.-$i/$#sorted;
}
close(SIZE);
printf "# File closed\n";
print "# Opening $file-duration.dat\n";
open(DURATION,">$file-duration.dat") || die;
printf "# Sorting array with %d elements...",$#duration;
@sorted=sort {$a <=> $b} @duration;
printf "done\n";
for($i=0; $i<@sorted;$i++)
{
printf DURATION "%g %g\n", $sorted[$i], 1.-$i/$#sorted;
}
close(DURATION);
printf "# File closed\n";
}
--
TWikiGuest - 20 Sep 2004