• 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. Allegro X PCB Editor
  3. How to Read a text file as Text Type

Stats

  • Replies 5
  • Subscribers 158
  • Views 14804
  • Members are here 0
More Content

How to Read a text file as Text Type

Geoff
Geoff over 12 years ago

I am having trouble reading a text file and having it stay as text. I guess skill expects every text item to be quoted.
Is there a way I can read it as text?

second choice: can I split each line into an Array?

sample_infile.il

775 640 N74011018 TP30CIR_TOP Top
5045 570 N74011128 TP30CIR_TOP Top
5175 1015 GND TP30CIR_TOP Top
55 1310 GND_EARTH TP30CIR_TOP Top
650 140 VOUT TP30CIR_TOP Top
500 140 MODEM_48VIN- TP30CIR_TOP Top
500 190 MODEM_48VIN+ TP30CIR_TOP Top
75 595 48VIN- TP30CIR_TOP Top
775 1190 48VIN+ TP30CIR_TOP Top

(defun Read_String ()
 FileData=infile("sample_infile.txt")
 LocLine=""

 while( LocLine!=nil
 
  LocLine=lineread(FileData)

  printf("%n    %n    %L\n" nth( 0 LocLine) nth( 1 LocLine) nth( 2 LocLine))

 );while

);defun


Skill > Read_String
775   640   N74011018
5045   570   N74011128
5175   1015   GND
55   1310   GND_EARTH
650   140   VOUT
500   140   (MODEM_48VIN - TP30CIR_TOP)
500   190   (MODEM_48VIN + TP30CIR_TOP)
E-
E- 75 595 48VIN- TP30CIR_TOP Top
E-             ^
E- SYNTAX ERROR found at line 8 column 13 of file sample_infile.txt
E- *Error* lineread/read: syntax error encountered in input
ERROR
Skill >

Things of note:

1. The minus and plus sign in MODEM_48VIN-  and  MODEM_48VIN+ gets separated in the output, and that makes a list of two items: (MODEM_48VIN - TP30CIR_TOP)
2. Program chokes on 48VIN-  maybe because it starts with a number and ends with a minus sign.

  • Sign in to reply
  • Cancel
  • eDave
    eDave over 12 years ago

    Use gets instead of lineread:

    (defun Read_String ()

     FileData = infile("sample_infile.txt")

     while(gets(str, FileData)

      LocLine = parseString(str)

      printf("%s    %s    %s\n" nth( 0 LocLine) nth( 1 LocLine) nth( 2 LocLine))

     );while

    );defun 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • eDave
    eDave over 12 years ago

    Oops. Use this:

    (defun Read_String ()

     FileData = infile("sample_infile.txt")

     while(gets(str, FileData)

      LocLine = parseString(str, " ")

      printf("%s    %s    %s\n" nth( 0 LocLine) nth( 1 LocLine) nth( 2 LocLine))

     );while

     close(FileData)

    );defun 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Geoff
    Geoff over 12 years ago

    That worked good except it seems to not exit gracefully from the While loop:

    Skill > Read_String
    775   640   N74011018
    5045   570   N74011128
    5175   1015   GND
    55   1310   GND_EARTH
    650   140   VOUT
    500   140   MODEM_48VIN-
    500   190   MODEM_48VIN+
    75   595   48VIN-
    775   1190   48VIN+
    E- *Error* fprintf/sprintf: format spec. incompatible with data - "Format is '%s   %s   %s\n', argument #2 is nil"
    ERROR
    Skill >

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • eDave
    eDave over 12 years ago
    You may want to add some checking. ie: when(length(LocLine) >= 3 printf("%s %s %s\n" nth( 0 LocLine) nth( 1 LocLine) nth( 2 LocLine)) )
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Geoff
    Geoff over 12 years ago

    I found the problem. The  text file had some empty lines at the end. Yes, I have to put a check for that.

     Thanks for Your help Dave!

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

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