Guest User

Untitled

a guest
Jan 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.92 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. no warnings "recursion";
  4.  
  5. my %ISFET_currents;
  6. my $searchdir;
  7. my $outfile;
  8.  
  9. unless(defined($ARGV[0]) && defined($ARGV[1])) {
  10.     print "Parsing ISFET-2007 transconductance IV curve data files\
  11.    \tsearches in folders recursively starting from specified \"root\" folder\
  12.    \tFoldername => must be ISFET number (device was marked)\
  13.    \tOutput file => to write parsed data\n\
  14.    Data processing:\n\
  15.    \t-find current values at Ugs = 5V\
  16.    \t-find out about the pH of buffer in filename(if recorded)\
  17.    \t-check wheather channel currents meet 350..650 uA range\
  18.    \t-find difference between currents in channels\
  19.    \t-say OK for using if remained ISFETS meet less than 60 uA difference\n\n";
  20.  
  21.     print "Usage:\t./current_script  searchdir  output_filename\n\n";    
  22.     exit;
  23. }
  24. chomp($searchdir = $ARGV[0]);
  25.  
  26. chomp($outfile = $ARGV[1]);
  27.  
  28. open(DATA_FILE, ">>$outfile") ||
  29. die "Can't open $outfile: $!";
  30.  
  31. parse_dir($searchdir);
  32.  
  33. foreach my $ISFET (sort keys %ISFET_currents) {
  34.  
  35.     if(($ISFET_currents{$ISFET}) < 60 ) {
  36.         print DATA_FILE "\nISFET #$ISFET Current diff = $ISFET_currents{$ISFET}";
  37.         print DATA_FILE " OK";
  38.            
  39.     }
  40. }
  41. close(DATA_FILE);
  42.  
  43. sub parse_dir {
  44.  
  45.     my $searchdir = shift;
  46.  
  47.     my $ISFET_num = $searchdir;
  48.     $ISFET_num    =~  s{.*/}{};
  49.  
  50.     opendir(DIR, $searchdir) ||
  51.     die "\nCan't open $searchdir: $!";
  52.  
  53.     my @files = readdir(DIR);
  54.     closedir(DIR);
  55.  
  56.     foreach my $current_file (@files) {
  57.         next if $current_file =~ m/^\.\.?$/;
  58.  
  59.         if ( $current_file =~ m/ugs/i ) {
  60.  
  61.             my $pH_data;
  62.            
  63.             if( $current_file =~ m/pH((\d+)[_.]?(\d+))/gi ) {
  64.                 $pH_data = 'pH' . $1;
  65.             }
  66.  
  67.             open(CUR_FILE, "<$searchdir/$current_file") ||
  68.             die "Can't open $current_file: $!";
  69.  
  70.             my @iv_lines= <CUR_FILE>;
  71.  
  72.             my($Ugs, $Uds, $I0, $I1) = iv_check(@iv_lines);
  73.             my $I_diff = abs($I0 - $I1);
  74.             $I_diff =~ s/(.\d\d)\d+/$1/g;
  75.  
  76.                 if(($I0 < 350 || $I0 > 650 ) ||
  77.                    ($I1 < 350 || $I1 > 650 ))   {
  78.                    
  79.                     print DATA_FILE "\n=============================\
  80.                    \nFile: $current_file\
  81.                    \nISFET = $ISFET_num\
  82.                    \nChannel current is not in range 350..650 uA\
  83.                    \nChannel currents I = $I0, $I1 uA
  84.                    \nVoltage Ugs = $Ugs\n\
  85.                    $pH_data\n";
  86.                 } else {
  87.  
  88.                     $ISFET_currents{$ISFET_num} = $I_diff;
  89.                     print DATA_FILE"\n===============================\
  90.                    \nFile: $current_file\
  91.                    \nISFET = $ISFET_num\
  92.                    \nVoltages:\
  93.                    \n\tUgs = -$Ugs\
  94.                    \n\tUds = -$Uds\
  95.                    \nCurrents:\
  96.                    \n\tI0 = $I0\
  97.                    \n\tI1 = $I1\
  98.                    \n\tDifference = $I_diff\n";
  99.                 }            
  100.             close(CUR_FILE);
  101.         }
  102.  
  103.         if ( -d "$searchdir/$current_file" ) {
  104.             parse_dir("$searchdir/$current_file");
  105.         }
  106.     }
  107. }
  108.  
  109. sub iv_check {
  110.  
  111.     my @lines = @_;
  112.     my @iv_checked;
  113.     foreach my $line (@lines) {
  114.  
  115.         next unless $line =~ m/^(\d\.\d{2})
  116.                                 (?>\s+)
  117.                                 (\d\.\d{2})
  118.                                 (?>\s+)
  119.                                 (\d+\.\d{2})
  120.                                 (?>\s+)
  121.                                 (\d+\.\d{2})
  122.                               /xgi;
  123.         my $Ugs = $1;
  124.         my $Uds = $2;
  125.         my $I0  = $3;
  126.         my $I1  = $4;
  127.        
  128.             if( $Ugs > 4.90 && $Ugs < 5.20) {
  129.                
  130.                 push @iv_checked, $Ugs, $Uds, $I0, $I1;
  131.                 return @iv_checked;
  132.             }
  133.  
  134.     }
  135. }
Add Comment
Please, Sign In to add comment