CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
extracting a .lib file-2

 



ohgiap
Novice

May 13, 2005, 2:13 AM

Post #1 of 18 (1910 views)
extracting a .lib file-2 Can't Post

hiSly,

here i attach my code that only apply to 1 set of data in .txt file, plz kindly gv opinion n ways to improve it, still my aim is to extract data from .lib file (plz refer mail 1), hopefully some adjustment on this code may help.

thanks.

Giap

open Infile, "data.txt" or die $!;

@data=<Infile>;
$ind1 = (@data[0]);
$ind2 = (@data[1]);
$da1 = (@data[2]);
$da2 = (@data[3]);
$da3 = (@data[4]);
$da4 = (@data[5]);
$da5 = (@data[6]);
$da6 = (@data[7]);
$da7 = (@data[8]);

@in1 = split(/, /, $ind1);
@in2 = split(/, /, $ind2);
@d1 = split(/, /, $da1);
@d2 = split(/, /, $da2);
@d3 = split(/, /, $da3);
@d4 = split(/, /, $da4);
@d5 = split(/, /, $da5);
@d6 = split(/, /, $da6);
@d7 = split(/, /, $da7);

@full_data = (\@d1, \@d2, \@d3, \@d4, \@d5, \@d6, \@d7);

print "\nFor Index 1 to be the class of data, the analysis results are as follow:\n";

$ans1=@in1[6]-@in1[5];
$ans2=@in1[5]-@in1[4];
$ans3=@in1[4]-@in1[3];
$ans4=@in1[3]-@in1[2];
$ans5=@in1[2]-@in1[1];
$ans6=@in1[1]-@in1[0];

for ($i=0;$i<=6;$i++)
{
$a=$i+1;
$der1=($full_data[$i][6]-$full_data[$i][5])/$ans1;
$der2=($full_data[$i][5]-$full_data[$i][4])/$ans2;
$der3=($full_data[$i][4]-$full_data[$i][3])/$ans3;
$der4=($full_data[$i][3]-$full_data[$i][2])/$ans4;
$der5=($full_data[$i][2]-$full_data[$i][1])/$ans5;
$der6=($full_data[$i][1]-$full_data[$i][0])/$ans6;

$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

$count1=0;
$count2=0;
$count3=0;
$count4=0;
$count5=0;
$count6=0;
$count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}

print "*****PLEASE CHECK********\n";
if ($count1==0){
print "";
}
else{
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2==0){
print "";
}
else{
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3==0){
print "";
}
else{
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4==0){
print "";
}
else{
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5==0){
print "";
}
else{
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6==0){
print "";
}
else{
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7==0){
print "";
}
else{
print "Point No.7 has $count7 warning(s)\n";
}
}
}

print "\n\nFor Index 2 to be the class of data, the analysis results are as follow:\n";

$ans1=@in2[6]-@in2[5];
$ans2=@in2[5]-@in2[4];
$ans3=@in2[4]-@in2[3];
$ans4=@in2[3]-@in2[2];
$ans5=@in2[2]-@in2[1];
$ans6=@in2[1]-@in2[0];
$ans6=@in1[1]-@in1[0];
$ans7=@in1[0]-@in1[6];

for ($i=0;$i<=6;$i++)
{
$a=$i+1;
$der1=($full_data[6][$i]-$full_data[5][$i])/$ans1;
$der2=($full_data[5][$i]-$full_data[4][$i])/$ans2;
$der3=($full_data[4][$i]-$full_data[3][$i])/$ans3;
$der4=($full_data[3][$i]-$full_data[2][$i])/$ans4;
$der5=($full_data[2][$i]-$full_data[1][$i])/$ans5;
$der6=($full_data[1][$i]-$full_data[0][$i])/$ans6;

$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

$count1=0;
$count2=0;
$count3=0;
$count4=0;
$count5=0;
$count6=0;
$count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}


print "*****PLEASE CHECK********\n";
if ($count1==0){
print "";
}
else{
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2==0){
print "";
}
else{
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3==0){
print "";
}
else{
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4==0){
print "";
}
else{
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5==0){
print "";
}
else{
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6==0){
print "";
}
else{
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7==0){
print "";
}
else{
print "Point No.7 has $count7 warning(s)\n";
}
}
}

exit;


rork
User

May 14, 2005, 2:02 AM

Post #2 of 18 (1901 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

Well, some improvement must be possible:

Always use strict and warnings.


Code
@data=<Infile>;  
...

@full_data = (\@d1, \@d2, \@d3, \@d4, \@d5, \@d6, \@d7);


It's better to use a while loop, consumes less memory and if you have a file of 1024 lines you don't have to copy the code 1024 times.


Code
my @full_data; 
while(<Infile>) {
chomp @_;
push @full_data, split(/,/, $_);
}



Code
 if ($count6==0){ 
print "";
}
else{
print "Point No.6 has $count6 warning(s)\n";
}


This might be more simple since when $count6 == 0 nothing is done.

