Skip to content

Instantly share code, notes, and snippets.

@steveroush
Created October 10, 2024 02:48
Show Gist options
  • Select an option

  • Save steveroush/84c11f6a8989a3f5f3d02aefcc3a1968 to your computer and use it in GitHub Desktop.

Select an option

Save steveroush/84c11f6a8989a3f5f3d02aefcc3a1968 to your computer and use it in GitHub Desktop.

Revisions

  1. steveroush created this gist Oct 10, 2024.
    167 changes: 167 additions & 0 deletions multiGraph.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,167 @@
    # set -x

    T=svg
    usage() { # Function: Print a help message.
    echo "Usage: $0 [ -G|N|E GraphvizOption ] [ -L layoutEngine ] [ -T outputFormat ] myFile.gv" 1>&2
    }
    exit_abnormal() { # Function: Exit with error.
    usage
    exit 1
    }
    ADD=""
    while getopts ":E:G:L:N:T:W:" options; do
    case "${options}" in
    G|N|E)
    ADD="$ADD"'*|'"${options}|${OPTARG/=/|}\n"
    ;;
    L) # layout
    Engines="$Engines ${OPTARG}"
    ;;
    T)
    T=${OPTARG}
    ;;
    *) # If unknown (any other) option:
    exit_abnormal # Exit abnormally.
    ;;
    esac
    done
    shift $(($OPTIND - 1))
    files=$@
    #File=${file%.*}

    if [[ "$Engines" == "" ]];then
    Engines="neato fdp sfdp dot circo twopi osage"
    fi

    #set -x
    # dot - ???
    dotOPTS="# dot
    "

    # osage - ???
    osageOPTS="# osage
    "

    # neato - dropped the hier
    # len added to support models
    neatoOPTS="
    neato|E|len|1.
    neato|G|mode|major|KK|sgd|ipsep
    neato|G|model|shortpath|mds|circuit|subset
    neato|G|overlap|false|vpsc
    neato|G|sep|+5|+10"

    # neato - see also K, weight, len, start, epsilon, Damping, diredgeconstraints, ...
    neatoOPTS="
    neato|E|len|1.
    neato|G|mode|major|KK|sgd|hier|ipsep
    neato|G|model|shortpath|mds|circuit|subset
    neato|G|overlap|false
    neato|G|sep|+5|+10"

    # fdp - see also weight, start & maxiter
    fdpOPTS="
    fdp|G|overlap|false
    fdp|G|sep|+5|+10
    fdp|G|K|.4|.8|1"

    # twopi - see also root & weight
    twopiOPTS="
    twopi|G|ranksep|.5|.75|1.2
    twopi|G|sep|+5|+10"

    # circo - see also root
    circoOPTS="
    circo|G|sep|+5|+10
    circo|G|mindist|.75|1.3"

    allOPTS="
    $dotOPTS
    $neatoOPTS
    $fdpOPTS
    $sfdpOPTS
    $twopiOPTS
    $circoOPTS
    $osageOPTS
    "

    (
    echo "$allOPTS"
    echo -e "$ADD"
    ) |
    gawk -F'|' -v "runEngines=$Engines" -v "files=$files" -vfmt="$T" '
    BEGIN{
    bar="|"
    sub(/^[ \t]*/, "", runEngines)
    split(runEngines, runEngine, "[ \t]")
    #File=file
    #sub(/\.[^.]*$/,"",File)
    split(files,file, "[ \t]")
    }
    /^#/ || NF<4{
    #print "NF:",NF,">" $0 "<"
    next
    }
    {
    ++Indx
    Inpt[Indx]=$0
    Eng[Indx]=$1
    Type[Indx]=$2
    Att[Indx]=$3
    #print "##", Eng[Indx], $0
    for (i=4;i<=NF;i++){
    cnt=i-3
    Val[$3,cnt]=$i
    }
    Vcnt[Indx]=cnt
    }
    END{
    for (x in file){
    File=file[x]
    sub(/\.[^.]*$/,"",File)
    for (R in runEngine){
    delete Combo
    delete Part
    for (I in Eng){
    if (Eng[I] == "*" || Eng[I] == runEngine[R]){
    for (J=1;J<=Vcnt[I];J++){
    this=" " Type[I] bar Att[I] bar Val[Att[I],J]
    # print"## this:",this
    if (1 in Part){
    for (p in Part){
    Combo[++cIndx]=Part[p] this
    }
    }else{ // first chunk
    Combo[++cIndx]=this
    }
    }
    delete Part
    #print"## combo:",combo
    for (i in Combo){
    Part[i]=Combo[i]
    delete Combo[i]
    cIndx=0
    }
    }
    }
    for (p in Part){
    cmd=runEngine[R] " -T" fmt " " file[x]
    lbl=file[x] " - " runEngine[R] "\\n"
    fName=File "." runEngine[R]
    cnt=split(Part[p], Chunk, " ")
    for (iX=1;iX<=cnt;iX++){
    c2=split(Chunk[iX], tok, "|")
    cmd=cmd " -" tok[1] tok[2] "=\"" tok[3] "\""
    lbl=lbl tok[2] "=" tok[3] " "
    fName=fName "." tok[2] "=" tok[3]
    }
    oFile=fName "." fmt
    Err=fName ".errs"
    print cmd " -Glabel=\"" lbl "\" -o \"" oFile "\""
    print ""
    }
    }
    }
    }'