#!/usr/bin/perl
use Term::ANSIColor;
my $input_library = $ARGV[0];
# $index --> 29 dc_current
$dc_current_flag=0; $index=0; $line=0; $increase=0; $decrease=0;
open(LIB,"<input_library");
while(<LIB>){
$line++;
if ($dc_current_flag=="4") {
$original=$_; $increase=0; $decrease=0;
$_ =~ s/"//g; $_ =~ s/,//g; $_ =~ s/\\//g;
@aryl=split(" ",$_); $array_size = $#ary1+1;
for ($i=0; $i<$array_size-1;$i++) {
if ($aryl[$i] > $aryl[$i+1]) {$increase=1;} # detect increment
if ($aryl[$i] < $aryl[$i+1]) {$decrease=1;} # detect decrement
}
if ($increase=="1" && $decrease=="1") {
## Values are non-monotonic when increment and decrement in same line
print "LINE $line is non-monotonic, the VALUE is \n";
for ($i=0; $i<$array_size-1; $i++) {
if ($ary1[$i] > $ary1[$i+1]) {print color("blue")."$ary1[$i] ";} # detect increment
if ($ary1[$i] < $ary1[$i+1]) {print color("red")."$ary1[$i] ";} # detect decrement
}
print "\n"; print color ('reset');
#print "$original";
}
++$index;
if ($index=="29") {$dc_current_flag=0; $index=0;}
}
if (/dc_current \(/) {$dc_current_flag=1;}
if ($dc_current_flag>0) { if (/index_1 \(/) {$dc_current_flag=2;}}
if ($dc_current_flag>0) { if (/index_2 \(/) {$dc_current_flag=3;}}
if ($dc_current_flag>0) { if (/values \(/) {$dc_current_flag=4;}}
}
close (LIB);