Sort a list.

Discussion in 'Cadence' started by eric.d.fitzsimmons, Apr 13, 2009.

  1. All,

    I have a Skill program that produces a list and wish to sort the list
    by Instance, Cellname, pin or net as user prompts thru a form. The
    format of the string is:

    "|I11.buff_01.out - net16" Where |I11 is the instance, buff_01.out
    the cellname, out is the pin of
    the instance and net16
    connects to out.

    The list looks like

    EFNet_list
    ("|I10.buff_01.in - ckin" "|I10.buff_01.out - net032" "|
    I10.buff_01.sub - vss" "|I10.buff_01.vdd - vbat" "|I11.buff_01.in -
    ckin_b" "|I11.buff_01.out - net16" "|I11.buff_01.sub - vss" "|
    I11.buff_01.vdd - vbat" "|I14.RC_delay.in - p2" "|I14.RC_delay.out -
    net021"
    )

    Upon user input I want to sort by instance or cellname or pin or net.
    So if user selects sort by instance |I10, then I need to produce a
    list from the above with only the instance chosen and refresh the
    form.

    In unix I could grep by the instance and pipe the same string into a
    file. To be clear, from above the new list needs to have only the
    instance chosen but the string is left intact such as:

    EFNet_list_sorted
    ("|I10.buff_01.in - ckin" "|I10.buff_01.out - net032" "|
    I10.buff_01.sub - vss" "|I10.buff_01.vdd - vbat"
    )

    How do I do this in Skill?

    Unfinished program is below, but if you bring up a schematic and load
    the skill a form should come up with the list.

    Thank you in advance for any help,
    Eric

    procedure(EFCreateNetForm()

    let((EFNetsBox EFTermsOrNet )

    cv=geGetEditCellView()
    EFNet_list=nil
    when(cv
    foreach( inst cv~>instances
    EFInstance=inst~>name
    EFCellname=inst~>master~>cellName
    foreach( instTerm inst~>instTerms
    Term=instTerm~>name
    Net=instTerm~>net~>name
    printf(EFInstance)
    printf(".")
    printf(EFCellname)
    printf(".")
    printf(Term)
    printf(" - ")
    printf(Net)
    printf("\n")
    ; EFNet_list='("|")
    ; EFNet_list=append(EFNet_list list(strcat(EFInstance "."
    EFCellname "." Term " - " Net )))
    EFNet_list=append(EFNet_list list(strcat( "|" EFInstance "."
    EFCellname "." Term " - " Net )))
    );foreach
    );foreach
    );when
    t
    );let

    ;sort the output
    EFNet_list=sort(EFNet_list nil)

    ;=============================================
    ;section below defines form
    ;=============================================

    EFDualMode = hiCreateRadioField(
    ?name 'EFDualMode
    ?prompt "All Data or Sort?"
    ?value "All Data"
    ?defValue "All Data"
    ?choices list("All Data" "Sort by" )
    ?callback
    list("case(EFInstanceNetsForm->EFDualMode->value
    (\"All Data\"
    EFInstanceNetsForm->EFSortBy->editable = nil
    )
    (\"Sort by\"
    EFInstanceNetsForm->EFSortBy->editable = t
    )
    )");end case
    )

    EFSortBy = hiCreateStringField(
    ?name 'EFSortBy
    ?prompt "Instance, Net, Cellname or Pin"
    ?editable nil
    ?value ""
    )

    EFNetsBox = hiCreateListBoxField(
    ?name 'EFListBoxField
    ?prompt " "
    ?choices EFNet_list
    ?value nil
    ?multipleSelect nil
    ?changeCB "EFprobe()"
    ?doubleClickCB "EFprobeinst()"
    ?numRows length(EFNet_list)
    )

    ;;; defines the form

    hiCreateAppForm(
    ?name 'EFInstanceNetsForm
    ?formTitle "Instance Nets"
    ?callback "EFSortExecution()"
    ?fields
    list(
    EFDualMode
    EFSortBy
    EFNetsBox
    )
    ?help ""

    ) ; hiCreateAppForm

    hiDisplayForm(EFInstanceNetsForm)

    );procedure
    EFCreateNetForm()
     
    eric.d.fitzsimmons, Apr 13, 2009
    #1
  2. eric.d.fitzsimmons

    Riad KACED Guest

    Hi Eric,

    This is a quick attempt you might need to tweak a bit.
    In summary, I have split up the strings into lists using a regular
    expression and then sorted the result as you described.
    Sorry for the lack of comments in my script, I'm running out of time
    I'm afraid :-(

    ;
    procedure( RKsortList(listToSort sortCriteria)
    let(((newList nil) returnList)
    rexCompile("^\\(.+\\)\\.\\(.+\\)\\.\\(.+\\) - \\(.+\\)")
    foreach(x listToSort
    rexExecute(x)
    newList=cons(list(rexSubstitute("\\1") rexSubstitute("\\2")
    rexSubstitute("\\3") rexSubstitute("\\4")) newList)
    )
    case(sortCriteria
    ("instance"
    returnList=sort(newList lambda( (a b) alphalessp((car a) (car
    b))))
    )
    ("cellname"
    returnList=sort(newList lambda( (a b) alphalessp((cadr a)
    (cadr b))))
    )
    ("pin"
    returnList=sort(newList lambda( (a b) alphalessp((caddr a)
    (caddr b))))
    )
    ("net"
    returnList=sort(newList lambda( (a b) alphalessp((cadddr a)
    (cadddr b))))
    )
    (t
    returnList=listToSort
    )
    )
    returnList
    )
    )
    ;

    Example of execution :
    myList= list("|I10.buff_01.in - ckin"
    "|I10.buff_01.out - net032"
    "|I10.buff_01.sub - vss"
    "|I10.buff_01.vdd - vbat"
    "|I11.buff_01.in - ckin_b"
    "|I11.buff_01.out - net16"
    "|I11.buff_01.sub - vss"
    "|I11.buff_01.vdd - vbat"
    "|I14.RC_delay.in - p2"
    "|I14.RC_delay.out - net021"
    )

    RKsortList(myList "pin")
    ==>
    (("|I10" "buff_01" "in" "ckin")
    ("|I11" "buff_01" "in" "ckin_b")
    ("|I14" "RC_delay" "in" "p2")
    ("|I10" "buff_01" "out" "net032")
    ("|I11" "buff_01" "out" "net16")
    ("|I14" "RC_delay" "out" "net021")
    ("|I10" "buff_01" "sub" "vss")
    ("|I11" "buff_01" "sub" "vss")
    ("|I10" "buff_01" "vdd" "vbat")
    ("|I11" "buff_01" "vdd" "vbat")
    )

    RKsortList(myList "instance")
    ==>
    (("|I10" "buff_01" "in" "ckin")
    ("|I10" "buff_01" "out" "net032")
    ("|I10" "buff_01" "sub" "vss")
    ("|I10" "buff_01" "vdd" "vbat")
    ("|I11" "buff_01" "in" "ckin_b")
    ("|I11" "buff_01" "out" "net16")
    ("|I11" "buff_01" "sub" "vss")
    ("|I11" "buff_01" "vdd" "vbat")
    ("|I14" "RC_delay" "in" "p2")
    ("|I14" "RC_delay" "out" "net021")
    )

    RKsortList(myList "cellname")
    ==>
    (("|I14" "RC_delay" "in" "p2")
    ("|I14" "RC_delay" "out" "net021")
    ("|I10" "buff_01" "in" "ckin")
    ("|I10" "buff_01" "out" "net032")
    ("|I10" "buff_01" "sub" "vss")
    ("|I10" "buff_01" "vdd" "vbat")
    ("|I11" "buff_01" "in" "ckin_b")
    ("|I11" "buff_01" "out" "net16")
    ("|I11" "buff_01" "sub" "vss")
    ("|I11" "buff_01" "vdd" "vbat")
    )

    RKsortList(myList "net")
    ==>
    (("|I10" "buff_01" "in" "ckin")
    ("|I11" "buff_01" "in" "ckin_b")
    ("|I14" "RC_delay" "out" "net021")
    ("|I10" "buff_01" "out" "net032")
    ("|I11" "buff_01" "out" "net16")
    ("|I14" "RC_delay" "in" "p2")
    ("|I10" "buff_01" "vdd" "vbat")
    ("|I11" "buff_01" "vdd" "vbat")
    ("|I10" "buff_01" "sub" "vss")
    ("|I11" "buff_01" "sub" "vss")
    )
     
    Riad KACED, Apr 13, 2009
    #2
  3. Riad,

    Thank you for the expample, I really appreciate your help

    Eric
     
    eric.d.fitzsimmons, Apr 14, 2009
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.