• 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. SKILL code to detect empty cells while parsing CSV file

Stats

  • Replies 7
  • Subscribers 160
  • Views 17250
  • Members are here 0
More Content

SKILL code to detect empty cells while parsing CSV file

BinduSripad
BinduSripad over 11 years ago

Hi SKILL experts,

I am trying to parse a CSV file and populate this data into a hash table. The CSV file could possibly have empty cells. If any of the first 7 columns for a given row in the CSV file is empty, the parser should stop and not write the data to the hash table.

Although when the line is read from the CSV file and written to a list, an empty cell is recognized as highlighted below:
 before parsing :"PCB Rules, SilkScreen Checks,SilkText to Exposed Pad Spacing,,Text to exposed ViaPad Spacing on Top Layer,axlformbmp1.bmp,silktxt_exposed-spacing.txt,MIN_TXT_TO_VIAPAD_TOP_DIST,FLOAT,1,,,"
 
After parsing the line using parseString(_line “,”) , the output is as follows. The empty cell is not being detected:
 after parsing :("PCB Rules" " SilkScreen Checks" "SilkText to Exposed Pad Spacing" "Text to exposed ViaPad Spacing on Top Layer" "axlformbmp1.bmp" "silktxt_exposed-spacing.txt" "MIN_TXT_TO_VIAPAD_TOP_DIST" "FLOAT" "1")

 My code snippet is as follows. Please let me know of any other string parsing function in SKILL which can detect spaces (empty cells read from CSV file). Or if I can use a combination of comma and spaces (more than 2) as ‘breakCharacters’.

 _returnLine = nil

_lineCount = 1

when(_inFile

while(gets(_newData _inFile)

when(_newData !="\n" && _lineCount > 1

_returnLine = ()

;; read each line from the csv file into a string

_textLine = car(parseString(_newData "\n"))

printf("\nbefore parsing :%L" _textLine)

;; parse the string with comma as the separator

_returnLine = parseString(_textLine ",")

printf("\nafter parsing :%L" _returnLine)

;; read the parsed fields

_ruleType = nth(0 _returnLine)

_category = nth(1 _returnLine)

_workbook = nth(2 _returnLine)

_ruleFile = nth(3 _returnLine)

_ruleName = nth(4 _returnLine)

_bitmap   = nth(5 _returnLine)

_document = nth(6 _returnLine)

;; populate the hash table only if the first 7 columns for each row are not empty

if( (_ruleType != " ") then

if( (nth(1 _returnLine) != " ") then

if( (nth(2 _returnLine) != " ") then

if( (nth(3 _returnLine) != " ") then

if( (nth(4 _returnLine) != " ") then

if( (nth(5 _returnLine) != " ") then

if( (nth(6 _returnLine) != " ") then 

_rule->ruletype = nth(0 _returnLine)

_rule->category = nth(1 _returnLine)

_rule->workbook = nth(2 _returnLine)

_rule->ruleFile = nth(3 _returnLine)

_rule->ruleName = nth(4 _returnLine)

_rule->bitmap   = nth(5 _returnLine)

_rule->document = nth(6 _returnLine)

)

)

)

)

)

)

)

;; insert this structure into hash table with rule name as key

ruleTable[nth(4 _returnLine)] = _rule

);when

;; move to next line

_lineCount = _lineCount + 1

);while

close(_inFile)

);when

 

 

Thanks,

Bindu 

  • Sign in to reply
  • Cancel
Parents
  • eDave
    eDave over 11 years ago

    Thanks for the warning. Did you raise a case with Cadence?

    Here's a clunky work around:

    defun( DE_StringCSVParse (txt "S")

     let((unusedChs, dummyCh1, dummyCh2)

    unusedChs = setof(ch, parseString("\t\f\r\n\v^~@#$%&*-_+={}[;:,.<>?|", ""), !index(txt, ch)); Assumes that at least two of these characters are unused.

    dummyCh1 = car(unusedChs)

    dummyCh2 = cadr(unusedChs)

    rexCompile(",")

    txt = rexReplace(txt, strcat(dummyCh1, dummyCh2), 0)

    rexCompile(dummyCh2)

    mapcar(lambda((x), rexReplace(x, "", 0)), parseString(strcat(dummyCh2, txt), dummyCh1))

    ))

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

    Thanks for the warning. Did you raise a case with Cadence?

    Here's a clunky work around:

    defun( DE_StringCSVParse (txt "S")

     let((unusedChs, dummyCh1, dummyCh2)

    unusedChs = setof(ch, parseString("\t\f\r\n\v^~@#$%&*-_+={}[;:,.<>?|", ""), !index(txt, ch)); Assumes that at least two of these characters are unused.

    dummyCh1 = car(unusedChs)

    dummyCh2 = cadr(unusedChs)

    rexCompile(",")

    txt = rexReplace(txt, strcat(dummyCh1, dummyCh2), 0)

    rexCompile(dummyCh2)

    mapcar(lambda((x), rexReplace(x, "", 0)), parseString(strcat(dummyCh2, txt), dummyCh1))

    ))

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
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