Last active
December 11, 2017 17:23
-
-
Save tueda/e5aa5414c2623ef021e5adc09e8feb55 to your computer and use it in GitHub Desktop.
Runs minos in a one-liner. #bin #sh #minos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# @minos.sh | |
# | |
# Wrapper script for minos database. | |
# | |
set -eu | |
# The program name. | |
prog=`basename "$0"` | |
# Prints the absolute path. | |
abs_path() {( | |
if [ ! -f "$1" ]; then | |
echo "$prog: \"$1\" not found" >&2 | |
exit 1 | |
fi | |
rel_dir=`dirname "$1"` | |
abs_dir=`cd "$rel_dir"; pwd` | |
fname=`basename "$1"` | |
echo "$abs_dir/$fname" | |
)} | |
# Prints the usage. | |
print_usage() { | |
cat << END | |
Usage: | |
$prog help | |
$prog makedia <process.h> <processdia.dat> | |
$prog makeres [<n>] <processdia.dat> <processres.dat> [options..] | |
$prog remakeres [<n>] <processdia.dat> <processres.dat> [options..] | |
$prog load <process.h> <processdia.dat> | |
$prog run <processdia.dat> <processres.dat> [options..] | |
$prog sum [<n>] <processres.dat> [options..] | |
$prog touch <processdia.dat> [options..] | |
$prog show <processdia/res.dat> [options..] | |
$prog merge <infile1> <infile2> <outfile> | |
Options: | |
-m<nprocesses>, -m<nprocesses>x<nthreads> -f<nthreads> | |
Specify the resources. | |
<NAME>=<value>, <n1>[-<n2>] | |
Specify database entries. (makedia,makeres,remakeres,run,sum,touch,show) | |
<VAR1>[,VAR2,...] | |
Specify variables. (show) | |
END | |
} | |
# Check the command. | |
if [ $# -lt 1 ]; then | |
print_usage | |
exit 1 | |
fi | |
cmd=$1 | |
shift | |
VARIETY=0 | |
case $cmd in | |
makeres|remakeres|sum) | |
# Check the variety (optional). | |
if [ $# -ge 1 ]; then | |
case $1 in | |
0|3|4|5|6|7|8) | |
VARIETY=$1 | |
shift | |
esac | |
fi | |
;; | |
esac | |
case $cmd in | |
help) | |
print_usage | |
exit 0 | |
;; | |
sum|touch|show) | |
if [ $# -lt 1 ]; then | |
echo "$prog: error: wrong number of arguments: $cmd $*" >&2 | |
print_usage | |
exit 1 | |
fi | |
;; | |
makedia|makeres|remakeres|load|run) | |
if [ $# -lt 2 ]; then | |
echo "$prog: error: wrong number of arguments: $cmd $*" >&2 | |
print_usage | |
exit 1 | |
fi | |
;; | |
merge) | |
if [ $# -lt 3 ]; then | |
echo "$prog: error: wrong number of arguments: $cmd $*" >&2 | |
print_usage | |
exit 1 | |
fi | |
;; | |
*) | |
echo "$prog: error: unrecognized command: $cmd" >&2 | |
exit 1 | |
;; | |
esac | |
# Determine the path to minos. | |
if [ -z "${MINOS:-}" ]; then | |
if [ -f ./minos ]; then | |
# Priority goes to qgraf in the current directory. | |
MINOS=./minos | |
else | |
# Hopefully in $PATH. | |
MINOS=minos | |
fi | |
fi | |
# Convert it into the absolute path when it looks like a relative path. | |
case "$MINOS" in | |
*/*) | |
if [ -f "$MINOS" ]; then | |
MINOS=`abs_path "$MINOS"` | |
fi | |
;; | |
esac | |
# Temporary file name. | |
tmpfile="${TMPDIR:-/tmp}/minosrun$$" | |
trap 'rm -f "$tmpfile"' 0 1 2 13 15 | |
RANGE= | |
SPEC= | |
VARS=@ | |
MINOSOPT= | |
parse_args() { | |
for a in "$@"; do | |
unused=false | |
case $a in | |
-f*|-m*|-b*) | |
MINOSOPT="$MINOSOPT $a" | |
;; | |
*=*) | |
case $cmd in | |
makedia|load|merge) | |
unused=: | |
;; | |
esac | |
SPEC="$SPEC $a" | |
;; | |
?*-?*) | |
case $cmd in | |
makedia|load|merge) | |
unused=: | |
;; | |
esac | |
RANGE="[$a]" | |
;; | |
''|*[!0-9]*) | |
case $cmd in | |
makedia|load|makeres|remakeres|run|sum|touch|merge) | |
unused=: | |
;; | |
esac | |
VARS=$a | |
;; | |
*) | |
case $cmd in | |
makedia|load|merge) | |
unused=: | |
;; | |
esac | |
RANGE="[$a-$a]" | |
;; | |
esac | |
if $unused; then | |
echo "$prog: Warning: \"$a\" unused" >&2 | |
fi | |
done | |
if [ "$VARS" != "@" ]; then | |
VARS="($VARS)" | |
fi | |
} | |
case $cmd in | |
makedia|load) | |
infile=$1 | |
outfile=$2 | |
shift | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
output "$outfile" | |
load "$outfile" "$infile" "DIA" fold | |
end | |
END | |
;; | |
makeres) | |
infile=$1 | |
outfile=$2 | |
shift | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile" | |
output "$outfile" | |
make 0 "$infile" "$outfile" (VALUE) $RANGE $SPEC | |
sum $VARIETY "$outfile" $RANGE $SPEC | |
sum 1 "$outfile" $RANGE $SPEC | |
sum 2 "$outfile" $RANGE $SPEC | |
end | |
END | |
;; | |
remakeres) | |
infile=$1 | |
outfile=$2 | |
shift | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile" | |
output "$outfile" | |
touch "$infile" $RANGE @ $SPEC | |
make 0 "$infile" "$outfile" (VALUE) $RANGE $SPEC | |
sum $VARIETY "$outfile" $RANGE $SPEC | |
sum 1 "$outfile" $RANGE $SPEC | |
sum 2 "$outfile" $RANGE $SPEC | |
end | |
END | |
;; | |
run) | |
infile=$1 | |
outfile=$2 | |
shift | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile" | |
output "$outfile" | |
make 0 "$infile" "$outfile" (VALUE) $RANGE $SPEC | |
end | |
END | |
;; | |
sum) | |
infile=$1 | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile" | |
sum $VARIETY "$infile" $RANGE $SPEC | |
sum 1 "$infile" $RANGE $SPEC | |
sum 2 "$infile" $RANGE $SPEC | |
end | |
END | |
;; | |
touch) | |
outfile=$1 | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
output "$outfile" | |
touch "$outfile" $RANGE @ $SPEC | |
end | |
END | |
;; | |
show) | |
infile=$1 | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile" | |
show "$infile" $RANGE $VARS $SPEC | |
end | |
END | |
;; | |
merge) | |
infile1=$1 | |
infile2=$2 | |
outfile=$3 | |
shift | |
shift | |
shift | |
parse_args "$@" | |
cat <<END >$tmpfile | |
input "$infile1" | |
input "$infile2" | |
output "$outfile" | |
merge "$infile1" "$infile2" "$outfile" | |
end | |
END | |
;; | |
esac | |
cat $tmpfile | |
$MINOS $MINOSOPT $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment