my $error_cnt = 0; my $day_cnt = 0; my $month = 0; my $test; my $julday_old; open(OUT,">$resultsfile.corrected"); open(OUT1,">$resultsfile.gaps"); open(INP, $resultsfile); while (){ chomp($_); my $line = $_; my ($timestr,$timebin,$fish,$vel,$azi,$px,$py) = split(/\s+/,$line); my ($year,$julday,$hour,$min,$sec,$msec) = split(/\./,$timestr); my $timest = timegm_nocheck($sec,$min,$hour,$julday,$month,$year); my $timeend = $timest + 512; $julday_old = $julday if $. == 1; #$test = sprintf"%s %s\n",$julday_old,$day_cnt if $. != 1; #printf OUT1 "%s",$test; if(! ($julday == $julday_old)){ printf OUT1 "%s %s\n",$julday_old,$day_cnt; print "$julday_old "; print "$day_cnt\n"; $julday_old = $julday; $day_cnt = 0; } open(IN,"$gapsfile"); while (){ chomp($_); my ($sttime,$endtime) = split(/\s+/,$_); if ($sttime < $timest && $endtime > $timeend){ print "Timespan $timestr will be removed\n"; $day_cnt++; $error_cnt++; last; } elsif ($endtime > $timest+3.2 && $endtime < $timeend){ print "Timespan $timestr will be removed\n"; $day_cnt++; $error_cnt++; last; } elsif ($sttime+3.2 < $timeend && $sttime > $timest){ print "Timespan $timestr will be removed\n"; $day_cnt++; $error_cnt++; last; } else{ printf OUT "$line\n"; } } close(IN); } close(OUT); close(OUT1); print "\n\nTotal number of timespans of 8m 32s removed is: $error_cnt\n"; close(INP);