Skip to content

Commit

Permalink
Add helper scripts for creating and deleting large numbers of tecplot…
Browse files Browse the repository at this point in the history
… files (#225)

* Add helper scripts for creating and deleting tecplot files

* Clean up `f5convert_all`

* Condense to 1 script for conversion and 1 for cleaning, add option to use f5tovtk

* Add some content to the docs

* Convert tabs to spaces

* Adding f5convert/f5clean to conda build

* Increasing max ci runtime

---------

Co-authored-by: Tim Brooks <41971846+timryanb@users.noreply.github.com>
  • Loading branch information
A-CGray and timryanb authored Jul 28, 2023
1 parent c63c1ce commit 888061a
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 17 deletions.
4 changes: 4 additions & 0 deletions conda/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

13 changes: 9 additions & 4 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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="<path to the tacs directory>/extern/f5totec:$PATH"
export PATH="<path to the tacs directory>/extern/f5tovtk:$PATH"
export PATH="<path to the tacs directory>/extern:$PATH"


Installing the python interface
-------------------------------
Expand Down
45 changes: 45 additions & 0 deletions extern/f5clean
Original file line number Diff line number Diff line change
@@ -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
127 changes: 127 additions & 0 deletions extern/f5convert
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions extern/f5totec/f5convert

This file was deleted.

0 comments on commit 888061a

Please sign in to comment.