• 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
Parents
  • ztzg
    ztzg over 12 years ago
    Hi Sanramz,

    What Andrew said.

    You are also missing a level of parens in the let( (cv) ... ) of
    create_boundary. As I was reindenting your code to get a better view, I
    couldn't help but split it into a couple of procedures as suggested by
    Andrew; the following seems to work for me:

    ;; File format:
    ;;
    ;; cell_name llx lly urx ury
    ;; BUF 0 0 4.448 4.424
    ;; AND 0 0 4.448 4.424

    procedure(MyCreateBoundary(libName cellName llx lly urx ury)
    let( (cv)
    cv = dbOpenCellViewByType(libName cellName "layout" "maskLayout" "w")
    dbCreateRect(cv list("prBoundary" "drawing") list(llx:lly urx:ury))
    dbSave(cv)
    )
    ) ; procedure

    procedure(MyCreateCells(libName listPath)
    let( (inPort line fields values)
    inPort = infile(listPath)
    if(inPort then
    while(gets(line inPort)
    ;; Split on *any* whitespace--gets rid of the trailing \n.
    fields = parseString(line)
    ;; Will contain nils if some fields cannot be converted.
    values = mapcar('atof (cdr fields))
    if(length(fields) == 5 && !memq(nil values) then
    ;; Looks good.
    apply('MyCreateBoundary libName car(fields) values)
    else
    warn("Skipping malformed line with fields %L" fields)
    )
    )
    close(inPort)
    else
    error("Unable to open %L for reading" listPath)
    ) ; if
    ) ; let
    ) ; procedure

    MyCreateCells("test" "/home/san/tiler/cell_list")

    Cheers, -D

    P.-S. — Pretty version at http://s.crosstwine.com/spb/487c57af. Feel
    free to use the reformatter to make your code easier to read!


    Andrew Beckett writes:
    > Two problems (at least, may be more because I didn't try the code)
    >
    > 1. The function create_boundary is not defined until after it's called, which is why you
    > have the problem you're seeing. If the main bit of the code had been contained within a
    > function definition, that would have been OK, because loading the file would have
    > defined the functions rather than executing them. In other words, if you'd put procedure
    > (createBoundaryFromFile(ListPath)... around your main code, the forward reference would
    > have been fine because you would not have been calling create_boundary before it had
    > been defined. Then after loading the code, you'd do createBoundaryFromFile("/path/to/the
    > /file")
    >
    > 2. The coordinates will all be strings, so you should do atof(nth(1 lineData)) etc.
    >
    > Note too that if this is for IC61, you'd have to use dbCreatePRBoundary rather than
    > creating a shape on the PRBoundary/drawing LPP.
    >
    > Regards,
    >
    > Andrew
    >
    > From: sanramz [mailto:bounce-sanramz@cadence.com]
    > Sent: Monday, December 17, 2012 07:00 AM
    > To: Andrew Beckett
    > Subject: Re: [Custom IC SKILL Forum] How to parse the contents of a file?
    >
    > Hi,
    >
    > I am trying to create multiple new layouts from a list unix file in to one library.
    > In each cell Iam also trying to create a PR boundary with the coordinates that are
    > present in the unix file.
    >
    > The list file contains the cell name and PR boundary coordinates as shown below.
    >
    > cell_name llx lly urx ury
    >
    > BUF 0 0 4.448 4.424
    >
    > AND 0 0 4.448 4.424
    >
    > My code for this is as shown below.
    >
    > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    >
    > ListPath = "/home/san/tiler/cell_list"
    >
    > ;lib_name="test"
    >
    > inPort = infile( ListPath )
    >
    > when( inPort
    >
    > while( gets( line inPort )
    >
    > ;println( nextLine )
    >
    > lineData = parseString(line " ")
    >
    > ;portTable[car(lineData)] = evalstring(cadr(lineData))
    >
    > ;cell_name=car(lineData)
    >
    > cell_name=nth(0 lineData)
    >
    > llx=nth(1 lineData)
    >
    > lly=nth(2 lineData)
    >
    > urx=nth(3 lineData)
    >
    > ury=nth(4 lineData)
    >
    > create_boundary(cell_name llx lly urx ury)
    >
    > )
    >
    > close( inPort )
    >
    > )
    >
    > procedure(create_boundary(cell_name llx lly urx ury)
    >
    > let (cv)
    >
    > cv=dbOpenCellViewByType("test" "cell_name" "layout" "maskLayout" "w")
    >
    > dbCreateRect(cv list("prBoundary" "drawing") list(llx:lly urx:ury))
    >
    > dbSave(cv)
    >
    > );procedure
    >
    > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    >
    > For this code, I am getting the following error.
    >
    > *Error* eval: undefined function - create_boundary
    > *Error* load: error while loading file - "create_cell.il" at line 20
    >
    > Kindly help me to solve this.
    >
    > Is it because of the "parsing", as i expect \n is coming for the "urx" variable when I
    > try to access it??
    >
    > Regards,
    >
    > santhosh.
    >
    > You received this email because you subscribed to notifications for the Cadence Custom
    > IC SKILL Forum. To unsubscribe, log in, go to forums, and change your forum
    > subscriptions.
    >
    > http://www.cadence.com/community/forums/ForumSubscriptions.aspx
    >
    > --
    > View this message online at: http://www.cadence.com/Community/forums/p/17331/
    > 1317721.aspx#1317721
    >
    http://crosstwine.com
    tel: +49 89 2189 2939
    cell: +49 174 3489 428

    “Strong Opinions, Weakly Held”
    — Bob Johansen
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • ztzg
    ztzg over 12 years ago
    Hi Sanramz,

    What Andrew said.

    You are also missing a level of parens in the let( (cv) ... ) of
    create_boundary. As I was reindenting your code to get a better view, I
    couldn't help but split it into a couple of procedures as suggested by
    Andrew; the following seems to work for me:

    ;; File format:
    ;;
    ;; cell_name llx lly urx ury
    ;; BUF 0 0 4.448 4.424
    ;; AND 0 0 4.448 4.424

    procedure(MyCreateBoundary(libName cellName llx lly urx ury)
    let( (cv)
    cv = dbOpenCellViewByType(libName cellName "layout" "maskLayout" "w")
    dbCreateRect(cv list("prBoundary" "drawing") list(llx:lly urx:ury))
    dbSave(cv)
    )
    ) ; procedure

    procedure(MyCreateCells(libName listPath)
    let( (inPort line fields values)
    inPort = infile(listPath)
    if(inPort then
    while(gets(line inPort)
    ;; Split on *any* whitespace--gets rid of the trailing \n.
    fields = parseString(line)
    ;; Will contain nils if some fields cannot be converted.
    values = mapcar('atof (cdr fields))
    if(length(fields) == 5 && !memq(nil values) then
    ;; Looks good.
    apply('MyCreateBoundary libName car(fields) values)
    else
    warn("Skipping malformed line with fields %L" fields)
    )
    )
    close(inPort)
    else
    error("Unable to open %L for reading" listPath)
    ) ; if
    ) ; let
    ) ; procedure

    MyCreateCells("test" "/home/san/tiler/cell_list")

    Cheers, -D

    P.-S. — Pretty version at http://s.crosstwine.com/spb/487c57af. Feel
    free to use the reformatter to make your code easier to read!


    Andrew Beckett writes:
    > Two problems (at least, may be more because I didn't try the code)
    >
    > 1. The function create_boundary is not defined until after it's called, which is why you
    > have the problem you're seeing. If the main bit of the code had been contained within a
    > function definition, that would have been OK, because loading the file would have
    > defined the functions rather than executing them. In other words, if you'd put procedure
    > (createBoundaryFromFile(ListPath)... around your main code, the forward reference would
    > have been fine because you would not have been calling create_boundary before it had
    > been defined. Then after loading the code, you'd do createBoundaryFromFile("/path/to/the
    > /file")
    >
    > 2. The coordinates will all be strings, so you should do atof(nth(1 lineData)) etc.
    >
    > Note too that if this is for IC61, you'd have to use dbCreatePRBoundary rather than
    > creating a shape on the PRBoundary/drawing LPP.
    >
    > Regards,
    >
    > Andrew
    >
    > From: sanramz [mailto:bounce-sanramz@cadence.com]
    > Sent: Monday, December 17, 2012 07:00 AM
    > To: Andrew Beckett
    > Subject: Re: [Custom IC SKILL Forum] How to parse the contents of a file?
    >
    > Hi,
    >
    > I am trying to create multiple new layouts from a list unix file in to one library.
    > In each cell Iam also trying to create a PR boundary with the coordinates that are
    > present in the unix file.
    >
    > The list file contains the cell name and PR boundary coordinates as shown below.
    >
    > cell_name llx lly urx ury
    >
    > BUF 0 0 4.448 4.424
    >
    > AND 0 0 4.448 4.424
    >
    > My code for this is as shown below.
    >
    > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    >
    > ListPath = "/home/san/tiler/cell_list"
    >
    > ;lib_name="test"
    >
    > inPort = infile( ListPath )
    >
    > when( inPort
    >
    > while( gets( line inPort )
    >
    > ;println( nextLine )
    >
    > lineData = parseString(line " ")
    >
    > ;portTable[car(lineData)] = evalstring(cadr(lineData))
    >
    > ;cell_name=car(lineData)
    >
    > cell_name=nth(0 lineData)
    >
    > llx=nth(1 lineData)
    >
    > lly=nth(2 lineData)
    >
    > urx=nth(3 lineData)
    >
    > ury=nth(4 lineData)
    >
    > create_boundary(cell_name llx lly urx ury)
    >
    > )
    >
    > close( inPort )
    >
    > )
    >
    > procedure(create_boundary(cell_name llx lly urx ury)
    >
    > let (cv)
    >
    > cv=dbOpenCellViewByType("test" "cell_name" "layout" "maskLayout" "w")
    >
    > dbCreateRect(cv list("prBoundary" "drawing") list(llx:lly urx:ury))
    >
    > dbSave(cv)
    >
    > );procedure
    >
    > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    >
    > For this code, I am getting the following error.
    >
    > *Error* eval: undefined function - create_boundary
    > *Error* load: error while loading file - "create_cell.il" at line 20
    >
    > Kindly help me to solve this.
    >
    > Is it because of the "parsing", as i expect \n is coming for the "urx" variable when I
    > try to access it??
    >
    > Regards,
    >
    > santhosh.
    >
    > You received this email because you subscribed to notifications for the Cadence Custom
    > IC SKILL Forum. To unsubscribe, log in, go to forums, and change your forum
    > subscriptions.
    >
    > http://www.cadence.com/community/forums/ForumSubscriptions.aspx
    >
    > --
    > View this message online at: http://www.cadence.com/Community/forums/p/17331/
    > 1317721.aspx#1317721
    >
    http://crosstwine.com
    tel: +49 89 2189 2939
    cell: +49 174 3489 428

    “Strong Opinions, Weakly Held”
    — Bob Johansen
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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