#!/bin/awk -f # # zort sorts a file of EPICS PVs by their assumed location in the beamline. # # Usage: # zort file Sorts PV names in file. # # e.g. aidalist VGCC:%:P | zort Sorts the output of aidalist # # It bases the sort on knowledge of the order of beamline regions, and # the assumption that beamline order will be implied by unit number. # The PV names must be of the form :::. # # zort specifically does not match non-LCLS areas, eg FEEn, NEHn. So, # for instance "aidalist VGCC:%:P | zort" will filter out non-LCLS PVs. # # zort is only alphanumeric on unit number. That is, 5 sorts < 45, # and P1 sorts < 999. This is an extract for BSY0: # VGCC:BSY0:5:P # VGCC:BSY0:45:P # VGCC:BSY0:95:P # VGCC:BSY0:P0:P # VGCC:BSY0:P3:P # VGCC:BSY0:999:P # # Programming note: To make 45 sort < 5, use asort (not asorti) and # remove use of mkindx. Just index arrays by $3. # BEGIN { FS=":" } $2~/^IN/ { indx=mkindx($2, $3); inj[indx] = $0; next; } $2~/^LI/ { indx=mkindx($2, $3); li[indx] = $0; next; } $2~/^BSY/ { indx=mkindx($2, $3); bsy[indx] = $0; next; } $2~/^LTU/ { indx=mkindx($2, $3); ltu[indx] = $0; next; } $2~/^UND/ { indx=mkindx($2, $3); und[indx] = $0; next; } $2~/^DMP/ { indx=mkindx($2, $3); dmp[indx] = $0; next; } END { n=asorti(inj,d); for ( v=1;v<=n;v++) print inj[d[v]]; n=asorti(li,d); for ( v=1;v<=n;v++) print li[d[v]]; n=asorti(bsy,d); for ( v=1;v<=n;v++ ) print bsy[d[v]]; n=asorti(ltu,d); for ( v=1;v<=n;v++ ) print ltu[d[v]]; n=asorti(und,d); for ( v=1;v<=n;v++ ) print und[d[v]]; n=asorti(dmp,d); for ( v=1;v<=n;v++ ) print dmp[d[v]]; } function mkindx(area, unitnum) # Constructs the index of the form: # <0padding>. This is necessary because you want to # sort alphanumerically by area, but then sort unit first numerically # among the numerical units, and then alphanumerically on unit # number. Without this, for instance, VGCC:BSY0:5:P would sort greater # than VGCC:BSY0:45:P. And you have to include area, since otherwise # VGCC:BSYA:P5:P would sort ahead of VGCC:BSY0:999:P. If all area # are not of the same length, then there will be more games to play. # { p = ""; for (i=length(unitnum); i<5; i++) { p=p "0" } return (area p unitnum); }