#!/bin/bash #------------------------------------------------------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. #------------------------------------------------------------------------------- # License # This file is part of OpenFOAM. # # OpenFOAM is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with OpenFOAM. If not, see . # # Script # foamExec # # Description # Usage: foamExec [-version=foamVersion] ... # # Runs the version of executable # with the rest of the arguments. # # Can also be used for parallel runs. For example, # \code # mpirun -np \ # foamExec -version=VERSION ... -parallel # \endcode # # Note # This script must exist in $WM_PROJECT_INST_DIR/OpenFOAM-/bin # or $WM_PROJECT_INST_DIR/openfoam/bin (debian) # # foamEtcFile located in the same directory as this script # # See also # foamEtcFile # #------------------------------------------------------------------------------ usage() { exec 1>&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat< ... options: -mode=MODE Any combination of u(user), g(group), o(other) -prefix=DIR Specify an alternative installation prefix pass through to foamEtcFile -version=VER Specify alternative OpenFOAM version (eg, 3.0, 1612, ...) pass through to foamEtcFile -help Print the usage Run a particular OpenFOAM version of USAGE exit 1 } #------------------------------------------------------------------------------- binDir="${0%/*}" # The bin dir projectDir="${binDir%/bin}" # The project dir # prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR) projectVersion="${WM_PROJECT_VERSION:-unknown}" unset etcOpts # parse options while [ "$#" -gt 0 ] do case "$1" in -h | -help*) usage ;; -mode=*) etcOpts="$etcOpts $1" # pass-thru to foamEtcFile ;; -prefix=/*) etcOpts="$etcOpts $1" # pass-thru to foamEtcFile ;; -version=*) etcOpts="$etcOpts $1" # pass-thru to foamEtcFile projectVersion="${1#*=}" # for reporting ;; -m | -mode) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile shift ;; -p | -prefix) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile shift ;; -v | -version) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile projectVersion="$2" # for reporting shift ;; --) shift break ;; -*) usage "invalid option '$1'" ;; *) break ;; esac shift done # Find and source the OpenFOAM # placed in function to preserve command-line arguments sourceBashrc() { rcFile="$($binDir/foamEtcFile $etcOpts bashrc)" || { echo "Error: bashrc file could not be found for OpenFOAM-$projectVersion" 1>&2 exit 2 } . $rcFile $FOAM_SETTINGS } [ "$#" -ge 1 ] || usage "no application specified" sourceBashrc exec "$@" #------------------------------------------------------------------------------