Code
if ($count6 != 0) { print ... };

--
Don't reinvent the wheel, use it, abuse it or hack it.


ohgiap
Novice

May 16, 2005, 1:23 AM

Post #3 of 18 (1882 views)
Re: [rork] extracting a .lib file-2 [In reply to] Can't Post

hi, thanx for ur guidance, i had tried my best to adjust my script. anyway, i dun hv any idea still about extracting the .lib file. would u plz intro any link if possible that have sample script something same as my project that is extracting certain information from a .lib file. besides, i fail to change my part of my script to be in while loop coz it make me cun run it. i feelBlush coz i think it's a really Q for u, anyway, i do hope u can gv me more guidelines. thanx a lot.

here i attached my .lib for u to hv a look. tq. my latest script is as below:

use warnings;
use strict;

open Infile, "data.txt" or die $!;

our @data;
@data=<Infile>;

our ($ind1, $ind2);
$ind1 = ($data[0]);
$ind2 = ($data[1]);

our ($da1, $da2, $da3, $da4, $da5, $da6, $da7);
$da1 = ($data[2]);
$da2 = ($data[3]);
$da3 = ($data[4]);
$da4 = ($data[5]);
$da5 = ($data[6]);
$da6 = ($data[7]);
$da7 = ($data[8]);

our (@in1, @in2);
@in1 = split(/, /, $ind1);
@in2 = split(/, /, $ind2);

our (@d1, @d2, @d3, @d4, @d5, @d6, @d7);
@d1 = split(/, /, $da1);
@d2 = split(/, /, $da2);
@d3 = split(/, /, $da3);
@d4 = split(/, /, $da4);
@d5 = split(/, /, $da5);
@d6 = split(/, /, $da6);
@d7 = split(/, /, $da7);

our @full_data;
@full_data = (\@d1, \@d2, \@d3, \@d4, \@d5, \@d6, \@d7);

print "\nFor Index 1 to be the class of data, the analysis results are as follow:\n";

our ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);
my ($in1);
$ans1=$in1[6]-$in1[5];
$ans2=$in1[5]-$in1[4];
$ans3=$in1[4]-$in1[3];
$ans4=$in1[3]-$in1[2];
$ans5=$in1[2]-$in1[1];
$ans6=$in1[1]-$in1[0];

our ($der1, $der2, $der3, $der4, $der5, $der6);
my $i;
for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[$i][6]-$full_data[$i][5])/$ans1;
$der2=($full_data[$i][5]-$full_data[$i][4])/$ans2;
$der3=($full_data[$i][4]-$full_data[$i][3])/$ans3;
$der4=($full_data[$i][3]-$full_data[$i][2])/$ans4;
$der5=($full_data[$i][2]-$full_data[$i][1])/$ans5;
$der6=($full_data[$i][1]-$full_data[$i][0])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}

print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

print "\n\nFor Index 2 to be the class of data, the analysis results are as follow:\n";
local ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);
my ($in2);
$ans1=$in2[6]-$in2[5];
$ans2=$in2[5]-$in2[4];
$ans3=$in2[4]-$in2[3];
$ans4=$in2[3]-$in2[2];
$ans5=$in2[2]-$in2[1];
$ans6=$in2[1]-$in2[0];
$ans6=$in1[1]-$in1[0];
local ($der1, $der2, $der3, $der4, $der5, $der6);

for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[6][$i]-$full_data[5][$i])/$ans1;
$der2=($full_data[5][$i]-$full_data[4][$i])/$ans2;
$der3=($full_data[4][$i]-$full_data[3][$i])/$ans3;
$der4=($full_data[3][$i]-$full_data[2][$i])/$ans4;
$der5=($full_data[2][$i]-$full_data[1][$i])/$ans5;
$der6=($full_data[1][$i]-$full_data[0][$i])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}


print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

exit;


feel so greatful that u could help me solving the prob.

best wishes.

best regards,

Giap
Attachments: grill_nom.lib (232 KB)


rork
User

May 16, 2005, 2:46 AM

Post #4 of 18 (1878 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

The way you handle it is ok. The while loop is mainly for fine tuning and making the script compatible with .lib files with more lines.

Don't feal Blush about the while loop, I do.
I made a big mistake with the push function: It adds the data directly to the end of the array instead of an array ref.

Let's stick to your script now and solve some problems.

Scince you split 'index_1 ("0.00100, 0.02000, 0.06100, 0.14200, 0.29700, 0.61500, 1.30000");' the first and last values of the array are 'index_1 ("0.00100' and '1.30000");' prevent this by using a regexp before splitting.


