From 9306e7551b60d222d440a44504e204f938d93d4a Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 15 Sep 2018 15:51:19 -0700 Subject: [PATCH] add dispOptions.sh --- dispOptions.sh | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ gmtsph-JA.sh | 33 +++++++++-------- gmtsph-global.sh | 27 +++++++------- 3 files changed, 125 insertions(+), 27 deletions(-) create mode 100755 dispOptions.sh diff --git a/dispOptions.sh b/dispOptions.sh new file mode 100755 index 0000000..87664b4 --- /dev/null +++ b/dispOptions.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# 一些输出帮助文档的函数 +# 显示命令简介 两个参数 命令名称 命令简介 +function dispTitle(){ + winWidth=`tput cols` + + cutLength=`expr ${winWidth} - 19` + segment=${2:0:${cutLength}} + printf "%s\n%-10s%s\n" "${1}" " " "${segment}" + + times=1 + while (( ${#segment} == ${cutLength} )) + do + st=`expr ${cutLength} \* ${times}` + segment=${2:${st}:${cutLength}} + printf "%-10s%s\n" " " "${segment}" + times=`expr ${times} + 1` + done + printf "\n" +} +# 显示作者信息 一个参数 作者信息 +function dispAuthorInfo(){ + winWidth=`tput cols` + + cutLength=`expr ${winWidth} - 19` + segment=${1:0:${cutLength}} + + printf "%-10s%s\n" "Author:" "${segment}" + + times=1 + while (( ${#segment} == ${cutLength} )) + do + st=`expr ${cutLength} \* ${times}` + segment=${1:${st}:${cutLength}} + printf "%-10s%s\n" " " "${segment}" + times=`expr ${times} + 1` + done + printf "\n" +} +# 显示用法 一个参数 做法信息 +function dispUsage(){ + winWidth=`tput cols` + + cutLength=`expr ${winWidth} - 19` + segment=${1:0:${cutLength}} + + printf "%-10s%s\n" "Usage:" "${segment}" + + times=1 + while (( ${#segment} == ${cutLength} )) + do + st=`expr ${cutLength} \* ${times}` + segment=${1:${st}:${cutLength}} + printf "%-10s%s\n" " " "${segment}" + times=`expr ${times} + 1` + done + printf "\nOptions:\n" +} +# 短命令说明 两个参数 命令符号 命令说明 +function dispOptionShort(){ + winWidth=`tput cols` + + cutLength=`expr ${winWidth} - 19` + segment=${2:0:${cutLength}} + printf "%-4s%-6s%s\n" " " "${1}" "${segment}" + + times=1 + while (( ${#segment} == ${cutLength} )) + do + st=`expr ${cutLength} \* ${times}` + segment=${2:${st}:${cutLength}} + printf "%-10s%s\n" " " "${segment}" + times=`expr ${times} + 1` + done +} +# 长命令说明 三个参数 短命令符号 长命令符号 命令说明 +function dispOptionLong(){ + winWidth=`tput cols` + + cutLength=`expr ${winWidth} - 32` + segment=${3:0:${cutLength}} + printf "%-4s%-6s%-12s%s\n" " " "${1}" "${2}" "${segment}" + + times=1 + while (( ${#segment} == ${cutLength} )) + do + st=`expr ${cutLength} \* ${times}` + segment=${3:${st}:${cutLength}} + printf "%-22s%s\n" " " "${segment}" + times=`expr ${times} + 1` + done +} \ No newline at end of file diff --git a/gmtsph-JA.sh b/gmtsph-JA.sh index a6e78e5..b43af32 100755 --- a/gmtsph-JA.sh +++ b/gmtsph-JA.sh @@ -1,6 +1,8 @@ #!/bin/bash # 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围 . gmt_shell_functions.sh +# 包含dispOption脚本 +. dispOptions #GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本 # 初始化参数 data='null' @@ -22,21 +24,22 @@ while getopts "hi:r:u:c:a:v:G:l:p:gsn" arg do case $arg in h) - printf "simple global wide data mapping using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \ -For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (zhangyi.cugwuhan@gmail.com)\n" - printf "usage: ${0##*/} -i [-r///] [-l//] [-u] [-c] [-a,] [-v] [-g] [-s] [-G] [-p]\n" - printf "%s\t%s\n" "-i" "input grid file" - printf "%s\t%s\n" "-r" "data range. The template will ditect the input data range automaticly, the use of this option will overwrite the range." - printf "%s\t%s\n" "-l" "central longitude and latitude values of the plot, the default value is 0/0/115,180/0/115. " - printf "%s\t%s\n" "-u" "data unit. The default is meter. use 'km+Uk' to append '+Uk' option to the psscale command" - printf "%s\t%s\n" "-c" "color cpt. The default is 'rainbow -Z' in which '-Z' tells the grd2cpt to make a continuous cpt-file, remove it to disable the function." - printf "%s\t%s\n" "-n" "disable the use of grd2cpt." - printf "%s\t%s\n" "-s" "plot the day-night terminator. The default is false." - printf "%s\t%s\n" "-a" "axis labels. The deafults are x (m) and y (m)." - printf "%s\t%s\n" "-v" "intervals of color bar's labels. the script will set the intervals automatically if -v option is not set." - printf "%s\t%s\n" "-g" "use grdgradient. The default is false." - printf "%s\t%s\n" "-G" "provide a different input grid data for the use of grdgradient. This should be used with the '-g' option at the same time" - printf "%s\t%s\n" "-p" "plot polygons via a file." + dispTitle "${0##*/}" "simple global wide data mapping using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \ +For futher explanations, please look for GMT's manuscripts." + dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)" + dispUsage "${0##*/} -i [-r///] [-l//] [-u] [-c] [-a,] [-v] [-g] [-s] [-G] [-p]" + dispOptionShort "-i" "input grid file" + dispOptionShort "-r" "data range. The template will ditect the input data range automaticly, the use of this option will overwrite the range." + dispOptionShort "-l" "central longitude and latitude values of the plot, the default value is 0/0/115,180/0/115. " + dispOptionShort "-u" "data unit. The default is meter. use 'km+Uk' to append '+Uk' option to the psscale command" + dispOptionShort "-c" "color cpt. The default is 'rainbow -Z' in which '-Z' tells the grd2cpt to make a continuous cpt-file, remove it to disable the function." + dispOptionShort "-n" "disable the use of grd2cpt." + dispOptionShort "-s" "plot the day-night terminator. The default is false." + dispOptionShort "-a" "axis labels. The deafults are x (m) and y (m)." + dispOptionShort "-v" "intervals of color bar's labels. the script will set the intervals automatically if -v option is not set." + dispOptionShort "-g" "use grdgradient. The default is false." + dispOptionShort "-G" "provide a different input grid data for the use of grdgradient. This should be used with the '-g' option at the same time" + dispOptionShort "-p" "plot polygons via a file." exit 0;; i) data=$OPTARG;; diff --git a/gmtsph-global.sh b/gmtsph-global.sh index a2999b5..9f03ee7 100755 --- a/gmtsph-global.sh +++ b/gmtsph-global.sh @@ -1,6 +1,8 @@ #!/bin/bash # 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围 . gmt_shell_functions.sh +# 包含dispOption脚本 +. dispOptions #GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本 # 初始化参数 data='null' @@ -19,18 +21,19 @@ while getopts "hi:r:u:c:a:G:l:p:g" arg do case $arg in h) - printf "simple global wide data mapping using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \ -For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (zhangyi.cugwuhan@gmail.com)\n" - printf "usage: ${0##*/} -i [-r///] [-l] [-u] [-c] [-a,] [-g] [-G] [-p]\n" - printf "%s\t%s\n" "-i" "input grid file" - printf "%s\t%s\n" "-r" "data range. The template will ditect the input data range automaticly, the use of this option will overwrite the range." - printf "%s\t%s\n" "-l" "central longitude value of the plot, the default value is 0" - printf "%s\t%s\n" "-u" "data unit. The default is meter. use 'km+Uk' to append '+Uk' option to the psscale command" - printf "%s\t%s\n" "-c" "color cpt. The default is rainbow." - printf "%s\t%s\n" "-a" "axis labels. The deafults are x (m) and y (m)." - printf "%s\t%s\n" "-g" "use grdgradient. The default is false." - printf "%s\t%s\n" "-G" "provide a different input grid data for the use of grdgradient. This should be used with the '-g' option at the same time" - printf "%s\t%s\n" "-p" "plot polygons via a file." + dispTitle "${0##*/}" "simple global wide data mapping using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \ +For futher explanations, please look for GMT's manuscripts." + dispAuthorInfo "Author: Yi Zhang (zhangyi.cugwuhan@gmail.com)" + dispUsage "${0##*/} -i [-r///] [-l] [-u] [-c] [-a,] [-g] [-G] [-p]" + dispOptionShort "-i" "input grid file" + dispOptionShort "-r" "data range. The template will ditect the input data range automaticly, the use of this option will overwrite the range." + dispOptionShort "-l" "central longitude value of the plot, the default value is 0" + dispOptionShort "-u" "data unit. The default is meter. use 'km+Uk' to append '+Uk' option to the psscale command" + dispOptionShort "-c" "color cpt. The default is rainbow." + dispOptionShort "-a" "axis labels. The deafults are x (m) and y (m)." + dispOptionShort "-g" "use grdgradient. The default is false." + dispOptionShort "-G" "provide a different input grid data for the use of grdgradient. This should be used with the '-g' option at the same time" + dispOptionShort "-p" "plot polygons via a file." exit 0;; i) data=$OPTARG;;