From c76e77f7f89566b7ab6d88d74d929f7fc2bbc4bf Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sun, 17 Dec 2017 23:43:46 -0500 Subject: [PATCH] Use argparse choices for libver in xsgen scripts --- scripts/openmc-ace-to-hdf5 | 19 ++++++++----------- scripts/openmc-convert-mcnp70-data | 15 ++++++--------- scripts/openmc-convert-mcnp71-data | 13 +++++-------- scripts/openmc-get-jeff-data | 15 ++++++--------- scripts/openmc-get-nndc-data | 16 ++++++++-------- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/scripts/openmc-ace-to-hdf5 b/scripts/openmc-ace-to-hdf5 index d6b7468901..3235a2da63 100755 --- a/scripts/openmc-ace-to-hdf5 +++ b/scripts/openmc-ace-to-hdf5 @@ -57,9 +57,10 @@ parser.add_argument('--xsdata', help='Serpent xsdata file that lists ' 'ACE libraries') parser.add_argument('--fission_energy_release', help='HDF5 file containing ' 'fission energy release data') -parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for ' - 'performance over backwards compatibility', - action='store_true') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() if not os.path.isdir(args.destination): @@ -121,10 +122,6 @@ else: nuclides = {} library = openmc.data.DataLibrary() -if args.latest_hdf5: - libver = 'latest' -else: - libver = 'earliest' for filename in ace_libraries: # Check that ACE library exists @@ -158,7 +155,7 @@ for filename in ace_libraries: # Determine filename outfile = os.path.join(args.destination, neutron.name.replace('.', '_') + '.h5') - neutron.export_to_hdf5(outfile, 'w', libver=libver) + neutron.export_to_hdf5(outfile, 'w', libver=args.libver) # Register with library library.register_file(outfile) @@ -174,7 +171,7 @@ for filename in ace_libraries: .format(table.name, neutron.name)) neutron.add_temperature_from_ace(table, args.metastable) neutron.export_to_hdf5(nuclides[name] + '_1', 'w', - libver=libver) + libver=args.libver) os.rename(nuclides[name] + '_1', nuclides[name]) except Exception as e: print('Failed to convert {}: {}'.format(table.name, e)) @@ -196,7 +193,7 @@ for filename in ace_libraries: # Determine filename outfile = os.path.join(args.destination, thermal.name.replace('.', '_') + '.h5') - thermal.export_to_hdf5(outfile, 'w', libver=libver) + thermal.export_to_hdf5(outfile, 'w', libver=args.libver) # Register with library library.register_file(outfile) @@ -213,7 +210,7 @@ for filename in ace_libraries: .format(table.name,thermal.name)) thermal.add_temperature_from_ace(table) thermal.export_to_hdf5(nuclides[name] + '_1', 'w', - libver=libver) + libver=args.libver) os.rename(nuclides[name] + '_1', nuclides[name]) except Exception as e: print('Failed to convert {}: {}'.format(table.name, e)) diff --git a/scripts/openmc-convert-mcnp70-data b/scripts/openmc-convert-mcnp70-data index 0618e51ead..0489b25de4 100755 --- a/scripts/openmc-convert-mcnp70-data +++ b/scripts/openmc-convert-mcnp70-data @@ -26,9 +26,10 @@ parser = argparse.ArgumentParser( ) parser.add_argument('-d', '--destination', default='mcnp_endfb70', help='Directory to create new library in') -parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for ' - 'performance over backwards compatibility', - action='store_true') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") parser.add_argument('mcnpdata', help='Directory containing endf70[a-k] and endf70sab') args = parser.parse_args() assert os.path.isdir(args.mcnpdata) @@ -41,10 +42,6 @@ if not os.path.isdir(args.destination): os.mkdir(args.destination) library = openmc.data.DataLibrary() -if args.latest_hdf5: - libver = 'latest' -else: - libver = 'earliest' for path in sorted(endf70): print('Loading data from {}...'.format(path)) @@ -69,7 +66,7 @@ for path in sorted(endf70): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w', libver=libver) + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) @@ -98,7 +95,7 @@ if os.path.exists(endf70sab): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w', libver=libver) + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-convert-mcnp71-data b/scripts/openmc-convert-mcnp71-data index fe4b063684..061f8f46f0 100755 --- a/scripts/openmc-convert-mcnp71-data +++ b/scripts/openmc-convert-mcnp71-data @@ -28,9 +28,10 @@ parser.add_argument('-d', '--destination', default='mcnp_endfb71', help='Directory to create new library in') parser.add_argument('-f', '--fission_energy_release', help='HDF5 file containing fission energy release data') -parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for ' - 'performance over backwards compatibility', - action='store_true') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") parser.add_argument('mcnpdata', help='Directory containing endf71x and ENDF71SaB') args = parser.parse_args() assert os.path.isdir(args.mcnpdata) @@ -54,10 +55,6 @@ if not os.path.isdir(args.destination): os.mkdir(args.destination) library = openmc.data.DataLibrary() -if args.latest_hdf5: - libver = 'latest' -else: - libver = 'earliest' for basename, xs_list in sorted(suffixes.items()): # Convert first temperature for the table @@ -87,7 +84,7 @@ for basename, xs_list in sorted(suffixes.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w', libver=libver) + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-get-jeff-data b/scripts/openmc-get-jeff-data index a8fb64acb5..6d9e086a91 100755 --- a/scripts/openmc-get-jeff-data +++ b/scripts/openmc-get-jeff-data @@ -43,9 +43,10 @@ parser.add_argument('-b', '--batch', action='store_true', help='supresses standard in') parser.add_argument('-d', '--destination', default='jeff-3.2-hdf5', help='Directory to create new library in') -parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for ' - 'performance over backwards compatibility', - action='store_true') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() response = input(download_warning) if not args.batch else 'y' @@ -168,10 +169,6 @@ if not os.path.isdir(args.destination): os.mkdir(args.destination) library = openmc.data.DataLibrary() -if args.latest_hdf5: - libver = 'latest' -else: - libver = 'earliest' for name, filenames in sorted(tables.items()): # Convert first temperature for the table @@ -186,7 +183,7 @@ for name, filenames in sorted(tables.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w', libver=libver) + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) @@ -229,7 +226,7 @@ for name, filenames in sorted(tables.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w', libver=libver) + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-get-nndc-data b/scripts/openmc-get-nndc-data index 43a528b415..e2c1e7ce3a 100755 --- a/scripts/openmc-get-nndc-data +++ b/scripts/openmc-get-nndc-data @@ -33,9 +33,10 @@ parser = argparse.ArgumentParser( ) parser.add_argument('-b', '--batch', action='store_true', help='supresses standard in') -parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for ' - 'performance over backwards compatibility', - action='store_true') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() @@ -160,8 +161,7 @@ fer_file = os.path.join(data_dir, 'fission_Q_data_endfb71.h5') # Call the ace-to-hdf5 conversion script pwd = os.path.dirname(os.path.realpath(__file__)) ace2hdf5 = os.path.join(pwd, 'openmc-ace-to-hdf5') -args_out = [ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release', fer_file] -if args.latest_hdf5: - args_out += ['--latest_hdf5'] -args_out += ace_files -subprocess.call(args_out) +subprocess.call([ace2hdf5, + '-d', 'nndc_hdf5', + '--fission_energy_release', fer_file, + '--libver', args.libver] + ace_files)