116 parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
117 parser.add_argument("input", help="field map to read")
118 parser.add_argument("-o", "--output", help="field map to write (omit to only report)")
119 parser.add_argument(
120 "--data-order",
121 choices=("auto", *fmt.ORDERS),
122 default="auto",
123 help="ordering of the input; auto requires the coordinates and the field to agree",
124 )
125 parser.add_argument(
126 "--check-only",
127 action="store_true",
128 help="report on the input and exit non-zero unless it is already canonical",
129 )
130 args = parser.parse_args()
131
132 rng = fmt.read_range(args.input)
133 field = fmt.read_field(args.input, rng=rng)
134
135 print(f"{args.input}:")
136 from_field = describe(args.input, rng, field)
137
138 if args.check_only:
139 residuals = fmt.coord_residuals(args.input, rng)
140
141 canonical = from_field != "yslow" and residuals is not None and max(residuals) < 0.5
142 print(" verdict " + ("canonical" if canonical else "NEEDS REPACKING"))
143 return 0 if canonical else 1
144
145 if not args.output:
146 parser.error("give --output, or --check-only to just report")
147
148 order = resolve_order(args.input, rng, field, args.data_order)
149 print(f"Reading {args.input} as {order} and writing {args.output}")
150 fmt.canonicalise(args.input, args.output, order=order, rng=rng)
151
152 print(f"{args.output}:")
153 written = fmt.read_field(args.output)
154 describe(args.output, fmt.read_range(args.output), written)
155 before, after = checksum(args.input), checksum(args.output)
156 print(f" field contents {before} -> {after} ({'unchanged' if before == after else 'reordered'})")
157 return 0
158
159