# generate_partition_binary.py import sys import struct import re def generate_binary_file(input_filepath, output_filepath): RECORD_FORMAT = '\d+)\s+ (?P\d+)\s+ (?P[\d\.]+) \s*\n (?P (?:^\s*(?:[\d.]+\s+){7}[\d.]+)\s*\n (?:^\s*(?:[\d.]+\s+){7}[\d.]+)\s*\n (?:^\s*(?:[\d.]+\s+){7}[\d.]+) ) """, re.MULTILINE | re.VERBOSE) with open(input_filepath, 'r') as f: content = f.read() record_count = 0 with open(output_filepath, 'wb') as f_out: for match in record_regex.finditer(content): z = int(match.group('z')) a = int(match.group('a')) spin = float(match.group('spin')) coeffs_str = match.group('coeffs') g_values = [float(val) for val in coeffs_str.split()] if len(g_values) != 24: print(f"Warning: Found {len(g_values)} coefficients for Z={z}, A={a}. Expected 24. Skipping.") continue packed_data = struct.pack(RECORD_FORMAT, z, a, spin, *g_values) f_out.write(packed_data) record_count += 1 print(f"Found and processed {record_count} records. Wrote to binary file {output_filepath}") if __name__ == "__main__": if len(sys.argv) != 3: print(f"Usage: python {sys.argv[0]} ") sys.exit(1) generate_binary_file(sys.argv[1], sys.argv[2])