http://qs321.pair.com?node_id=11105244


in reply to Comparing values from two different files and flag error

anirbanphys:

Sorry, but this is turning out to be a longish post. Anyway, I've read your post, but don't know exactly what you're having trouble with. It's nice to see that you've provided some sample data and some code, but you didn't make it easy enough for (most) people to try to help. I happened to be in the right mood to slog through it, so you at least get a response from me, if no others. The easier you make it for people to try your code, the more likely it is that people will give it a go and respond. As it is, you have to slog through all the code to figure out how to build the file directory, and how to figure out what parameters to call it with. I'm not certain I guessed at everything correctly, but here goes!


OK, when I tried running your code with "perl -c pm_11105228.pl", it had a couple complaints:

$ perl -c pm_11105228.pl Unrecognized escape \v passed through at pm_11105228.pl line 47. Unrecognized escape \v passed through at pm_11105228.pl line 72. Scalar value @vol_temp[1] better written as $vol_temp[1] at pm_1110522 +8.pl line 38. Scalar value @vol_temp[0] better written as $vol_temp[0] at pm_1110522 +8.pl line 39. Scalar value @vol_temp[0] better written as $vol_temp[0] at pm_1110522 +8.pl line 41. Scalar value @vol_temp[0] better written as $vol_temp[0] at pm_1110522 +8.pl line 42. pm_11105228.pl syntax OK

Lines 47 and 72 have the same issue. Looking at line 47, we get:

my $file_name2 = "$in_macro/lib_pg/$in_macro\_$process_two$volt_1\v$te +mp\_pg.lib";

The problem is that you're using backslashes ('\') instead of forward slashes ('/') in your filename, so I just changed it to:

my $file_name2 = "$in_macro/lib_pg/$in_macro/_$process_two$volt_1/v$te +mp/_pg.lib";

I also made a similar fix to line 72. Perl generally "just works" if you use forward slashes to delimit the parts of path names. If you wanted to use backslashes, then you'd need to be sure you escaped your backslashes properly, which is a nuisance I avoid entirely by using forward slashes exclusively.

For the warnings on lines 38 through 42, it's telling you what to do to fix the problem, so I made those changes, too.

Since you don't use strict and warnings in your program, I was expecting more issues to crop up when I added them. However, I was pleasantly surprised to see that other than the issues listed, everything was fine. I left in strict and warnings, though, as it's an easy way to prevent errors.

Your directory structure and file naming was a bit much for me to try to reproduce, so I just made a subdirectory lib_pg and dumped your sample files in there. Then, to make it so that the code would find the files, I changed lines 46 and 47 to:

my $file_name1 = "lib_pg/$in_macro"; my $file_name2 = "lib_pg/$in_macro";

At this point, the code ran, discovered the files and printed some stuff. But I don't know if I structured everything correctly or not--this is where you could've done a little more work to make it easy on us. Anyway, it printed some stuff. However, I don't know (a) which lines in the code printed stuff, nor (b) what the correct content would be. To handle (a), I added a bit of info to the print statements, so I could see what was printing what, in an attempt to get a little further.

Your indentation was messy and inconsistent, so I cleaned that up a bit. I then noticed that the last section of your code was essentially duplicated, so I pulled it out into a subroutine to handle things.

I also noticed a few other things:

I stopped here, because I got the code in a nice enough state to work on. But I don't really know what you're asking for help with, at the moment. It looks like you've done most of the work in parsing the files and collecting the data. You're not doing anything with the data though. So I don't know if you're asking for help in storing the data in a structured form, or how to figure out what to compare with what, or exactly what the issue is.

I'll leave you with the code I ended up with:

