• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How to parse the contents of a file?

Stats

  • Locked Locked
  • Replies 15
  • Subscribers 145
  • Views 24587
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to parse the contents of a file?

Messi
Messi over 14 years ago

Hi everyone,

    If for example i have some file say rules file with contents of file being : <ruleno.> <rule name> <value>.

   How to parse the contents of this file and store in  table format?

  Can i get code for this?

Thanks,

  Messi

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago
    Hi Messi,

    Can you give an example of the file contents? In particular knowing the delimiters would help. Your description was not that precise...

    Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Messi
    Messi over 14 years ago

    Thanks for the quick reply...

    I will set an example: infile("/messi/Exp/rulecheck.il") looks like

       R1A  POLY WIDTH 0.5

          R1B ACTIVE WIDTH 0.4

       R2A POLY SEP    0.25

            R2B ACTIVE SEP    0.75

       R3 POLY OVERLAP 0.6

       ......................................

      ........................................

    ie..<ruleno.> <space> <layername> <space> <type> <space> <value>

    So basically i want to read this file and use parseString and store contents in table.I understand that i have to use infile command and then parseString with "space".but i am not able to put all these into a code..also i would like to make it into a table with all the values read from the file. The table contents should be like:

             <ruleno.>     <layer used(eg:POLY)>  <type(eg:WIDTH)>  <value>

    So, basically if i feed my rules filename in the procedure i should be able to see its contents in an tabulated form.

    Thanks

     Messi

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • LeJonT
    LeJonT over 14 years ago

    Hi,

    Something like this would do..

     procedure( parseFile( ipFile )
      let( ( tokens table )
        table = list()
        fpFile = infile( ipFile )
        while( gets( line fpFile )
          tokens = parseString( line )
          tokens && ( table = cons( tokens table ) )
        ) ;while file
        close( fpFile )
        println( table )
      ) ;let
    ) ;procedure

     After saving the above code in a file, you need to load it in icfb.

    load( "parseFile.il" )
    parseFile( "int.txt" )

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Messi
    Messi over 14 years ago

    Thanks LeJonT,

       It works but it returns the contents of file as list.Can i obtain each element of this list and outfile (instead of geeting it printed in CIW) it into another file say out.txt.

      my out.txt should look like in table form as,

       headers: <ruleno.>   <layername>   <type>    <value>

                       R1A          POLY           WIDTH      0.5

                       R1B          ACTIVE         WIDTH     0.4               

                      .....            .........           .........     ......

                    .......            ...........         .........     ........

    Thanks once again for your help,

       Messi

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • LeJonT
    LeJonT over 14 years ago

    Hi,

    This would do it.. 

    procedure( parseFile( ipFile outFile )
      let( ( tokens table fpFile fpoutFile )
        table = list()
        fpFile = infile( ipFile )
        fpoutFile = outfile( outFile )
        fprintf( fpoutFile "%-15s%-15s%-15s%-15s\n" "RULE NO" "LAYERNAME" "TYPE" "VALUE" )
        while( gets( line fpFile )
          tokens = parseString( line )
          tokens && fprintf( fpoutFile "%-15s%-15s%-15s%-15s\n" nth( 0 tokens ) nth( 1 tokens ) nth( 2 tokens ) nth( 3 tokens ) )
        ) ;while file
        close( fpoutFile )
        close( fpFile )
      ) ;let
    ) ;procedure

    parseFile( "int.txt" "out.txt" )

     But, I'm little surprised about why you are using SKILL for a file operation!

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Messi
    Messi over 14 years ago

    Thanks alot,

        i wanted to know how i can read any file and out it.i tried to code by reading file as u have written using infile then parsing it.To make table i was using makeTable commands and i was using car and cdr concepts to get the contents of my parsed file.But my code generateed errors...

    anyways thanx for the help,

    Regards,

      Messi

      

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • LeJonT
    LeJonT over 14 years ago

    Hi,

      You ofcourse can choose to use table, list or any datatype that suits the purpose. Here in this case, double list can serve the purpose. car and nth( 0 list ) are similar and car is much more efiiicient to.

    If you can post the code in here, we can try to see to the issues..

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Messi
    Messi over 14 years ago

    Thanks for your help,

        This is working and able to write to outfile.But can i know how to do the same using makeTable command.ie..my input would be just a rule file with the format mentioned earlier.my output would be a SKILL table.

    eg: a = makeTable("myTable" nil)

         so when i say a[R1A] it should return a list as: ("POLY" "WIDTH" "0.5")

    Thanks,

    Messi

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • dmay
    dmay over 14 years ago

    This is simple enough. Here is the original code suggestion with changes to make it store the data in a table:

    procedure( parseFile( ipFile )
      let( ( tokens table )
        table = makeTable("ruleTable" nil)
        fpFile = infile( ipFile )
        while( gets( line fpFile )
          tokens = parseString( line )
          when(tokens
            table[car(tokens)] = cdr(tokens)
          )
        ) ;while file
        close( fpFile )
        printstruct( table )
      ) ;let
    ) ;procedure

    Derek

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Messi
    Messi over 14 years ago

    Hi Derek,

             Thanks for your help.But when my rule file have this

                         RULE NO.    LAYER       TYPE                    VALUE
                            R1A,          POLY,      POLY WIDTH,            0.5
                            R1B,          POLY,      POLY SPACING,        0.25
                            R2A,          ACTIVE,    ACTIVE WIDTH,        0.7
                            R2B,         ACTIVE,    ACTIVE SPACING,     0.3

    when i load the code the output would have on top of it the headers ie (RULE NO.,LAYER...etc). cdr would help me remove these headers right??the output is also found to have results with R1B occuring first then R1A.How can get the output in same order as in the input rule file??

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information