On Feb 10, 9:03 am, jwkr...@shaw.ca ("John W. Krahn") wrote:
> PolyPusher wrote:
> > All,
>
> Hello,
>
>
>
>
>
> > I have a file that defines pins for an IC.   The code needs to find
> > ".SUBCKT RE1321_4" and produce a list that complies with SKILL(lisp)
> > context for Cadence tool suite, the output needs to like ("Ant"
> > "DCS_RX"...... "last pin ")   and outputs to a file...
>
> > If pins list in the file do not fit on one line the line ends and the
> > next line has the "+"
> > sign.    The code needs to look for the + sign if on the next line
> > following .SUBCKT RE1321_4, in this case and stop when a + sign is not
> > found.
>
> > What I have so far is posted below.   I really need the user to input
> > the circuit name, in this case
> > "RE1321_4" and the output file to be "RE1321_4_NavInputPins.list"
> > file.    How is that done.
>
> > Thank you for any and all help you people are great!
> > Eric
>
> > .SUBCKT RE1321_4 ANT DCS_RX DCS_VRX GSM_RX GSM_TX GSM_VRX GSM_VTX
> > HB_GND PCS_TX
> > +    PCS_VTX SHUNT_GND VRXEN X1 HB_GND GSM_RX DCS_RX DCS_VRX GSM_VRX
> > PCS_TX SHUNT_GND ANT VRXEN GSM_VTX
> > +    GSM_TX PCS_VTX __RE1321_4 rlin=18 TXgateWLB=2200 CHB_sht=3.31
> > rgate=4.46
> > +    rbias=9 rlinsg=13.45 TXgateW=1500
> > .ENDS RE1321_4
>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
>
> > my $read_file  = 'RE1321_4.cbr';
> > my $write_file = 'NavInputPins.list';
>
> > open READ,  '<', $read_file  or die "Can't open '$read_file' $!";
> > open WRITE, '>', $write_file or die "Can't open '$write_file' $!";
>
> > while( my $line = <READ> ) {
> >     if( $line =~ m{ \A \.SUBCKT\ RE1321_4}x ) {
> >         my @fields = split(' ',$line);
> >         my @pins = grep(!/\n/, @fields[ 2 .. $#fields] );
>
> Your grep() will not find any newlines in @fields because split('
> ',$line) removes *all* whitespace and a newline is a type of whitespace.
>
>           my @pins = @fields[ 2 .. $#fields ];
>
> >         print WRITE '(';
> >         print WRITE '"',  join('" "',@pins);
> >         print WRITE  '")', "\n";
> >     }
> > }
> > close READ  or die "Couldn't close '$read_file' $!";
> > close WRITE or die "Couldn't close '$write_file' $!";
>
> >     exit(0);
>
> This may be close to what you want:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> print 'Please input the circuit name: ';
> chomp( my $circuit_name = <STDIN> );
>
> my $read_file  = 'RE1321_4.cbr';
> my $write_file = "${circuit_name}_NavInputPins.list";
>
> open READ,  '<', $read_file  or die "Can't open '$read_file' $!";
> open WRITE, '>', $write_file or die "Can't open '$write_file' $!";
>
> my $data;
> while ( <READ> ) {
>      if ( s/^\.SUBCKT\s+$circuit_name\s// ..
> s/^\.ENDS\s+$circuit_name\s// ) {
>          s/^\+//;
>          $data .= $_;
>          }
>      elsif ( length $data ) {
>          $data =~ s/\s\w*$circuit_name.*//s;  # remove non-pin data
>          my @pins = split ' ', $data;
>          print WRITE '(', join( ' ', map qq["$_"], @pins ), ")\n";
>          $data = undef;
>          }
>      }
>
> close READ  or die "Couldn't close '$read_file' $!";
> close WRITE or die "Couldn't close '$write_file' $!";
>
> exit 0;
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.               -- Damian Conway- Hide quoted text -
>
> - Show quoted text -

John,

That came close to working with a slight change.  My explanation and/
or understanding was too weak yet.  Here is another example:

.SUBCKT VtoI_opamp_BD_v2 Ibias30uA2 Res Vbias VtoI_casc2 casc en enN
gate
+    gate_filt gnd offset_en offset_enN offset_mirror_en
offset_mirror_enN vcc
+    wcdma_offset

The code needs to look for ".SUBCKT VtoI_opamp_BD_v2", then see if the
new line, next line, has a "+" sign in front of it, if yes process if
no end.    As you can tell the syntax for Perl is still making my head
spin ;)

Here is what we have so far...

#!/usr/bin/perl
use warnings;
use strict;


print 'Please input the circuit name: ';
chomp( my $circuit_name = <STDIN> );


my $read_file  = "${circuit_name}.cbr";
my $write_file = "${circuit_name}_Pins.list";


open READ,  '<', $read_file  or die "Can't open '$read_file' $!";
open WRITE, '>', $write_file or die "Can't open '$write_file' $!";


my $data;
while ( <READ> ) {
     if ( s/^\.SUBCKT\s+$circuit_name\s// .. s/^\.ENDS\s+$circuit_name
\s// )
        { s/^\+//;$data .= $_;}
     elsif ( $data ) {
         $data =~ s/\s\w*$circuit_name.*//s;  # remove non-pin data
         my @pins = split ' ', $data;
         print WRITE '(', join( ' ', map qq["$_"], @pins ), ")\n";
         $data = undef;
         }
     }


close READ  or die "Couldn't close '$read_file' $!";
close WRITE or die "Couldn't close '$write_file' $!";


exit 0;


Thank you!
Eric



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to