code to produce pattuples