diff --git a/conda/build.sh b/conda/build.sh index 6f7fe6695..11ce566a4 100644 --- a/conda/build.sh +++ b/conda/build.sh @@ -49,3 +49,7 @@ make default TACS_DIR=${TACS_DIR} \ SO_LINK_FLAGS="${F5TOVTK_SLF}" SO_EXT=${SO_EXT}; mv ./f5totec ${PREFIX}/bin; +cd ${TACS_DIR}/extern +mv ./f5convert ${PREFIX}/bin; +mv ./f5clean ${PREFIX}/bin; + diff --git a/docs/source/install.rst b/docs/source/install.rst index eb845280a..2d00f39f9 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -158,14 +158,19 @@ After compiling the C++ TACS library, go to the subdirectory ``tacs/extern/f5tov ``f5totec`` requires Tecplot's ``tecio`` library, the installation of which is described above. +The ``extern`` directory also contains two bash scripts, ``f5convert`` and ``f5clean``, that can be used to convert and clean ``.f5`` files. +``f5convert`` converts any ``.f5`` files that don't have an up-to-date ``.vtk`` or ``.plt`` file, and ``f5clean`` removes the ``.vtk`` or ``.plt`` file corresponding to each ``.f5`` file. +Both scripts accept a ``-s`` flag that will also convert or clean the ``.f5`` files in any subdirectories that contain ``.f5`` files. +Run ``f5convert -h`` or ``f5clean -h`` for more information. -It is useful to put these utilities on your path if possible. -I add the directory ``$HOME/bin`` to my ``PATH`` and then from the directory ``$HOME/bin`` execute +Add the following lines to your ``.bashrc`` file to add the executables to your path: :: - ln -s $HOME/git/tacs/extern/f5tovtk - ln -s $HOME/git/tacs/extern/f5totec + export PATH="/extern/f5totec:$PATH" + export PATH="/extern/f5tovtk:$PATH" + export PATH="/extern:$PATH" + Installing the python interface ------------------------------- diff --git a/extern/f5clean b/extern/f5clean new file mode 100755 index 000000000..bb7ee3b61 --- /dev/null +++ b/extern/f5clean @@ -0,0 +1,45 @@ +#!/bin/bash + +helpstring=" + +This command will look for all .f5 files in the current directory and delete any files with the same name but a +.plt, .szplt or .vtk extension, this is useful for clearing space on your filesystem by removing tecplot/paraview files +that can be regenerated from the f5 files when needed. It is also safer than simply running 'rm *.plt *.szplt *.vtk' as +it will only delete the files that can be regenerated from the f5 files. + +To clean up all files in the current directory: +> `basename $0` + +To also run recursively in all subdirectories that contain .f5 files: +> `basename $0` -s +" + +if [ "$1" == "-h" ]; then + echo "$helpstring" + exit 0 +fi + +subdirs=false +while [[ "$#" -gt 0 ]]; do case $1 in + -s|--subdirs) subdirs=true;; + *) echo "Unknown parameter passed: $1"; exit 1;; +esac; shift; done + +f5clean_all() { + for f in *.f5; do + for extension in plt szplt vtk; do + fileName="${f%.*}.$extension" + [ -e $fileName ] && echo "deleting $fileName" && rm -f ./$fileName + done + done +} + + +if [ $subdirs = true ] ; then + RootDir=$(pwd) + find . -iname '*.f5' -printf '%h\n' | sort -u | while read i; do + cd "$i" && pwd && f5clean_all ; cd "$RootDir" + done +else + f5clean_all +fi diff --git a/extern/f5convert b/extern/f5convert new file mode 100755 index 000000000..eec50eaec --- /dev/null +++ b/extern/f5convert @@ -0,0 +1,127 @@ +#!/bin/bash + +helpstring=" + +This command runs f5totec or f5tovtk in parallel on all .f5 files in the current directory + +Usage: + +To convert .f5 files in the current directory using all available procs: +> `basename $0` + +By default, `basename $0` will ignore any .f5 files for which there is a corresponding .plt file newer than the .f5 file +To convert all .f5 files overwriting existing files: +> `basename $0` -r + +To run on N procs: +> `basename $0` -n N + +To supress the echoing of which files will and won't be converted (does not supress f5totec's own output): +> `basename $0` -q + +To also run recursively in all subdirectories that contain .f5 files: +> `basename $0` -s + +To use f5tovtk instead of f5totec: +> `basename $0` --vtk + +This script uses GNU parallel which can be installed on debian using: +> sudo apt-get install parallel + + +" + +if [ "$1" == "-h" ]; then + echo "$helpstring" + exit 0 +fi + +if ! command -v parallel &> /dev/null +then + echo "parallel could not be found, please install it to use f5convert_all" + exit +fi + +# Parse input options +reconvert=false +quiet=false +vtk=false +subdirs=false +extra_args="" +nprocs=+0 +while [[ "$#" -gt 0 ]]; do case $1 in + -n|--nprocs) nprocs=$2; shift;; + -q|--quiet) quiet=true; shift;; + -r|--reconvert) reconvert=true; shift;; + -s|--subdirs) subdirs=true; shift;; + --vtk) vtk=true;; + *) echo "Unknown parameter passed: $1"; exit 1;; +esac; shift; done + +f5convert_all() { + + reconvert=$1 + quiet=$2 + vtk=$3 + nprocs=$4 + + for value in $reconvert $quiet $vtk $nprocs; do + echo $value + done + + if [ $vtk = true ] ; then + convertCommand=f5tovtk + else + convertCommand=f5totec + fi + + # Loop through all the f5 files in the current directory and figure out which ones to convert + filesToConvert=() + for f in *.f5; + do + if [ $reconvert = true ] || ([ "$vtk" = false ] && [ ! -f "${f%.*}.plt" ] && [ ! -f "${f%.*}.szplt" ]) || ([ "$vtk" = true ] && [ ! -f "${f%.*}.vtk" ]) ; then + # If there is not .plt/.szplt/.vtk file corresponding to the current .f5 or is user specified -r then convert the file + filesToConvert[${#filesToConvert[@]}]=$f + echo "$f" 'will be converted' + elif [ -f "${f%.*}.plt" ] && [ "$vtk" = false ] ; then + if [ "${f%.*}.plt" -ot "$f" ] ; then + # If there is a .plt file but it's older than the corresponding .f5 file then convert the .f5 file + echo "$f" 'will be converted as it is newer than' "${f%.*}.plt" + filesToConvert[${#filesToConvert[@]}]=$f + else + echo "$f" 'will not be converted as' "${f%.*}.plt" 'already exists, to force overwriting use the -r flag' + fi + elif [ -f "${f%.*}.szplt" ] && [ "$vtk" = false ] ; then + if [ "${f%.*}.szplt" -ot "$f" ] ; then + # If there is a .szplt file but it's older than the corresponding .f5 file then convert the .f5 file + echo "$f" 'will be converted as it is newer than' "${f%.*}.szplt" + filesToConvert[${#filesToConvert[@]}]=$f + else + echo "$f" 'will not be converted as' "${f%.*}.szplt" 'already exists, to force overwriting use the -r flag' + fi + elif [ -f "${f%.*}.vtk" ] && [ "$vtk" = true ] ; then + if [ "${f%.*}.vtk" -ot "$f" ] ; then + # If there is a .vtk file but it's older than the corresponding .f5 file then convert the .f5 file + echo "$f" 'will be converted as it is newer than' "${f%.*}.vtk" + filesToConvert[${#filesToConvert[@]}]=$f + else + echo "$f" 'will not be converted as' "${f%.*}.vtk" 'already exists, to force overwriting use the -r flag' + fi + fi + done + + # Do the conversion + for f in "${filesToConvert[@]}"; + do + echo "$f" + done | parallel --will-cite -j$nprocs $convertCommand {} +} + +if [ $subdirs = true ] ; then + RootDir=$(pwd) + find . -iname '*.f5' -printf '%h\n' | sort -u | while read i; do + cd "$i" && pwd && f5convert_all $reconvert $quiet $vtk $nprocs ; cd "$RootDir" + done +else + f5convert_all $reconvert $quiet $vtk $nprocs +fi diff --git a/extern/f5totec/f5convert b/extern/f5totec/f5convert deleted file mode 100644 index fa1485964..000000000 --- a/extern/f5totec/f5convert +++ /dev/null @@ -1,13 +0,0 @@ -if [ $# -lt 1 ] ; then -cat <