#! /bin/csh -f
# Last edited on 2001-11-17 20:46:06 by stolfi

set usage = "$0 AFILE BFILE > DFILE"

set cmd = "$0"

# Writes to standard output a candidate file containing all candidates
# in AFILE that do not have a candidate in BFILE with same curve pair.

set Afile = "$1"; shift
set Bfile = "$1"; shift

set Apairs = "/tmp/$$-A.pairs"
set Bpairs = "/tmp/$$-B.pairs"
set Dpairs = "/tmp/$$-D.pairs"
set Dfile = "/tmp/$$-D.cands"

cat ${Afile} \
  | gawk '/^ *[0-9]/ { printf "%03s %03d\n", $1, $6;}' \
  | sort | uniq \
  > ${Apairs}

cat ${Bfile} \
  | gawk '/^ *[0-9]/ { printf "%03s %03s\n", $1, $6;}' \
  | sort | uniq \
  > ${Bpairs}
  
bool 1-2 ${Apairs} ${Bpairs} > ${Dpairs}

cat ${Afile} \
  | gawk -v tb=${Dpairs} \
      ' BEGIN { \
          split("", dic); \
          while(getline lin < tb) \
            { split(lin,fld); dic[fld[1],fld[2]]=1; } \
        } \
        /^ *[0-9]/{ \
          a = sprintf($1, "%03d"); b = sprintf($6, "%03d"); \
          if(dic[a,b]) { print; } \
          next; \
        } \
      ' \
  > ${Dfile}

cat <<EOF
begin PZCandidate.List (format of 99-07-25)
| Last edited on DATE TIME by USER
|
| generated by ${cmd:t} ${Afile} ${Bfile}
| 
candidates = `cat ${Dfile} | wc -l`
`cat ${Afile} | egrep '^lambda'`
EOF
cat ${Dfile}
cat <<EOF
end PZCandidate.List
EOF



