Skip to content
Merged
23 changes: 18 additions & 5 deletions docs/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,28 @@ To generate the library file from the collection of raw ACE files one can use th

.. code-block:: bash

./scripts/make_ace_lib.sh /path/lib.xsfile CE ./path_to_ace_files/*.ace
./scripts/make_ace_lib.sh <output> <MODE> <search_keyword> <path_to_base_folder>

To get extra help run the script without any arguments. In the line above, <output> is the file that
will be created; <MODE> can be either ``CE`` for continuous energy neutron data cards and ``SAB`` for
thermal scattering S(α,β) cards; <search_keyword> will restrict the search to files that include this
keyword in their name; <path_to_base_folder> is the path to the folder than contains the ace files.
The script can search recursively inside folder structures too.

Some useful choices for the input <search_keyword> could be: ``ace``, ``nc`` (e.g., for ENDFB/VIII.0),
``t`` for thermal scattering data, ``sssth`` for the Serpent thermal scattering file, or ``'*'`` to
search all files available in the path specified. Some example calls are:

.. code-block:: bash

./scripts/make_ace_lib.sh ./endfb8.aceXS CE nc ./Lib80x/
./scripts/make_ace_lib.sh ./jeff40.aceXS CE '*' ./JEFF40/

To get extra help run the script without any arguments. The ``CE`` letters allow to select between
searching for continuous energy neutron data cards and thermal scattering S(α,β) cards (SAB mode).
Sadly the script can search only for a single type of card in one pass. Thus to create a full
library with thermal data we need to do the following:

.. code-block:: bash

./scripts/make_ace_lib.sh ./tempCE CE ./path_to_CE_ace_files/*.ace
./scripts/make_ace_lib.sh ./tempSAB SAB ./path_to_SAB_ace_files/*.ace
./scripts/make_ace_lib.sh ./tempCE CE ace ./path_to_CE_ace_files/
./scripts/make_ace_lib.sh ./tempSAB SAB t ./path_to_SAB_ace_files/
cat tempCE tempSAB > fullLib.xsfile
56 changes: 36 additions & 20 deletions scripts/make_ace_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,40 @@

HELP="Create a SCONE nuclear data library file from raw ACE Neutron CE files.

make_ace_lib.sh <output> <MODE> <ace-file>+
make_ace_lib.sh <output> <MODE> <search-word> <path-to-directory>

Arguments:
<output> Library file to create.
<MODE> Choose tosearch for CE Neutron cards (ZZAAA.TTc id). or SAB cards (XXXXXX.TTt)
<ace-files> List of files to search for the ID pattern

The script searches each of the <ace-file> for a presence of an ID pattern (ZZAAA.TTc for CE;
XXXXXX.TTt for SAB card) at a beginning of the line. By ACE definition this should match only
a first line of a header of an ACE card. For each match the script prints a line of the SCONE
nuclear data library file to <output> as:
<output> Library file to create.
<MODE> Choose tosearch for CE Neutron cards (ZZAAA.TTc id). or SAB cards (XXXXXX.TTt)
<search-word> Keyword expected within the name of the ace files (e.g., ace, nc, t, ENDF, sssth)
<path-to-directory> Path of the base directory where to search in

The script recursively searches inside <path-to-directory> for files with a name that includes the given
common <search-word>; in each file, it searches for the presence of an ID pattern (ZZAAA.TTc for CE;
XXXXXX.TTt for SAB card) within the first line. By ACE definition this should match only in the first
line of a header of an ACE card. For each match the script prints a line of the SCONE nuclear data library
file to <output> as:
ZAID; LINE_NUMBER; FILE;
...
"

# Display help if number of arguments is wrong
if [ $# -le 2 ]; then
if [ $# -ne 4 ]; then
echo "${HELP}"
exit 1
fi

# Pop first argument to be the library file
OUTNAME=$1
MODE=$2
shift 2
WORD=$3
SEARCH_DIR=$4

# Check a path to directory is given correctly
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: '$SEARCH_DIR' is not a directory"
exit 1
fi

# If file already exists ask for confirmation and remove it
if [ -f $OUTNAME ]; then
Expand All @@ -38,19 +47,26 @@ if [ -f $OUTNAME ]; then
rm $OUTNAME
fi

FILES=()
while IFS= read -r -d '' f; do
FILES+=("$f")
done < <(
find "$SEARCH_DIR" -type f -name "*${WORD}*" -print0
)

if [ "${#FILES[@]}" -eq 0 ]; then
echo "No files with format '*${WORD}*' found in ${SEARCH_DIR}"
exit 1
fi

# Process each ACE file with awk
for var in $@
for var in "${FILES[@]}";
do
if [ ! -f $var ]; then
echo -e "File '${var}' does not exist \U0001F61E"
echo -e "Quitting \U0001F44B"
exit 1
fi

# We need full path to put in the file
FULL_PATH=$(realpath $var)
FULL_PATH=$(realpath "$var")
echo "Processing file $var"

echo "Processing file ${var}"
if [[ $MODE =~ ^CE$ ]]; then
awk -v FILE=$FULL_PATH \
'/^[[:space:]]*[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]?.[[:digit:]][[:digit:]]c/\
Expand All @@ -66,4 +82,4 @@ do
exit 1
fi

done
done