%M4 needs explicit name #### #!/usr/bin/perl use strict; ###################################### # variables ########### # this is the TV my $tv; # profile is the CTFM or FTFM my $profile; # $reg is the name of the regulation my $reg; # $reason is the reason of the regulation my $reason; # $fmp is the name of the FMP my $fmp; # $date is the date my $date; # ${autre_date} is the same as {date} but it is rearranged. my $autre_date; # ${duration_reg} is the length of the regulation, which is equal to the length of the CUT file + the count_parameter : 60 or 20 my $duration_reg; my $count_parameter; my $filename; my $entry_count; my $flow_rate; my $Duration; my $q; # we introduce ${mod_target} because we have to compare the target to a relative flow $q # the target ranges from 0 to 50, so the ${mod_target} ranges from 0 to 0.5 # which is the same order of magnitude as the $q my $mod_target; #there are two arguments $count_parameter=$ARGV[1]; $Duration = 0; $duration_reg=0; if ($ARGV[0] =~ /^(\d\d\d\d)(\d\d)(\d\d)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$/) { $tv="$4"; $profile="$5"; $reg="$6"; $reason="$7"; $fmp="$8"; $date="$3/$2/$1"; $autre_date="$3"."$2"."$1"; } # what follows aims at calculating the time by looking for the number of lines open (INFILE,"$ARGV[0]"); while () { $duration_reg++; } # after summing up the number of lines in the CUT file, you have to add the count_parameter $duration_reg=$duration_reg+$count_parameter-1; close INFILE; open (INFILE,"$ARGV[0]"); $filename = "M4_all_target"."_$profile"."_$reg"."_$autre_date"."_$reason"."_$duration_reg"."_$fmp"; open (OUTFILE, ">$filename.txt"); while() { if (/^(\d+);(\d+);(\d+)\n$/) { $entry_count=$2; $flow_rate=$3; } $q=$entry_count/$flow_rate-1; $Duration = $Duration + 1; my @TARGET = (0..50); my $target; my $M4; my $M4_compteur; foreach $target(@TARGET){ ${mod_target}=${target}/100; if ($q > ${mod_target}) { $M4_compteur{$target} = 1; } else { $M4_compteur{$target} = 0; } $M4{$target} = $M4{$target} + $M4_compteur{$target}; } } foreach $target(@TARGET){ $M4{$target} = $M4{$target}/$Duration; } print OUTFILE "$reg;;$M4{0};$M4{1};$M4{2};$M4{3};$M4{4};$M4{5};$M4{6};$M4{7};$M4{8};$M4{9};$M4{10};$M4{11};$M4{12};$M4{13};$M4{14};$M4{15};$M4{16};$M4{17};$M4{18};$M4{19};$M4{20};$M4{21};$M4{22};$M4{23};$M4{24};$M4{25};$M4{26};$M4{27};$M4{28};$M4{29};$M4{30};$M4{31};$M4{32};$M4{33};$M4{34};$M4{35};$M4{36};$M4{37};$M4{38};$M4{39};$M4{40};$M4{41};$M4{42};$M4{43};$M4{44};$M4{45};$M4{46};$M4{47};$M4{48};$M4{49};$M4{50};$tv;$reg;$date;$reason;$duration_reg;$fmp\n"; close INFILE; close OUTFILE;