use strict; use warnings; my $in_macro = $ARGV[0]; my $alpha_config = $ARGV[1]; if ($#ARGV!=1) { print "USAGE :: perl bias_vol_chk.pl <<CELL_NAME>> <<config_FILE> +> \n\n"; exit(1); } my $pvt_name; my $bias_voltage; my @bias_voltage; open my $ALPHAFILE, "<", $alpha_config or die "Can not open config_FIL +E"; while (my $line = <$ALPHAFILE>) { chomp $line; print "alpha[$.]: $line \n"; if ($line =~m/\s*cornerData\((.*)\)\s*\{(.*),TEMP\s*(.*)/g) { $pvt_name = $1; $bias_voltage = $2; print " PVT_NAME: $pvt_name\n"; print " BIAS_V: $bias_voltage\n"; @bias_voltage = split (',',$bias_voltage); if ($pvt_name =~m/^([a-z].*)([0-9]p.*)/) { my ($process, $vol_temp) = ($1, $2); my $process_two = substr($process, 0, 2); #got ff from ffg +p my @vol_temp = split ('v',$vol_temp); my $temp = $vol_temp[1]; my $volt_1 = $vol_temp[0]; $volt_1 =~ s/[0]$//; $vol_temp[0] =~ s/[0]$//; my $volt_2 = $vol_temp[0]; my @volt_2 = split('p',$volt_2); $volt_2 = join('.',@volt_2); #replacing p with . my $file_name1 = "lib_pg/$in_macro"; print " FNAME 1: $file_name1\n"; if (-e $file_name1) { my $data = handle_library_file($file_name1); # Do something with the $data } my $file_name2 = "lib_pg/$in_macro"; print " FNAME 2: $file_name2\n"; if (-e $file_name2) { my $data = handle_library_file($file_name2); # Do something with the $data } } } } sub handle_library_file { my $file_name = shift; open my $LIBFILE, "<", $file_name or die "Can not open INPUT liber +ty file $file_name: $!"; while (my $libline = <$LIBFILE>) { chomp $libline; if ($libline=~m/^\s*voltage_map\((.*)\)/g) { my @volt_array = ("$1"); my $lib_volt = $1; my @lib_volt = split (',',$lib_volt); print "FILE lib_volt: @lib_volt \n"; } } # After gathering and processing the data, return it! }

And if anyone else has any guesses as to what to do, I took his second code chunk, named it 'mnk_alpha' and put it in the same directory as the script (which I called 'pm_1115228.pl'). I then created a subdirectory named 'lib_pg' and dropped his third, fourth and fifth code chunks in that directory named 'ss0p905v100c', 'ffg0p82v100c' and 'tt0p4v100c', respectively. I'm pretty sure I got the $file_name1 and $file_name2 bit wrong, but at this point the question became unclear enough and I have written enough, that I'm kinda done with it, pending further input from the OP.

A sample run gives me:

$ perl pm_11105228.pl ffg0p82v100c mnk_alpha alpha[1]: put cornerData(ffg0p82v100c) {VDD 0.825,VDDQN 1.17,VDDM 1.17 +,TEMP 100} PVT_NAME: ffg0p82v100c BIAS_V: VDD 0.825,VDDQN 1.17,VDDM 1.17 FNAME 1: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 FNAME 2: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 alpha[2]: put cornerData(ssg0p905v100c) {VDD 0.825,VDDQN 1.1,VDDM 0.17 +,TEMP 100} PVT_NAME: ssg0p905v100c BIAS_V: VDD 0.825,VDDQN 1.1,VDDM 0.17 FNAME 1: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 FNAME 2: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 alpha[3]: put cornerData(tt0p40v100c) {VDD 0.825,VDDQN 1.07,VDDM 2.15, +TEMP 100} PVT_NAME: tt0p40v100c BIAS_V: VDD 0.825,VDDQN 1.07,VDDM 2.15 FNAME 1: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 FNAME 2: lib_pg/ffg0p82v100c FILE lib_volt: VDDQN 1.1 FILE lib_volt: VDDM 1.1 FILE lib_volt: VSS 0 alpha[4]:

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Comparing values from two different files and flag error
by anirbanphys (Beadle) on Aug 29, 2019 at 17:26 UTC

    Thank you roboticus for reading the post and providing some valuable feedback. You have justified things rightly. I agree with your points. The fact is, I am not at all good at this language. For the purpose of automation I use perl and I seek help Monks from Perl Monks :). But I can assure you I noted all the valuable feedback and this will always be reflected for my next perl assignment.

    Let me explain you what is the expectation from the code.

    I need to compare the different bias voltages, one which we picked up from "mnk_alpha" and the other from the files, inside of lib_pg directory.For example "put cornerData(ffg0p82v100c) {VDD 0.825,VDDQN 1.17,VDDM 1.17 +,TEMP 100} " line bias voltages for the given PVT ffg0p82v100c of mnk_alpha file and the corresponding file (file name must be <cell_name>_PVT_pg.lib, here the cell name is "mnk_lib" and PVT is ff0p82v100c. We are omitting the word "g") inside mnk_lib/lib_pg/mnk_lib_ff0p82v100c_pg.lib, if it is wrong it will flag an ERROR message. Beside this if any bias voltages are missing from any of the file, it will also display the message. Please follow the desired output in the terminal or in a separate file after running the code.

    DESIRED OUTPUT

    PVT === ffg0p82v100c File mnk_alpha ==== VDD 0.825,VDDQN 1.17,VDDM 1.17 File mnk_lib_ff0p82v100c_pg.lib ===== VDDQN 1.1, VDDM 1.1,VSS 0 Bias voltage differences has been observed for VDDQN, VDDM. Missing Bias voltages VSS from mnk_alpha file. VDD from mnk_lib_ff0p82v100c_pg.lib file PVT === ssg0p905v100c File mnk_alpha === VDD 0.825,VDDQN 1.1,VDDM 0.17 File mnk_lib_ss0p905v100c_pg.lib ===== VDDQN 1.1, VDDM 1.1,VSS 0 Bias voltage differences has been observed for VDDQN, VDDM. Missing Bias voltages VSS from mnk_alpha file. VDD from mnk_lib_ss0p905v100c_pg.lib file PVT === tt0p40v100c File mnk_alpha === VDD 0.825,VDDQN 1.07,VDDM 2.15 File mnk_lib_tt0p40v100c_pg.lib ===== VDDQN 1.1, VDDM 1.1,VSS 0 Bias voltage differences has been observed for VDDQN, VDDM. Missing Bias voltages VSS from mnk_alpha file. VDD from mnk_lib_tt0p40v100c_pg.lib file

    At time of posting I was not very clear what should be the desired output and please accept my sincere apologies for this.

    Few things I want to explain more to avoid confusions :)

    1. The file inside <Cell>/lib_pg/ directory could be mnk_lib_ss0p905v100c_pg.lib or mnk_lib_ssg0p905v100c_pg.lib. And that is why I did some operations in the first posted code.

    2. The code which I posted at the beginning, actually just grepping the bias voltages but not comparing.

    I hope this can give some light to understand the problem. I updated the code, and this look like this ::
    use strict; use warnings; my $in_macro = $ARGV[0]; my $alpha_config = $ARGV[1]; if ($#ARGV!=1) { print "USAGE :: perl bias_mnk.pl <<CELL_NAME>> <<config_FILE>> \n +\n"; exit(1); } my $pvt_name; my $bias_voltage; my @bias_voltage; open my $ALPHAFILE, "<", $alpha_config or die "Can not open config_FIL +E"; while (my $line = <$ALPHAFILE>) { chomp $line; print "alpha[$.]: $line \n"; if ($line =~m/\s*cornerData\((.*)\)\s*\{(.*),TEMP\s*(.*)/g) { $pvt_name = $1; $bias_voltage = $2; print " PVT_NAME: $pvt_name\n"; print " BIAS_V: $bias_voltage\n"; @bias_voltage = split (',',$bias_voltage); if ($pvt_name =~m/^([a-z].*)([0-9]p.*)/) { my ($process, $vol_temp) = ($1, $2); my $process_two = substr($process, 0, 2); #got ff from ffg +p my @vol_temp = split ('v',$vol_temp); my $temp = $vol_temp[1]; my $volt_1 = $vol_temp[0]; $volt_1 =~ s/[0]$//; $vol_temp[0] =~ s/[0]$//; my $volt_2 = $vol_temp[0]; my @volt_2 = split('p',$volt_2); $volt_2 = join('.',@volt_2); #replacing p with . my $file_name1 = "$in_macro/lib_pg/$in_macro\_$pvt_name\_p +g.lib"; if (-e $file_name1) { print " FNAME 1: $file_name1\n"; my $data = handle_library_file($file_name1); # Do something with the $data } my $file_name2 = "$in_macro/lib_pg/$in_macro\_$process_two +$volt_1\v$temp\_pg.lib"; if (-e $file_name2) { print " FNAME 2: $file_name2\n"; my $data = handle_library_file($file_name2); # Do something with the $data } } } } sub handle_library_file { my $file_name = shift; open my $LIBFILE, "<", $file_name or die "Can not open INPUT liber +ty file $file_name: $!"; while (my $libline = <$LIBFILE>) { chomp $libline; if ($libline=~m/^\s*voltage_map\((.*)\)/g) { my @volt_array = ("$1"); my $lib_volt = $1; my @lib_volt = split (',',$lib_volt); print "FILE lib_volt: @lib_volt \n"; } } # After gathering and processing the data, return it! }