• 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. read in text file containing numerical data and store in...

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 15058
  • 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

read in text file containing numerical data and store in list

MarkAL
MarkAL over 9 years ago

Hi, 

I need to read in a text file that contains x,y coordinate pairs as comma separated values and a newline between x,y pairs. The format would look like this: 

x1,y1
x2,y2
x3,y3
...
xN,yN

I would like to like to take these values and store them in a list:

MyList = list( list(x1,y1) list(x2,y2) list(x3,y3) ... list(xN,yN) )

I saw the "read" function can read in a text file line by line. Do I need to then write my own parsing scripts to store the data in the way I would like it? 

Thanks,
Mark

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 9 years ago

    Hi Mark,

    lineread() is probably easier, since it will read both numbers on the line at once; read would only read one value at a time, which makes more work.

    I also used tconc so that the list can be constructed in the right order (the alternative is to use cons to add each point on at the beginning of the list, and then call reverse() at the end). The car(points) at the end is to remove the tconc nature of the list (the info pointing to the end of the list).

    points=nil
    port=infile("coords.txt")
    when(port
      while(data=lineread(port)
        points=tconc(points data)
      )
      close(port)
      points=car(points)
    )

    Regards,

    Andrew.

    • 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