Skip to content

Commit

Permalink
add new chsck at -r (not working yet), see #21
Browse files Browse the repository at this point in the history
  • Loading branch information
demanast@triangle committed Oct 19, 2017
1 parent 1159faa commit 93edfb7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 33 deletions.
22 changes: 22 additions & 0 deletions .checknum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# N={0,1,2,3,...} by syntaxerror
function isNaturalNumber()
{
[[ ${1} =~ ^[0-9]+$ ]]
}
# Z={...,-2,-1,0,1,2,...} by karttu
function isInteger()
{
[[ ${1} == ?(-)+([0-9]) ]]
}
# Q={...,-½,-¼,0.0,¼,½,...} by karttu
function isFloat()
{
[[ ${1} == ?(-)@(+([0-9]).*([0-9])|*([0-9]).+([0-9]))?(E?(-|+)+([0-9])) ]]
}
# R={...,-1,-½,-¼,0.E+n,¼,½,1,...}
function isNumber()
{
isNaturalNumber $1 || isInteger $1 || isFloat $1
}

85 changes: 52 additions & 33 deletions coulomb2gmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ function DEBUG()
[ "$_DEBUG" == "on" ] && $@
}

source .checknum.sh

# //////////////////////////////////////////////////////////////////////////////
# GMT parameters
#gmtset MAP_FRAME_TYPE fancy
Expand Down Expand Up @@ -194,18 +196,43 @@ then
shift
;;
-r)
RANGE=1
minlon=${4}
maxlon=${5}
minlat=${6}
maxlat=${7}
prjscale=${8}
shift
shift
shift
shift
shift
shift
DEBUG echo "-r next arguments:" ${4} ${5} ${6} ${7} ${8}
if [ $# -ge 8 ];
then
isNumber ${4}; if [ $? -eq 0 ]; then
# isNumber ${5}; if [ $? -eq 0 ] && [ ${5} -gt ${4} ]; then
# isNumber ${6}; if [ $? -eq 0 ]; then
# isNumber ${7}; if [ $? -eq 0 ] && [ ${7} -gt ${6} ]; then
# isNumber ${8}; if [ $? -eq 0 ] && [ ${7} -gt 0 ]; then
DEBUG echo "[DEBUG:${LINENO}] test if"
RANGE=1
minlon=${4}
maxlon=${5}
minlat=${6}
maxlat=${7}
prjscale=${8}
shift
shift
shift
shift
shift
# fi
# fi
# fi
# fi

else
echo "[ERROR] Not enough input arguments at \"-r\" option."
echo "[STATUS] Script Finished Unsuccesful! Exit Status 1"
exit 1

fi
else
echo "[ERROR] Not enough input arguments at \"-r\" option."
echo "[STATUS] Script Finished Unsuccesful! Exit Status 1"
exit 1
fi
shift # for -r
;;
-topo)
TOPOGRAPHY=1
Expand Down Expand Up @@ -239,73 +266,65 @@ then
;;
-cmt)
DEBUG echo "[DEBUG:${LINENO}] cmt: next argument:" ${4}
if [ $# -gt 3 ] && [ -f ${4} ];
if [ $# -ge 4 ] && [ -f ${4} ];
then
CMT=1
inpcmt=${4}
DEBUG echo "cmt file is: $inpcmt"
shift
shift
elif [ $# -gt 3 ] && [ ${4:0:1} == \- ];
elif [ $# -ge 4 ] && [ ${4:0:1} == \- ];
then
echo "[WARNING] CMT file does not set! CMT will not be plotted"
shift
elif [ $# -gt 3 ] && [ ! -f ${4} ];
elif [ $# -ge 4 ] && [ ! -f ${4} ];
then
echo "[WARNING] CMT file does not exist! CMT will not be plotted"
shift
shift
elif [ $# -eq 3 ];
then
echo "[WARNING] CMT file does not exist! CMT will not be plotted"
shift
fi
shift #shift for arg -cmt
;;
-faults)
FAULTS=1
shift
;;
-mt)
DEBUG echo "[DEBUG:${LINENO}] maptitle: next argument:" ${4}
if [ $# -gt 3 ] && [ ${4:0:1} != \- ];
if [ $# -ge 4 ] && [ ${4:0:1} != \- ];
then
MTITLE=1
mtitle=$4
shift
shift
elif [ $# -gt 3 ] && [ ${4:0:1} == \- ];
elif [ $# -ge 4 ] && [ ${4:0:1} == \- ];
then
echo "[WARNING] No map title defined. Default title will be printed"
shift
elif [ $# -eq 3 ];
then
echo "[WARNING] No map title defined. Default title will be printed"
shift
fi
shift #shift for the argument -mt
;;
-ctext)
DEBUG echo "[DEBUG:${LINENO}] ctext: next argument:" ${4}
if [ $# -gt 3 ] && [ -f ${4} ];
if [ $# -ge 4 ] && [ -f ${4} ];
then
CTEXT=1
pth2ctextfile=${4}
DEBUG echo "custom text file is: $pth2ctextfile"
shift
shift
elif [ $# -gt 3 ] && [ ${4:0:1} == \- ];
elif [ $# -ge 4 ] && [ ${4:0:1} == \- ];
then
echo "[WARNING] Custom text file does not set! Custom text will not be plotted"
shift
elif [ $# -gt 3 ] && [ ! -f ${4} ];
elif [ $# -ge 4 ] && [ ! -f ${4} ];
then
echo "[WARNING] Custom text file does not exist! Custom text will not be plotted"
shift
shift
elif [ $# -eq 3 ];
then
echo "[WARNING] Custom text file does not set! Custom text will not be plotted"
shift
fi
shift # shift for the arg -ctext
;;
-cstress)
CSTRESS=1
Expand Down Expand Up @@ -407,8 +426,8 @@ then
help
;;
-*)
echo "[ERROR] Bad argument structure. Script Finished Unsuccesful!"
echo "[ERROR] Exit Status 1"
echo "[ERROR] Bad argument structure. argument \"$3\" is not right"
echo "[STATUS] Script Finished Unsuccesful! Exit Status 1"
exit 1
esac
done
Expand Down

0 comments on commit 93edfb7

Please sign in to comment.