• 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. abTable() to read only desired lines from CSV file?

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 14230
  • 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

abTable() to read only desired lines from CSV file?

yeh1
yeh1 over 5 years ago

Is there an update to abTable, or some other way to import only lines from 20 to 40 from a CSV into a waveform? Ref: community.cadence.com/.../getasciiwave has abTable but not with this feature added.

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago

    In the other post, I provided the original code (abTable was pretty much made obsolete by getAsciiWave) with a view to anyone who wanted to update it, could. If the original requester (from 9 years ago) did, they didn't re-post the code that they'd changed.

    Anyway, I spent a few minutes this morning adding a ?maxRows argument to the function (was pretty easy) - here's the updated version (which can also be registered with the calculator in IC617 and later by using the "fx" button on the calculator function panel, or the + button in the ADE Explorer/Assembler expression builder):

    /* abTable.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Jan 11, 1999 
    Modified   Jun 20, 2020 
    By         A.D.Beckett
    
    Read a waveform from a file of numbers, and return
    it as a waveform object
    
    e.g.
    
    myWave=abTable("data.asc")
    myWave2=abTable("withheader.asc" ?skip 1 ?xCol 2 ?yCol 3)
    ; ignore the first 20 lines and only read the next 10
    myWave3=abTable("withheader.asc" ?skip 20 ?maxRows 10)
    
    Version 1.2 added (after 21 years!) ability to specify the maximum
    rows to read, and the calculator template. From IC617 onwards can use
    the "fx" button in the calculator function panel to add this function
    to the calculator using this.
    
    ***************************************************
    
    SCCS Info: @(#) abTable.il 06/20/20.13:33:02 1.2
    
    */
    
    /**********************************************************************
    *                                                                     *
    *      (abTable fileName @key (xCol 1) (yCol 2) (skip 0) maxRows)     *
    *                                                                     *
    *      Reads a tabulated file of numbers from file specified in       *
    *    fileName, and the remain arguments are keyword. xCol and yCol    *
    *    are the column numbers of the x and y axis (starting from 1).    *
    * skip is the number of lines to skip at the beginning (for headers). *
    *                   A waveform object is returned.                    *
    *                                                                     *
    **********************************************************************/
    
    (procedure (abTable fileName @key (xCol 1) (yCol 2) (skip 0) (maxRows 'all))
      (let (prt line wave xVec yVec xVal yVal (row 0))
           (unless
            (setq prt (infile fileName))
            (error "Could not read waveform from file %s\n" fileName)
            )
           ;-----------------------------------------------------------------
           ; skip header lines
           ;-----------------------------------------------------------------
           (for count 1 skip
                (gets line prt))
           ;-----------------------------------------------------------------
           ; create the empty vectors
           ;-----------------------------------------------------------------
           (setq xVec (drCreateVec 'double 1))
           (setq yVec (drCreateVec 'double 1))
           ;-----------------------------------------------------------------
           ; these want to be zero indexed
           ;-----------------------------------------------------------------
           (postdecrement xCol)
           (postdecrement yCol)
           (while (and
                    (setq line (lineread prt))
                    (or (null (numberp maxRows))
                        (lessp row maxRows)))
                  /* ignore blank lines */
                  (unless (equal line t)
                          (setq xVal (nth xCol line))
                          (setq yVal (nth yCol line))
                          (unless (and (numberp xVal) (numberp yVal))
                                  (error "Invalid data %L\n" line)
                                  )
                          (drAddElem xVec xVal)
                          (drAddElem yVec yVal)
                          (postincrement row)
                          )
                  )
           ;-----------------------------------------------------------------
           ; create the waveform object and return it
           ;-----------------------------------------------------------------
           (setq wave (drCreateEmptyWaveform))
           (drPutWaveformXVec wave xVec)
           (drPutWaveformYVec wave yVec)
           wave
           ))
    
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abTable
      name abTable
      description "Read waveform from file"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (fileName xCol yCol skip maxRows )
              params(nil
                     fileName (nil
                           prompt "File Name"
                           tooltip "File name"
                           guiRowHint 0
                           type string
                           required t
                     )
                     xCol (nil
                           prompt "X Column"
                           tooltip "X column number"
                           guiRowHint 1
                           type int
                           default 1
                           required nil
                           keyed t
                     )
                     yCol (nil
                           prompt "Y Column"
                           tooltip "Y column number"
                           guiRowHint 1
                           type int
                           default 2
                           required nil
                           keyed t
                     )
                     skip (nil
                           prompt "Skip rows"
                           tooltip "Rows to skip"
                           guiRowHint 3
                           type int
                           default 0
                           required nil
                           keyed t
                     )
                     maxRows (nil
                           prompt "Maximum rows"
                           tooltip "Maximum rows to read"
                           guiRowHint 3
                           type int
                           required nil 
                           keyed t
                     )
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • yeh1
    yeh1 over 5 years ago in reply to Andrew Beckett

    Thanks

    • 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