Code
 $ind1 =~ s/index_\d\s\("//; 
$ind1 =~ s/"\)//;


Explanation about the RegExp:
s/1/2/ = substitute (replace 1 by 2)

\d = any diget
\s = white space
\( and \) = ( and ) since these characters have a function in the regexp use \ to escape it.

Do the same for the other lines.

More info about RegExp and metacharacters can be found in perlreref

my ($in1); Why is this, it doesn't seem to do anything.
--
Don't reinvent the wheel, use it, abuse it or hack it.


ohgiap
Novice

May 16, 2005, 9:24 PM

Post #5 of 18 (1876 views)
Re: [rork] extracting a .lib file-2 [In reply to] Can't Post

hi, thanx again. i follow ur step n finally OK for both index. anyway, i face some prob in data.

For the 1st data, code:

$da1=~s/values \("//;
$da1=~s/\\//;
@d1=split(/,/, $da1);
print "@d1\n";

wat i get is:1.66970 1.75890 2.33820 3.36560 4.84910 6.83140 9.33340"

For the center data, code:

$da2=~s/ \"//;
$da2=~s/"\\//;
@d2=split(/,/, $da2);

wat i get is :1.67410 1.76100 2.34130 3.36860 4.88890 6.83710 9.34650"

i try to eliminate the " but fail could u plz help me?

but the final data i think is ok

the code


$da7=~s/ \"//;
$da7=~s/"\);//;
@d7=split(/,/, $da7);
print "@d7\n";

wat i get is 1.75470 1.84320 2.42220 3.45040 4.93280 6.91000 9.43100

thanx again.

GIap


ohgiap
Novice

May 16, 2005, 11:58 PM

Post #6 of 18 (1874 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

Hi, after trying and trying. I manage to solve above problem that jz sent.Wink

Now i change my file to AGLMII_IOST_NOM.lib which is my source file, ShockedaiyaCrazyanother problem arises, that i actually realize previously (which also my main problem). My question is "How the program noe where to 'go' in my source file that has a lot of information???", as i want only 16 tables of information look like below (1 example) are applied to my program.

cell_fall (delay_template7x7) {
index_1 ("0.00100, 0.02000, 0.06100, 0.14200, 0.29700, 0.61500, 1.30000");
index_2 ("0.00100, 0.00500, 0.01000, 0.20000, 0.30000, 0.40000, 0.50000");
values ("0.47560, 0.47900, 0.48330, 0.58120, 0.61720, 0.66400, 0.69980", \
"0.52260, 0.52450, 0.52520, 0.58590, 0.63290, 0.66430, 0.69390", \
"0.52380, 0.52380, 0.52480, 0.58520, 0.62570, 0.65460, 0.69470", \
"0.51310, 0.50850, 0.50970, 0.59350, 0.62360, 0.65600, 0.69290", \
"0.50350, 0.50580, 0.50970, 0.60540, 0.65560, 0.68450, 0.72840", \
"0.57470, 0.57600, 0.57840, 0.63040, 0.66510, 0.70150, 0.74650", \
"0.63650, 0.63780, 0.63960, 0.71980, 0.75910, 0.79350, 0.83300");
}

here i attach my sourcefile to u to have a look. i really wish to settle this program as soon as possible. if u dun hv much time to help me figure out, would u plz show me some alike example that also extract certain information from a .lib file, where i can modify from it. i really appreciate wat u hv suggested to me.

From ur opinion, izit still a long way to complete my task 100% which my script will extract and differentiate(coz they are 16 tables in the sourcefile) desired information from my source file and perform the prog successfully?

is LABEL useful here?i m still thinking!!!

THANXXX!!

Best wishes!!

Best regards,

GiapSmile
p/s: my latest script is as below:

use warnings;
use strict;

open Infile, "AGLMII_IOST_NOM.lib" or die $!;

our @data;
@data=<Infile>;

our ($ind1, $ind2);
$ind1 = ($data[0]);
$ind2 = ($data[1]);

our ($da1, $da2, $da3, $da4, $da5, $da6, $da7);
$da1 = ($data[2]);
$da2 = ($data[3]);
$da3 = ($data[4]);
$da4 = ($data[5]);
$da5 = ($data[6]);
$da6 = ($data[7]);
$da7 = ($data[8]);

our (@in1, @in2);
$ind1=~s/index_\d\s\("//;
$ind1=~s/"\);//;
@in1 = split(/,/, $ind1);
$ind2=~s/index_\d\s\("//;
$ind2=~s/"\);//;
@in2 = split(/,/, $ind2);

our (@d1, @d2, @d3, @d4, @d5, @d6, @d7);
$da1=~s/values \("//;
$da1=~s/"\W\\//;
@d1=split(/,/, $da1);
$da2=~s/ \"//;
$da2=~s/"\W\\//;
@d2=split(/,/, $da2);
$da3=~s/ \"//;
$da3=~s/"\W\\//;
@d3=split(/,/, $da3);
$da4=~s/ \"//;
$da4=~s/"\W\\//;
@d4=split(/,/, $da4);
$da5=~s/ \"//;
$da5=~s/"\W\\//;
@d5=split(/,/, $da5);
$da6=~s/ \"//;
$da6=~s/"\W\\//;
@d6=split(/,/, $da6);
$da7=~s/ \"//;
$da7=~s/"\);//;
@d7=split(/,/, $da7);

our @full_data;
@full_data = (\@d1, \@d2, \@d3, \@d4, \@d5, \@d6, \@d7);

print "\nFor Index 1 to be the class of data, the analysis results are as follow:\n";
our ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);
$ans1=$in1[6]-$in1[5];
$ans2=$in1[5]-$in1[4];
$ans3=$in1[4]-$in1[3];
$ans4=$in1[3]-$in1[2];
$ans5=$in1[2]-$in1[1];
$ans6=$in1[1]-$in1[0];

our ($der1, $der2, $der3, $der4, $der5, $der6);
my $i;
for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[$i][6]-$full_data[$i][5])/$ans1;
$der2=($full_data[$i][5]-$full_data[$i][4])/$ans2;
$der3=($full_data[$i][4]-$full_data[$i][3])/$ans3;
$der4=($full_data[$i][3]-$full_data[$i][2])/$ans4;
$der5=($full_data[$i][2]-$full_data[$i][1])/$ans5;
$der6=($full_data[$i][1]-$full_data[$i][0])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}

print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

print "\n\nFor Index 2 to be the class of data, the analysis results are as follow:\n";
local ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);

$ans1=$in2[6]-$in2[5];
$ans2=$in2[5]-$in2[4];
$ans3=$in2[4]-$in2[3];
$ans4=$in2[3]-$in2[2];
$ans5=$in2[2]-$in2[1];
$ans6=$in2[1]-$in2[0];
$ans6=$in1[1]-$in1[0];

local ($der1, $der2, $der3, $der4, $der5, $der6);
for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[6][$i]-$full_data[5][$i])/$ans1;
$der2=($full_data[5][$i]-$full_data[4][$i])/$ans2;
$der3=($full_data[4][$i]-$full_data[3][$i])/$ans3;
$der4=($full_data[3][$i]-$full_data[2][$i])/$ans4;
$der5=($full_data[2][$i]-$full_data[1][$i])/$ans5;
$der6=($full_data[1][$i]-$full_data[0][$i])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}


