code: def msregularize(msname, newname):
      t = table(msname)
      t1 = t.sort('unique ANTENNA1,ANTENNA2')
      nadded = 0
      for tsub in t.iter(['TIME', 'DATA_DESC_ID']):
          nmissing = t1.nrows() - tsub.nrows()
          if nmissing < 0:
              raise ValueError("A time/band chunk has too many rows")
          if nmissing > 0:
              ant1 = str(t1.getcol('ANTENNA1')).replace(' ', ',')
              ant2 = str(t1.getcol('ANTENNA2')).replace(' ', ',')
              ant1 = tsub.getcol('ANTENNA1')
              ant2 = tsub.getcol('ANTENNA2')
              t2 = taql('select from $t1 where !any(ANTENNA1 == $ant1 &&' +
                        ' ANTENNA2 == $ant2)')
              six.print_(nmissing, t1.nrows(), tsub.nrows(), t2.nrows())
              if t2.nrows() != nmissing:
                  raise ValueError("A time/band chunk behaves strangely")
              if nadded == 0:
                  tnew = t2.copy(newname + "_add", deep=True)
                  tnew = table(newname + "_add", readonly=False)
              else:
                  t2.copyrows(tnew)
              tnew.putcell('TIME',
                           range(nadded, nadded + nmissing),
                           tsub.getcell('TIME', 0))
              tnew.putcell('DATA_DESC_ID',
                           range(nadded, nadded + nmissing),
                           tsub.getcell('DATA_DESC_ID', 0))
              nadded += nmissing
      if nadded > 0:
          taql('update $tnew set DATA=0+0i')
          taql('update $tnew set FLAG=True')
          tcomb = table([t, tnew])
          tcomb.rename(newname + '_adds')
          tcombs = tcomb.sort('TIME,DATA_DESC_ID,ANTENNA1,ANTENNA2')
      else:
          tcombs = t.query(offset=0)
      tcombs.rename(newname)
      six.print_(newname, 'has been created; it references the original MS')
      if nadded > 0:
          six.print_(' and', newname + '_adds', 'containing', nadded, 'new rows')
      else:
          six.print_(' no rows needed to be added')