#!/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=":"; n=0; if ( beamline != "" ) bl=beamline; else bl="FullMachine"; inst=sprintf("aidaget modelTwiss//Design.%s | areas",bl); while ((inst | getline result) > 0) if ( result != "" ) { areanames[m++]=result; } close(inst); M=m; for (i=0;i 0 ) { delete areaDevices; for (j=1;j<=(N[i]);j++ ) { indx=mkindx(area, units[area,j]); areaDevices[indx]=devices[area,j]; } n=asorti(areaDevices,d); for (v=1;v<=n;v++) print areaDevices[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 (l=length(unitnum); l<5; l++) { p=p "0" } return (area p unitnum); }