print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

exit;
Attachments: AGLMII_IOST_NOM.lib (14.4 KB)


KevinR
Veteran


May 17, 2005, 12:56 AM

Post #7 of 18 (1870 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

Have you gotten your program to produce any output at all? I tried running your script using your data file and the script does nothing but go into a seemingly endless loop.
-------------------------------------------------


ohgiap
Novice

May 17, 2005, 1:06 AM

Post #8 of 18 (1869 views)
Re: [KevinR] extracting a .lib file-2 [In reply to] Can't Post

hi,

Yup, my program only run in this condition:

sourcefile as attached, data3.txt

script as below (that i only change the source file name only compared script i sent jz now)

use warnings;
use strict;

open Infile, "data3.txt" or die $!;

our @data;
@data=<Infile>;

our ($ind1, $ind2);
$ind1 = ($data[0]);
$ind2 = ($data[1]);

our ($da1, $da2, $da3, $da4, $da5, $da6, $da7);
$da1 = ($data[2]);
$da2 = ($data[3]);
$da3 = ($data[4]);
$da4 = ($data[5]);
$da5 = ($data[6]);
$da6 = ($data[7]);
$da7 = ($data[8]);

our (@in1, @in2);
$ind1=~s/index_\d\s\("//;
$ind1=~s/"\);//;
@in1 = split(/,/, $ind1);
$ind2=~s/index_\d\s\("//;
$ind2=~s/"\);//;
@in2 = split(/,/, $ind2);

our (@d1, @d2, @d3, @d4, @d5, @d6, @d7);
$da1=~s/values \("//;
$da1=~s/"\W\\//;
@d1=split(/,/, $da1);
$da2=~s/ \"//;
$da2=~s/"\W\\//;
@d2=split(/,/, $da2);
$da3=~s/ \"//;
$da3=~s/"\W\\//;
@d3=split(/,/, $da3);
$da4=~s/ \"//;
$da4=~s/"\W\\//;
@d4=split(/,/, $da4);
$da5=~s/ \"//;
$da5=~s/"\W\\//;
@d5=split(/,/, $da5);
$da6=~s/ \"//;
$da6=~s/"\W\\//;
@d6=split(/,/, $da6);
$da7=~s/ \"//;
$da7=~s/"\);//;
@d7=split(/,/, $da7);

our @full_data;
@full_data = (\@d1, \@d2, \@d3, \@d4, \@d5, \@d6, \@d7);

print "\nFor Index 1 to be the class of data, the analysis results are as follow:\n";
our ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);
$ans1=$in1[6]-$in1[5];
$ans2=$in1[5]-$in1[4];
$ans3=$in1[4]-$in1[3];
$ans4=$in1[3]-$in1[2];
$ans5=$in1[2]-$in1[1];
$ans6=$in1[1]-$in1[0];

our ($der1, $der2, $der3, $der4, $der5, $der6);
my $i;
for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[$i][6]-$full_data[$i][5])/$ans1;
$der2=($full_data[$i][5]-$full_data[$i][4])/$ans2;
$der3=($full_data[$i][4]-$full_data[$i][3])/$ans3;
$der4=($full_data[$i][3]-$full_data[$i][2])/$ans4;
$der5=($full_data[$i][2]-$full_data[$i][1])/$ans5;
$der6=($full_data[$i][1]-$full_data[$i][0])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}

