From acefa3db68c8d03ad4ac044c1746cfe086984f6f Mon Sep 17 00:00:00 2001 From: pi Date: Tue, 12 Jun 2018 11:19:16 -0700 Subject: [PATCH] add -G option --- gmtsph-global.sh | 16 ++++++++++++---- gmtsph-regional.sh | 14 +++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gmtsph-global.sh b/gmtsph-global.sh index 406ba6c..f202829 100755 --- a/gmtsph-global.sh +++ b/gmtsph-global.sh @@ -4,6 +4,7 @@ #GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本 # 初始化参数 data='null' +gridData='null' unit='m' color='rainbow' range='null' @@ -13,13 +14,13 @@ labels=("longitude (degree)" "latitude (degree)") plotgrad=0 clon=0 # 从命令行获取参数 -while getopts "hi:r:u:c:a:g" arg +while getopts "hi:r:u:c:a:G: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]\n" + printf "usage: ${0##*/} -i [-r///] [-l] [-u] [-c] [-a,] [-g] [-G]\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" @@ -27,6 +28,7 @@ For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (z 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" exit 0;; i) data=$OPTARG;; @@ -43,6 +45,8 @@ For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (z labels=(${OPTARG//,/ });; g) plotgrad=1;; + G) + gridData=$OPTARG;; ?) printf "error: unknow argument\nuse -h option to see help information\n" exit 1;; @@ -77,8 +81,12 @@ else gmt grd2cpt ${data} -C${color} -Z -D > $cptfile if [[ $plotgrad == 1 ]]; then - gradfile=usergradient.nc - gmt grdgradient ${data} -G${gradfile} -Nt -A0/45 + gradfile=${data%.*}Grad.nc + if [[ $gridData == 'null' ]]; then + gmt grdgradient ${data} -G${gradfile} -Nt -A0/45 + else + gmt grdgradient ${gridData} -G${gradfile} -Nt -A0/45 + fi gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -Bxag+l"${labels[0]}" -Bpya40g40+l"${labels[1]}" -JN${clon}/3i -K -P > $psfile else gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Bpya40g40+l"${labels[1]}" -JN${clon}/3i -K -P > $psfile diff --git a/gmtsph-regional.sh b/gmtsph-regional.sh index 8f993e3..38a640e 100755 --- a/gmtsph-regional.sh +++ b/gmtsph-regional.sh @@ -4,6 +4,7 @@ #GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本 # 初始化参数 data='null' +gridData='null' unit='m' color='rainbow' range='null' @@ -23,13 +24,13 @@ smallPage="1.5i,0.125i/-0.3i,1.2i/0.06i" # 图大小,色标位置,色标尺寸 middlePage="2i,0.2i/-0.35i,1.5i/0.07i" largePage="2.5i,0.35i/-0.4i,1.75i/0.08i" # 从命令行获取参数 -while getopts "hi:r:u:c:a:t:v:l:gnpb" arg +while getopts "hi:r:u:c:a:t:v:l:G:gnpb" arg do case $arg in h) printf "simple regional data mapping using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \ For further explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (zhangyi.cugwuhan@gmail.com)\n" - printf "usage: ${0##*/} -i [-r///] [-u] [-c] [-a,] [-t,] [-v] [-l] [-b] [-g] [-n] [-p]\n" + printf "usage: ${0##*/} -i [-r///] [-u] [-c] [-a,] [-t,] [-v] [-l] [-g] [-G] [-b] [-n] [-p]\n" printf "%s\t%s\n" "-i" "input grid file" printf "%s\t%s\n" "-r" "data range. The template will detect the input data range automatically, the use of this option will overwrite the range." printf "%s\t%s\n" "-u" "data unit. The default is meter. use 'km+Uk' to append '+Uk' option to the psscale command." @@ -40,6 +41,7 @@ For further explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang ( printf "%s\t%s\n" "-l" "image layout and size. three available options are small(1.5 inch wide), middle and large." printf "%s\t%s\n" "-b" "draw coast line." 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" "-n" "disable the use of grd2cpt." printf "%s\t%s\n" "-p" "inverse the color pattern specified by the -c option, no use if -n option is implemented." exit 0;; @@ -64,6 +66,8 @@ For further explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang ( coastline=1;; g) plotgrad=1;; + G) + gridData=$OPTARG;; n) nocpt=1;; p) @@ -136,7 +140,11 @@ else if [[ $plotgrad == 1 ]]; then gradfile=${data%.*}Grad.nc - gmt grdgradient ${data} -G${gradfile} -Nt -A0/45 + if [[ $gridData == 'null' ]]; then + gmt grdgradient ${data} -G${gradfile} -Nt -A0/45 + else + gmt grdgradient ${gridData} -G${gradfile} -Nt -A0/45 + fi gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -Bx${axistick[0]}g+l"${labels[0]}" -By${axistick[1]}g+l"${labels[1]}" -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/${pagePara[0]} -K -P > $psfile else gmt grdimage ${data} -R${range} -C${cptfile} -Bx${axistick[0]}g+l"${labels[0]}" -By${axistick[1]}g+l"${labels[1]}" -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/${pagePara[0]} -K -P > $psfile