#!/usr/bin/perl
# $Id: get_all_impedance,v 1.6 2025/11/26 09:00:15 sqko Exp $
use strict;
use AFM;

my $rig = 0;
if ( scalar(@ARGV) > 0 ) 
{
    my $rigno = $ARGV[0];
    $rigno =~ /(\d+)/;
    $rig = $1;
}

&check_run($rig);

my $test = 1;
if ( scalar(@ARGV) > 1 ) 
{
    my $ttestno = $ARGV[1];
    $ttestno =~ /(\d+)/;
    $test = $1;
}
else
{
    $test = &AFM::get_test_nr($rig)+0;
}
## Remove any 'check time' file
my $cmd = '/bin/rm -f '.$AFM::publicdir.'rig'.$rig.'/'.$rig.'test'.$test.'/impedance/'.$rig.'test'.$test.'_12b_times*';
system($cmd);
## Remove any 'choice' file
$cmd = '/bin/rm -f '.$AFM::publicdir.'rig'.$rig.'/'.$rig.'test'.$test.'/impedance/'.$rig.'test'.$test.'*_choices.txt';
system($cmd);
## Check time stamps for time offset ###
system("/usr/local/bin/check_i2b_timestamps.py $rig $test 30");
$cmd = 'dir -1 '.$AFM::publicdir.'rig'.$rig.'/'.$rig.'test'.$test.'/impedance/*.i2b 2> /dev/null';
my @list = `$cmd`;
if  (@list)
{
    for my $file (@list)
    {
	$file =~ /([\w+\.\-\_\:]+)\s*$/;
	$file = $1;
	system("/usr/local/bin/impedance_plot.pl $rig $test $file");
    }
    system("/usr/local/bin/get_impedance_data $rig $test");
    system("/usr/local/bin/impedance_html.pl $rig $test");
}
system("/usr/local/bin/celltest/create_data_export.pl $rig > /dev/null 2> /dev/null");