print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

print "\n\nFor Index 2 to be the class of data, the analysis results are as follow:\n";
local ($ans1, $ans2, $ans3, $ans4, $ans5, $ans6);

$ans1=$in2[6]-$in2[5];
$ans2=$in2[5]-$in2[4];
$ans3=$in2[4]-$in2[3];
$ans4=$in2[3]-$in2[2];
$ans5=$in2[2]-$in2[1];
$ans6=$in2[1]-$in2[0];
$ans6=$in1[1]-$in1[0];

local ($der1, $der2, $der3, $der4, $der5, $der6);
for ($i=0;$i<=6;$i++)
{
my $a=$i+1;

$der1=($full_data[6][$i]-$full_data[5][$i])/$ans1;
$der2=($full_data[5][$i]-$full_data[4][$i])/$ans2;
$der3=($full_data[4][$i]-$full_data[3][$i])/$ans3;
$der4=($full_data[3][$i]-$full_data[2][$i])/$ans4;
$der5=($full_data[2][$i]-$full_data[1][$i])/$ans5;
$der6=($full_data[1][$i]-$full_data[0][$i])/$ans6;

our ($rel1, $rel2, $rel3, $rel4, $rel5);
$rel1= ($der1-$der2)*100;
$rel2= ($der2-$der3)*100;
$rel3= ($der3-$der4)*100;
$rel4= ($der4-$der5)*100;
$rel5= ($der5-$der6)*100;

if ($rel1<=10 && $rel1>=-10 && $rel2<=10 && $rel2>=-10 && $rel3<=10 && $rel3>=-10 && $rel4<=10 && $rel4>=-10 &&

$rel5<=10 && $rel5>=-10)
{
print "\nDATA SET NO.$a IS OK!!!\n";

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n\n\n", $rel5;
}
else
{
print "\n\nDATA SET NO.$a IS UNDESIRABLE!!!\n";

my $count1=0;
my $count2=0;
my $count3=0;
my $count4=0;
my $count5=0;
my $count6=0;
my $count7=0;

printf "Relative error of slope point No.7 & 6 VS slope point No.6 & 5 is %5.4f\n", $rel1;
printf "Relative error of slope point No.6 & 5 VS slope point No.5 & 4 is %5.4f\n", $rel2;
printf "Relative error of slope point No.5 & 4 VS slope point No.4 & 3 is %5.4f\n", $rel3;
printf "Relative error of slope point No.4 & 3 VS slope point No.3 & 2 is %5.4f\n", $rel4;
printf "Relative error of slope point No.3 & 2 VS slope point No.2 & 1 is %5.4f\n", $rel5;

if ($rel5>=10 || $rel5<=-10)
{
if ($der6<$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count1++;
}
elsif ($der6<$der5 && $der6*$der5<0)
{
$count1++;
}
elsif ($der6*$der5<0)
{
$count2++;
}
elsif ($der6>$der5 && $der6*$der5>0)
{
$count3++;
}
}
if ($rel4>=10 || $rel4<=-10)
{
if ($der5<$der4 && $der5*$der4>0)
{
$count2++;
}
elsif ($der5*$der4<0)
{
$count3++;
}
elsif ($der5>$der4 && $der5*$der4>0)
{
$count4++;
}
}
if ($rel3>=10 || $rel3<=-10)
{
if ($der4<$der3 && $der4*$der3>0)
{
$count3++;
}
elsif ($der4*$der3<0)
{
$count4++;
}
elsif ($der4>$der3 && $der4*$der3>0)
{
$count5++;
}
}
if ($rel2>=10 || $rel2<=-10)
{
if ($der3<$der2 && $der3*$der2>0)
{
$count4++;
}
elsif ($der3*$der2<0)
{
$count5++;
}
elsif ($der3>$der2 && $der3*$der2>0)
{
$count6++;
}
}
if ($rel1>=10 || $rel1<=-10)
{
if ($der2<$der1 && $der2*$der1>0)
{
$count5++;
}
elsif ($der2*$der1<0)
{
$count6++;
}
elsif ($der2>$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2<$der1 && $der2*$der1>0)
{
$count7++;
}
elsif ($der2>$der1 && $der2*$der1<0)
{
$count7++
}
}


print "*****PLEASE CHECK********\n";
if ($count1!=0){
print "Point No.1 has $count1 warning(s)\n";
}
if ($count2!=0){
print "Point No.2 has $count2 warning(s)\n";
}
if ($count3!=0){
print "Point No.3 has $count3 warning(s)\n";
}
if ($count4!=0){
print "Point No.4 has $count4 warning(s)\n";
}
if ($count5!=0){
print "Point No.5 has $count5 warning(s)\n";
}
if ($count6!=0){
print "Point No.6 has $count6 warning(s)\n";
}
if ($count7!=0){
print "Point No.7 has $count7 warning(s)\n";
}
}
}

