<commit_before>#!/usr/bin/perl
# ******************************************************************************
# FILE : acl.pl
#
# LAST MODIFIED : 16 September 2001
#
# DESCRIPTION :
# Calculates the mean and standard deviation of the activation cycle length
# (acl) for each electrode in a unemap events file.
#
# USAGE :
# acl [options] events-file acl-file
# ==============================================================================

use strict;
use Getopt::Long;

my $acl;
my $calculate;
my $electrode;
my $event_time;
my @event_times;
my $file_name;
# the first electrode in the events file to calculate acls for
my $first_electrode;
my $help;
# the first electrode in the events file to calculate acls for
my $last_electrode;
my $line;
my $number_of_acls;
my $sum_acl;
my $sum_acl_squared;
my $temp;

# get the options
if (Getopt::Long::GetOptions(
	'f|first_electrode=s' => \$first_electrode,
	'h|help' => \$help,
	'l|last_electrode=s' => \$last_electrode))
{
	if (defined $help)
	{
		printf("Usage: acl [options] events-file acl-file\n");
		printf("  -f first_electrode  First electrode to calculate acls for\n");
		printf("  -h  Display this help\n");
		printf("  -f last_electrode  Last electrode to calculate acls for\n");
	}
	else
	{
		# open the events file
		$file_name=shift @ARGV;
		if ((defined $file_name) and (defined open EVENTS,"<$file_name"))
		{
			# skip the event times header
			while (($line=<EVENTS>) and ('Electrode' ne substr($line,0,9)))
			{
			}
			# open the acl file
			$file_name=shift @ARGV;
			if ((defined $file_name) and (defined open ACLS,">$file_name"))
			{
				printf(ACLS "Electrode  mean  standard_deviation\n");
				# read the events file calculating and writing the mean and standard
				#   deviation for the activation cycle as you go
				if (defined $first_electrode)
				{
					$calculate=0;
				}
				else
				{
					$calculate=1;
				}
				while (($line=<EVENTS>) and ('Reference' ne substr($line,0,9)))
				{
					# get rid of end of lines
					chomp $line;
					@event_times=split /,/,$line;
					$electrode=shift @event_times;
					if ((0==$calculate) and (defined $first_electrode) and
						(defined $electrode) and ($electrode eq $first_electrode))
					{
						$calculate=1;
					}
					if (0!=$calculate)
					{
						$event_time=shift @event_times;
						$number_of_acls=0;
						$sum_acl=0;
						$sum_acl_squared=0;
						while ((defined $event_time) and ('none' eq $event_time))
						{
							$event_time=shift @event_times;
						}
						$acl=$event_time;
						while (defined $event_time)
						{
							$event_time=shift @event_times;
							if ((defined $event_time) and ('none' ne $event_time))
							{
								$acl=$event_time-$acl;
								$number_of_acls++;
								$sum_acl += $acl;
								$sum_acl_squared += $acl*$acl;
								$acl=$event_time;
							}
						}
						printf(ACLS $electrode);
						if (0<$number_of_acls)
						{
							printf(ACLS ' %g',$sum_acl/$number_of_acls);
						}
						else
						{
							printf(ACLS ' none');
						}
						if (1<$number_of_acls)
						{
							$temp=$sum_acl_squared-$sum_acl*$sum_acl/$number_of_acls;
							if (0<$temp)
							{
								printf(ACLS ' %g',sqrt($temp)/($number_of_acls-1));
							}
							else
							{
								printf(ACLS ' 0');
							}
						}
						else
						{
							printf(ACLS ' none');
						}
						printf(ACLS "\n");
					}
					if ((0!=$calculate) and (defined $last_electrode) and
						(defined $electrode) and ($electrode eq $last_electrode))
					{
						$calculate=0;
					}
				}
				close ACLS;
			}
			else
			{
				printf("Could not open acl file\n");
			}
			close EVENTS;
		}<commit_msg>Now writes error messages if the first or last electrodes are not in the events file<commit_after>#!/usr/bin/perl
# ******************************************************************************
# FILE : acl.pl
#
# LAST MODIFIED : 23 September 2001
#
# DESCRIPTION :
# Calculates the mean and standard deviation of the activation cycle length
# (acl) for each electrode in a unemap events file.
#
# USAGE :
# acl [options] events-file acl-file
# ==============================================================================

use strict;
use Getopt::Long;

my $acl;
my $calculate;
my $electrode;
my $event_time;
my @event_times;
my $file_name;
# the first electrode in the events file to calculate acls for
my $first_electrode;
my $valid_first_electrode;
my $help;
# the first electrode in the events file to calculate acls for
my $last_electrode;
my $valid_last_electrode;
my $line;
my $number_of_acls;
my $sum_acl;
my $sum_acl_squared;
my $temp;

# get the options
if (Getopt::Long::GetOptions(
	'f|first_electrode=s' => \$first_electrode,
	'h|help' => \$help,
	'l|last_electrode=s' => \$last_electrode))
{
	if (defined $help)
	{
		printf("Usage: acl [options] events-file acl-file\n");
		printf("  -f first_electrode  First electrode to calculate acls for\n");
		printf("  -h  Display this help\n");
		printf("  -l last_electrode  Last electrode to calculate acls for\n");
	}
	else
	{
		# open the events file
		$file_name=shift @ARGV;
		if ((defined $file_name) and (defined open EVENTS,"<$file_name"))
		{
			# skip the event times header
			while (($line=<EVENTS>) and ('Electrode' ne substr($line,0,9)))
			{
			}
			# open the acl file
			$file_name=shift @ARGV;
			if ((defined $file_name) and (defined open ACLS,">$file_name"))
			{
				printf(ACLS "Electrode  mean  standard_deviation\n");
				# read the events file calculating and writing the mean and standard
				#   deviation for the activation cycle as you go
				if (defined $first_electrode)
				{
					$calculate=0;
					$valid_first_electrode=0;
				}
				else
				{
					$calculate=1;
					$valid_first_electrode=1;
				}
				if (defined $last_electrode)
				{
					$calculate=0;
					$valid_last_electrode=0;
				}
				else
				{
					$calculate=1;
					$valid_last_electrode=1;
				}
				while (($line=<EVENTS>) and ('Reference' ne substr($line,0,9)))
				{
					# get rid of end of lines
					chomp $line;
					@event_times=split /,/,$line;
					$electrode=shift @event_times;
					if ((defined $electrode) and (defined $first_electrode)
						and ($electrode eq $first_electrode))
					{
						$valid_first_electrode=1;
						if (0==$calculate)
						{
							$calculate=1;
						}
					}
					if (0!=$calculate)
					{
						$event_time=shift @event_times;
						$number_of_acls=0;
						$sum_acl=0;
						$sum_acl_squared=0;
						while ((defined $event_time) and ('none' eq $event_time))
						{
							$event_time=shift @event_times;
						}
						$acl=$event_time;
						while (defined $event_time)
						{
							$event_time=shift @event_times;
							if ((defined $event_time) and ('none' ne $event_time))
							{
								$acl=$event_time-$acl;
								$number_of_acls++;
								$sum_acl += $acl;
								$sum_acl_squared += $acl*$acl;
								$acl=$event_time;
							}
						}
						printf(ACLS $electrode);
						if (0<$number_of_acls)
						{
							printf(ACLS ' %g',$sum_acl/$number_of_acls);
						}
						else
						{
							printf(ACLS ' none');
						}
						if (1<$number_of_acls)
						{
							$temp=$sum_acl_squared-$sum_acl*$sum_acl/$number_of_acls;
							if (0<$temp)
							{
								printf(ACLS ' %g',sqrt($temp)/($number_of_acls-1));
							}
							else
							{
								printf(ACLS ' 0');
							}
						}
						else
						{
							printf(ACLS ' none');
						}
						printf(ACLS "\n");
					}
					if ((defined $electrode) and (defined $last_electrode) and
						($electrode eq $last_electrode))
					{
						$valid_last_electrode=1;
						if (0!=$calculate)
						{
							$calculate=0;
						}
					}
				}
				if (0==$valid_first_electrode)
				{
					printf("First electrode, %s, is not in the events file\n",
						$first_electrode);
				}
				if (0==$valid_last_electrode)
				{
					printf("Last electrode, %s, is not in the events file\n",
						$last_electrode);
				}
				close ACLS;
			}
			else
			{
				printf("Could not open acl file\n");
			}
			close EVENTS;
		}
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.007457121551081283, 'mean_word_length': 2.749767008387698, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7224339', 'n_tokens_mistral': 3888, 'n_tokens_neox': 2786, 'n_words': 677}