#!/usr/bin/awk -f ## ## Does its best to group array of instances in a spice netlist ## XA[2] ... ## XA[1] ... ## XA[0] ... ## --> XA[2:0] ... ## instances that can be grouped must be of subckts with no bussed ports ## run this script before importing a netlist into xschem with make_sch_from_spice.awk ## ## usage: ~/xschem/netlist_compactor.awk netlist > netlist.compact ## ## stefan, 20161226 BEGIN{ #print compact_label("A[3],A[3],A[3],A[4],A[5],A[6],A[6],A[6],A[6],A[8],A[7],A[7],A[9],A[8],A[7],A[11],A[13]") ## 3*A[3],A[4:6],3*A[6],A[8:7],A[7],A[9:7],A[11],A[13] #exit ########################## JOIN ########################## netlist_lines=0 first=1 while(err= (getline l) >0) { gsub(//,"]",l) if(first) { $0=l first=0 } else if(l !~/^\+/) { netlist[netlist_lines++]=$0 $0=l } else $0 = $0 " " substr(l,2) } netlist[netlist_lines++]=$0 ########################## END JOIN ########################## for(i=0;i1) { ## ---------20170308---------- if( (curr_line_arr[1] ~/^X/) && lab_name(curr_line_arr[1]) == lab_name(prev_line_arr[1]) ) { for(j=1;j<=nf;j++) { if( j0 ? a: -a } # 1 2 3 4 5 6 7 8 9 10 11 12 # PP A[3] A[2] A[1] B C K[10] K[9] K[5] K[4] K[3] K[1] function compact_label(str, a, b, ar, ret,start,i) { # print "compact_label_str(): str=" str a=1 b=split(str, ar,",") ret="" for(i=a;i<=b;i++) { if(i==a) {start=a} else { if(ar[i-1] !~ /\[/) { if(ar[i-1] != ar[i]) { if(start < i-1) { ret = ret (i-start) "*" ar[i-1] ","; start=i } else {ret = ret ar[i-1] ","; start=i } } } else if(lab_name(ar[i])!=lab_name(ar[i-1])) { # lab basename changed if(start