exit;




i still yet hv an idea to extract file from a .lib file so i try with .txt file 1st. when my source file is .lib file, everything go to a mess...Frown

Thanx

Best regards,

Giap
Attachments: data3.txt (0.67 KB)


davorg
Thaumaturge / Moderator

May 17, 2005, 2:35 AM

Post #9 of 18 (1866 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

Having looked at your .lib file, it looks to me that the best way to extract the data from it would be using some kind of grammar-based parser algorithm. I'd recommend taking a look at the Parse::RecDescent Perl module on CPAN.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


KevinR
Veteran


May 17, 2005, 3:17 AM

Post #10 of 18 (1863 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

not to confuse the issue after dave's post, but if you can't get that to work, this seems to work OK for creating a data set that could then be fed into the rest of your routines.


Code
#!perl 
use strict;
use warnings;
use Data::Dump qw(dump);
open Infile, "AGLMII_IOST_NOM.lib" or die $!;
my @data=<Infile>;
close(Infile);

my @AofH = ();
my ($i,$n,$f) = (0,0,0);
for (@data) {
chomp;
$AofH[$i]{'index_1'} = [strip($_)] if (/index_1/);
$AofH[$i]{'index_2'} = [strip($_)] if (/index_2/);
($n,$f)=(1,1) if (/values/);
push @{$AofH[$i]{'values'}},[strip($_)] if ($f == 1);
($f=0) if (/;/);
($i++,$n=0) if ($n == 1 && $f == 0);
}

sub strip {
local $_ = shift;
s/index_\d//;
tr/,0-9.//cd;
return(split(/,/));
}
print dump(@AofH);


the above makes an array of hashes out of the lib file. You would then loop through the array (@AofH) to get the rest of your output. It might be better to store the data as references instead of annonymous arrays if there is a lot of data.

Note that:

use Data::Dump qw(dump);

and

print dump(@AofH);

are just to test to see if the script is producing the correct data, they are not needed to run the script to do what you want. Data::Dump is a very good tool to use when creating complex data records.
-------------------------------------------------


(This post was edited by KevinR on May 17, 2005, 2:05 PM)


ohgiap
Novice

May 20, 2005, 2:20 AM

Post #11 of 18 (1837 views)
Re: [KevinR] extracting a .lib file-2 [In reply to] Can't Post

thanx kevin, u really help me a lot!!

lastly about this project, if i wish to display certain information at the begining of each table, wat the script like? my example to be displayed in the 1st analysis result of 1st table is

timing_type : "three_state_enable";
timing_sense : "negative_unate";
cell_rise (delay_template7x7)

it's as wat display in the sourcefile.

anyway, different table (16 set of data in the source file) hv differnt pharse to be display..could u help me, anyway, i will try also....

Best Regards,

giap


KevinR
Veteran


May 20, 2005, 12:18 PM

Post #12 of 18 (1835 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

I assume that the table information is the first three lines after cell (AGLMII_IOST)


