#!/home/conda/feedstock_root/build_artifacts/bld/rattler-build_pyne_1778004878/host_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/bin/python3.13
import argparse

from pyne.mcnp import Meshtal

def main():
    parser = argparse.ArgumentParser(description=(
             'Reads an MCNP meshtal file and creates an h5m mesh file '
             'for each meshtally within the file. The output mesh files are '
             'named <filename>_tally_<tally_num>.h5m. Note that this script '
             'only works for Cartesian meshes, and only with the default '
             'setting for OUT=COL format.'))
    parser.add_argument('filename', help='Name of the MCNP meshtal file.')
    parser.add_argument('-o', dest='output', 
                        help=('Base name of the output files:  output files '
                              'will be named <output>_tally_<tally_num>.h5m'))

    args = parser.parse_args()
    m = Meshtal(args.filename)
    output = args.output if args.output is not None else args.filename
    for num, tal in m.tally.items():
        tal.write_hdf5("{0}_tally_{1}.h5m".format(output, num))

if __name__ == '__main__':
    main()
