2023年9月20日 星期三

calculate_sigma

#!/usr/bin/perl
$input_library = $ARGV[0];
$timing_flag=0; $timing_type_flag=0; $get_value_flag=0; $table_count=0;

open(LIB,"<$input_library");
open(NEW, ">hold_sigma.lib") || die "Can not open the file : temp.txt \n";

while(<LIB>){
      print NEW "$_";
      chop $_;
      $table_count++;
      #if(/timing \(\) {/){
  #    #  $timing_flag=1;
  #        #  print "$_ \n";
  #            #}
  #
    if(/timing_type : hold_rising/ || /timing_type : hold_falling/){
        $timing_type_flag=1;
#print "$_ \n";
}
if(/values \( / && ($timing_type_flag=="1")){
$get_value_flag=1; $timing_type_flag=0;
$table_count=0;
#print "$_ \n";
}
    if($get_value_flag==1 && $table_count>0){
        #print "start to get values: $table_count\n";
$_ =~ s/", \\//; $_ =~ s/" \\//; $_ =~ s/"//; $_ =~ s/,//g; #removed unnecessary symbols
@ary=split(" ",$_);
for ($i=0; $i<5; $i++) {
$table_array[(($table_count-1)*5)+$i]=$ary[$i];
}
#print NEW "$_\n";
if($table_count>79){
$table_count=0; $get_value_flag=0; $timing_type_flag=0;
#print NEW @table_array; print NEW "\n";
print NEW "ADD sigma table\n";
for ($j=0; $j<25; $j++) {
$sigma=((($table_array[125+$j]**2)+($table_array[175+$j]**2)+($table_array[225+$j]**2)+($table_array[275+$j]**2)+($table_array[325+$j]**2)+($table_array[375+$j]**2))**0.5);
print NEW "$sigma ";
if((($j+1)%5)=="0"){print NEW "\n";}
}
print NEW "\n";
}
}
}
close(LIB);
close(NEW);

######################################################################

#!/usr/bin/perl                                                                                                                                                                                                    

# input file cell.ldb 
# output add on sigma for mpw

$input_library = $ARGV[0];
$timing_flag=0; $timing_type_flag=0; $get_value_flag=0; $table_count=0;

open(LIB,"<$input_library");
open(NEW, ">mpw_sigma.ldb") || die "Can not open the file : temp.txt \n";

while(<LIB>){
      print NEW "$_";
          chop $_;
              $table_count++;
                  #if(/timing \(\) {/){
                  #    #  $timing_flag=1;
                  #        #  print "$_ \n";
                  #            #}
                  #
    if(/timing_type : min_pulse_width/){
            $timing_type_flag=1;
            #print "$_ \n";
            }
    if(/values \( / && ($timing_type_flag=="1")){
    $get_value_flag=1; $timing_type_flag=0;
    $table_count=0;
    #print "$_ \n";
    }
    if($get_value_flag==1 && $table_count>0){
            #print "start to get values: $table_count\n";
            $_ =~ s/", \\//; $_ =~ s/" \\//; $_ =~ s/"//; $_ =~ s/,//g; #removed unnecessary symbols
            @ary=split(" ",$_);
            #save 5X1 values into a array
            for ($i=0; $i<5; $i++) {
            $table_array[(($table_count-1)*5)+$i]=$ary[$i];
            }
            #print NEW "$_\n";
            if($table_count>15){
            $table_count=0; $get_value_flag=0; $timing_type_flag=0;
            #print NEW @table_array; print NEW "\n";
            print NEW "ADD sigma table\n";
            for ($j=0; $j<5; $j++) {
            $sigma=((($table_array[25+$j]**2)+($table_array[35+$j]**2)+($table_array[45+$j]**2)+($table_array[55+$j]**2)+($table_array[65+$j]**2)+($table_array[75+$j]**2))**0.5);
            print NEW "$sigma ";
            $sigma_plus_nominal[$j]=($sigma*3)+($table_array[15+$j]);
            #if((($j+1)%5)=="0"){print NEW "\n";}
            }
            print NEW "\n";
            print NEW "ADD 3sigma+nominal table\n";
            for ($k=0; $k<5; $k++) {
            print NEW "$sigma_plus_nominal[$k] ";
            }
            print NEW "\n";
        }
    }
}
            
        close(LIB);
        close(NEW);               

2023年8月24日 星期四

AWK

1. 用","當作分隔,取出某一欄位
 cat *.csv | awk -V FS="," '{print $11}'

2. 比較某一欄的值是否大於或小於某個值
使用方法: cat *.txt | awk -f max.awk

BEGIN {
    max = 0.005;
    min = -0.005;
    FS="[,]";
    }
    {
if (FNR > 1) {
    if ($11>max) {
        # print NR;  -->印出行號
        print $0; -->印出該行內容
            }
    if ($11<min) {
        # print NR;
        print $0;
            }
}
}
END {
    printf("max = %f min = %f ", max,min);

3. grep comparison results 
grep -A 2 Pass */*diff.cmp.txt | grep % | awk -F "|" '{print $5}' | xargs



2023年8月11日 星期五

vimdiff


摺疊的命令:
zo : open fold
zc : close fold
zr : reducing folding level
zm : more folding level
zR : reduce completel folding
zM : fold Most

重新計算diff :
:diffupdate or :diffu

同步滾動:
:set scrollbind
:set noscrollbind


2023年6月26日 星期一

Check spike current for CCST waveform

 #! /usr/local/bin/perl 

### input all simulation waveforms then export values which have spike current
### generate a shell script (check_waveform.sh) to plot waveforms in gnuplot for examination

open (AA, "ls analyze_ccs/*/*/*/waveforms/waveform simulation.txt |") or die;
    while (<AA>){
        chomp;
        push @libs, $_;
        }
close AA; 

$out = "check_waveform.sh";
open (BB,">$out") or die;
foreach $lib (@libs){
    open (AA, $lib) or die;
    #print "file: $lib ";
    $i=0; $previous_current=le-8; $present_current=le-8;
    #$dir=`basename $lib`;
    $dir=`dirname $lib`;
    chomp($dir);
    #print "dir path is $dir \n";
    while (<AA>){
        chomp;
        if ($i>"1"){
            @current=split(" ",$_);
            $present_current=$current[1];}
        if ($i=="2"){
            $previous_current=$current[1]; $present_current=$current[1];}
$rel_diff=abs($previous_current/$present_current) ;
#print "Rel diff is $rel_diff , previous is $previous_current , present is $present_current \n";
#export waveform values which have large differences (X10000)
        if ($rel_diff > 10000 || $rel_diff < 0.0001){
            print "file: $lib has spike at line $i, Rel diff is $rel_diff, previous is $previous_current, present is $present_current\n";
            $time_axis=$current[0]+le-10;
            print BB "sed -i '/set datafile missing/i";
            print BB "set xrange [0:$time_axis]";
            print BB "gnuplot $dir/gnuplot.cmd\n";
            print BB "gnuplot $dir/gnuplot.cmd\n";
            }
        $previous_current=$present_current ;
        $i++;
        }
close AA; 
}
close BB;

標籤