Code
cell (AGLMII_IOST) { 
...
...
...
timing_type : "three_state_enable"
timing_sense : "negative_unate"
cell_rise (delay_template7x7)
...
...


if there is more than one cell of 16 sets of tables then the flag ($h) would have to be reset. Here is one possible way:


Code
#!perl 
use strict;
use warnings;
use Data::Dump qw(dump);

open Infile, "C:/WINDOWS/Desktop/AGLMII_IOST_NOM.txt" or die $!;
#open Infile, "AGLMII_IOST_NOM.lib" or die $!;
my @data=<Infile>;
close(Infile);

my @AofH = ();
my ($i,$n,$f,$h) = (0,0,0,0);
for (@data) {
chomp;
($h++,$AofH[$i]{'timing_type'} = [strip_heading($_)]) if (index($_,'timing_type')>-1 && $h<3);
($h++,$AofH[$i]{'timing_sense'} = [strip_heading($_)]) if (index($_,'timing_sense')>-1 && $h<3);
($h++,$AofH[$i]{'cell_rise'} = [strip_heading($_)]) if (index($_,'cell_rise')>-1 && $h<3);
$AofH[$i]{'index_1'} = [strip($_)] if (/index_1/);
$AofH[$i]{'index_2'} = [strip($_)] if (/index_2/);
($n,$f)=(1,1) if (/values/);
push @{$AofH[$i]{'values'}},[strip($_)] if ($f == 1);
($f=0) if (/;/);
($i++,$n=0) if ($n == 1 && $f == 0);
}

sub strip {
local $_ = shift;
s/index_\d//;
tr/,0-9.//cd;
return(split(/,/));
}
sub strip_heading {
local $_ = shift;
tr/;{"//d;
s/^\s+//;
s/\s+$//;
s/\s+/ /g;
return($_);
}
print dump(@AofH);

-------------------------------------------------


(This post was edited by KevinR on May 22, 2005, 10:49 PM)


ohgiap
Novice

May 23, 2005, 8:04 PM

Post #13 of 18 (1828 views)
Re: [KevinR] extracting a .lib file-2 [In reply to] Can't Post

hi Kevin,

by today, i think i can settle my project.Thanks so much, u did help me a lot!!

Best regards,

Giap


KevinR
Veteran


May 23, 2005, 8:13 PM

Post #14 of 18 (1827 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

You're welcome.
-------------------------------------------------


ohgiap
Novice

May 25, 2005, 1:48 AM

Post #15 of 18 (1823 views)
Re: [KevinR] extracting a .lib file-2 [In reply to] Can't Post

hi Kevin, sorry to interupt u again, i wish to display certain information in my output as attachment1. but i think it's not practical enough as u may refer to my source code regression.pl as attached. So, i have write a script individually 1st to display the information i want then i will apply it in my script then.

another Source code:

for ($i=0; $i<=15; $i++){

%name=(
type=>[cell_fall, fall_transition, cell_fall, fall_transition],
sense=>[positive, negative],
pin=>[OE_N, DATA_OUT, SIGNAME] );

for($i=0; $i<=7; $i++){
$pin=$name{pin}[0];

for ($i=0; $i<=3; $i++){
$sense=$name{sense}[1];}
for ($i=4; $i<=7; $i++){
$sense=$name{sense}[0];}

for ($i==0 || $i==4){
$type=$name{type}[0];}
for ($i==1 || $i==5){
$type=$name{type}[1];}
for ($i==2 || $i==6){
$type=$name{type}[2];}
for ($i==3 || $i==7){
$type=$name{type}[3];}}

for($i=8; $i<=11; $i++){
$pin=$name{pin}[1];
$sense=$name{sense}[0];

for ($i==8){
$type=$name{type}[0];}
for ($i==9){
$type=$name{type}[1];}
for ($i==10){
$type=$name{type}[2];}
for ($i==11){
$type=$name{type}[3];}}

for($i=12; $i<=15; $i++){
$pin=$name{pin}[2];
$sense=$name{sense}[0];

if ($i==12){
$type=$name{type}[0];}
elsif ($i==13){
$type=$name{type}[1];}
elsif ($i==14){
$type=$name{type}[2];}
elsif ($i==15){
$type=$name{type}[3];}}

print "$i is $pin and $sense and $type\n";
}

the output is only printing the last line information.

Wat i desire is

0 is OE_N and negative and cell rise

1 is OE_N and negative and rise transition

2 is OE_N and negative and cell fall

.

.

.

14 is SIGNAME and positive and cell fall

15 is SIGNAME and positive and fall transition



anything wrong about my source code?

then, i run my program in window is ok, but when i run in UNIX, i get

"Can't locate Data/Dump.pm in @INC (@INC contains: /opt/perl/lib/5.6.1/PA-RISC1.1-thread-multi /opt/perl/lib/5.6.1 /opt/perl/lib/site_perl/5.6.1/PA-RISC1.1-thread-multi /opt/perl/lib/site_perl/5.6.1 /opt/perl/lib/site_perl .)"

what i should do about it?Thanx alot!!

takegoodcare!!

Best regards,

Giap

p/s: my completed script is regression.pl. plz kindly give me ur opinion and suggestion, my presentation has postphoned to this friday, so i wish my script still can be improved...my desired output is obtained but i dun think my script is flexible enough....Wink
Attachments: attachment1.bmp (120 KB)
  regression.pl (18.8 KB)


KevinR
Veteran


May 25, 2005, 12:34 PM

Post #16 of 18 (1817 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

Sorry but I do not understand what you are wanting to do with the display. I ran the script regression.pl and the output seems like what it is in the image you attached.

As far as the error "Can't locate Data/Dump.pm in @INC" I guess your Unix server doesn't have the module inbstalled, but it's not a problem. Just comment out the line:

use Data::Dump qw(dump);

as I said before it's not needed to run the script, it's only there for test/debugging purposes.
-------------------------------------------------


ohgiap
Novice

May 25, 2005, 5:52 PM

Post #17 of 18 (1816 views)
Re: [KevinR] extracting a .lib file-2 [In reply to] Can't Post

Hi Kevin, sorry for asking too much in a single mail untill confuse u.

1. The display of my output is wat i desired, but the script wriiten to display it i think is not flexible enough coz it's wat i preset in the result loop. So, i wish to improve it by calling these information ($type, $sense & $pin) in an individual loop.

2. So, i'd written separately a script just to display the name and wat i c in the ouput is only 1 line output showing last result only. So, may i seek your opinion anything wrong about my script as below:

for ($i=0; $i<=15; $i++){

%name=(
type=>[cell_fall, fall_transition, cell_fall, fall_transition],
sense=>[positive, negative],
pin=>[OE_N, DATA_OUT, SIGNAME] );

for($i=0; $i<=7; $i++){
$pin=$name{pin}[0];

for ($i=0; $i<=3; $i++){
$sense=$name{sense}[1];}
for ($i=4; $i<=7; $i++){
$sense=$name{sense}[0];}

for ($i==0 || $i==4){
$type=$name{type}[0];}
for ($i==1 || $i==5){
$type=$name{type}[1];}
for ($i==2 || $i==6){
$type=$name{type}[2];}
for ($i==3 || $i==7){
$type=$name{type}[3];}}

for($i=8; $i<=11; $i++){
$pin=$name{pin}[1];
$sense=$name{sense}[0];

for ($i==8){
$type=$name{type}[0];}
for ($i==9){
$type=$name{type}[1];}
for ($i==10){
$type=$name{type}[2];}
for ($i==11){
$type=$name{type}[3];}}

for($i=12; $i<=15; $i++){
$pin=$name{pin}[2];
$sense=$name{sense}[0];

if ($i==12){
$type=$name{type}[0];}
elsif ($i==13){
$type=$name{type}[1];}
elsif ($i==14){
$type=$name{type}[2];}
elsif ($i==15){
$type=$name{type}[3];}}

print "$i is $pin and $sense and $type\n";
}



3. MY desired output display is

0 is OE_N and negative and cell rise

1 is OE_N and negative and rise transition

2 is OE_N and negative and cell fall

.

.

.

14 is SIGNAME and positive and cell fall

15 is SIGNAME and positive and fall transition


Thanx so much!!Smile

Best Regards,

Giap


KevinR
Veteran


May 25, 2005, 10:59 PM

Post #18 of 18 (1814 views)
Re: [ohgiap] extracting a .lib file-2 [In reply to] Can't Post

OK, I see what you are trying to do with that short script. It's only printing the last line because you are not printing the lines after each loop, and instead only printing the line that the very last loop creates. You could that with just one "for" loop, like this


Code
my %name=( 
type=>['cell_fall', 'fall_transition', 'cell_fall', 'fall_transition'],
sense=>['positive', 'negative'],
pin=>['OE_N', 'DATA_OUT', 'SIGNAME']
);

my($pin,$sense,$type);

for my $i (0 .. 15){
if ($i <= 7) {
$pin=$name{pin}[0];
if ($i <= 3){
$sense=$name{sense}[1];
if ($i==0 || $i==4){
$type=$name{type}[0];
}
elsif ($i==1 || $i==5){
$type=$name{type}[1];
}
elsif ($i==2 || $i==6){
$type=$name{type}[2];
}
elsif ($i==3 || $i==7){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
elsif ($i > 3 && $i <= 7){
$sense=$name{sense}[0];
if ($i==0 || $i==4){
$type=$name{type}[0];
}
elsif ($i==1 || $i==5){
$type=$name{type}[1];
}
elsif ($i==2 || $i==6){
$type=$name{type}[2];
}
elsif ($i==3 || $i==7){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
}
elsif ($i > 7 && $i <= 11){
$pin=$name{pin}[1];
$sense=$name{sense}[0];
if ($i==8){
$type=$name{type}[0];
}
elsif ($i==9){
$type=$name{type}[1];
}
elsif ($i==10){
$type=$name{type}[2];
}
elsif ($i==11){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
else {
$pin=$name{pin}[2];
$sense=$name{sense}[0];
if ($i==12){
$type=$name{type}[0];
}
elsif ($i==13){
$type=$name{type}[1];
}
elsif ($i==14){
$type=$name{type}[2];
}
elsif ($i==15){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
}


which outputs:


Code
0 is OE_N and negative and cell_fall 
1 is OE_N and negative and fall_transition
2 is OE_N and negative and cell_fall
3 is OE_N and negative and fall_transition
4 is OE_N and positive and cell_fall
5 is OE_N and positive and fall_transition
6 is OE_N and positive and cell_fall
7 is OE_N and positive and fall_transition
8 is DATA_OUT and positive and cell_fall
9 is DATA_OUT and positive and fall_transition
10 is DATA_OUT and positive and cell_fall
11 is DATA_OUT and positive and fall_transition
12 is SIGNAME and positive and cell_fall
13 is SIGNAME and positive and fall_transition
14 is SIGNAME and positive and cell_fall
15 is SIGNAME and positive and fall_transition


Note that the elements in the arrays have to be quoted:


type=>['cell_fall', 'fall_transition', 'cell_fall', 'fall_transition'],
sense=>['positive', 'negative'],
pin=>[qw(OE_N DATA_OUT SIGNAME)]

like any array you must use quotes around alpha (words) elements.
-------------------------------------------------


(This post was edited by KevinR on May 25, 2005, 11:00 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives