#!/usr/bin/perl -w # get_possible_epics.perl [filename] # # by: Jaideep Singh # # date: 12/17/2005 # # about: reads a raw data file and looks for all possible EPICS variables # creates a file that contains a list of unique possible EPICS variables names and their count # skips over the first 500 lines of a raw data file (i don't know how this script handles a split data file...) # # EPICS info is injected into the data stream at certain times intervals. # More important stuff is logged more often. # Immediately preceding one log cycle, a timestamp is grabbed # Each variable is recorded in ASCII format on its own line: # # [variable name, upto 30 characters][at least one blank space][upto 20 characters for value] # # for example: # # IPM1H04B.XPOS -0.0408508 # 000000000111111111122222222223333333333444444444455 # 123456789012345678901234567890123456789012345678901 # # Variable names can have ".", ":","+","_" as well as alphanumeric characters #getting name of file to search + ARGUMENT ERROR HANDLING $filename = $ARGV[0]; print "Uh, what file do you want me to look at dude?: Too few arguments\n" and die unless ($filename); print "Scared and confused: Too many arguments\n" and die unless (($#ARGV+1) < 2); open(FILE,$filename) or print "doh! ($filename): File not found\n" and die; print "\nSearching raw data file:\t$filename\n"; #initializing variables $count = 0; $line_count = 0; $max_size_variable_name = 0; $max_number_of_spaces = 0; $max_size_value = 0; $min_size_variable_name = 9999; $min_number_of_spaces = 9999; $min_size_value = 9999; my %variable_count; #searching line by line, grabbing the timestamp before and after searching print "\nstart\t"; print scalar localtime; print "\n"; while() { $line_count++; if (/([\w\-.:+]{5,30})(\s{1,26})([\w+\-.]{1}[\w+\-.\s:]{0,19})/) { if ((length($_) < 52) && ($line_count > 500)) { chomp; $count++; # print "$line_count : $_\n"; $max_size_variable_name = length($1) if (length($1) > $max_size_variable_name); $max_number_of_spaces = length($2) if (length($2) > $max_number_of_spaces); $max_size_value = length($3) if (length($3) > $max_size_value); $min_size_variable_name = length($1) if (length($1) < $min_size_variable_name); $min_number_of_spaces = length($2) if (length($2) < $min_number_of_spaces); $min_size_value = length($3) if (length($3) < $min_size_value); if ($variable_count{$1}) { $variable_count{$1}++ } else { $variable_count{$1} = 1} } } }; close(FILE); print "end\t"; print scalar localtime; print "\n\nFound $count total instances of possible EPICS variables\n\n"; print "minimum size of variable name : $min_size_variable_name\n"; print "maximum size of variable name : $max_size_variable_name\n"; print "minimum number of spaces : $min_number_of_spaces\n"; print "maximum number of spaces : $max_number_of_spaces\n"; print "minimum size of value : $min_size_value\n"; print "maximum size of value : $max_size_value\n\n"; #setting up output file @file_name_parts = split(/\./,$filename); $file_out = $file_name_parts[0]."_possible_epics_var.txt"; print "OUTPUT filename : $file_out\n\n"; open(OUTPUT,">$file_out"); #$total_time_sec = 220; foreach $variable_name (sort keys %variable_count) { # $update_time = int(100*$total_time_sec/$variable_count{$variable_name})/100; # print "$variable_name\t\t\t$update_time\n" if ($update_time < 60) # print OUTPUT "$variable_name\t\t\t$variable_count{$variable_name}\n" if ($variable_count{$variable_name} > 2) print OUTPUT "$variable_name\n" if ($variable_count{$variable_name} > 1) } close(OUTPUT);