Add files via upload

上传了sph_global.sh sph_regional.sh xy_dot.sh xy_grid.sh
This commit is contained in:
张壹 2017-10-22 20:29:46 -07:00 committed by GitHub
parent cfb976a069
commit 62d9f5dca7
4 changed files with 378 additions and 0 deletions

94
sph_global.sh Normal file
View File

@ -0,0 +1,94 @@
#!/bin/bash
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
. gmt_shell_functions.sh
#GMT显示平面数据脚本输入文件为网格文件没有包含网格化语句因为网格化过程中的情况多样化建议在其他脚本中个别添加再调用此脚本
# 初始化参数
data='null'
unit='m'
color='rainbow'
range='null'
overwriteRange='null'
overwrite=0
labels=("longitude (degree)" "latitude (degree)")
plotgrad=0
# 从命令行获取参数
while getopts "hi:r:u:c:a: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<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-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" "-u" "data unit. The default is meter."
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."
exit 0;;
i)
data=$OPTARG;;
u)
unit=$OPTARG;;
c)
color=$OPTARG;;
r)
overwrite=1
overwriteRange=$OPTARG;;
a)
labels=(${OPTARG//,/ });;
g)
plotgrad=1;;
?)
printf "error: unknow argument\nuse -h option to see help information\n"
exit 1;;
esac
done
# 进行必要的参数检查
if [[ $data == "null" ]]; then
printf "error: no input file name\nuse -h option to see help information\n"
exit 1
else
# 初始化临时文件名
cptfile=user.cpt
psfile=${data%.*}.ps
jpgfile=${data%.*}.png
# 获取网格范围
if [[ $overwrite == 1 ]]; then
range=${overwriteRange}
else
range=$(gmt_get_gridregion ${data})
fi
# 设置绘图参数
gmt gmtset \
FONT_ANNOT_PRIMARY=6.5p,Times-Roman,black \
MAP_FRAME_PEN=thinnest,black \
MAP_TICK_LENGTH_PRIMARY=1.5p/1p \
MAP_TICK_PEN_PRIMARY=thinnest,black \
MAP_TITLE_OFFSET=6.5p \
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
FONT_LABEL=6.5p,Times-Roman,black \
MAP_FRAME_AXES=WESnZ \
MAP_LABEL_OFFSET=2.5p
gmt grd2cpt ${data} -C${color} -Z -D > $cptfile
if [[ $plotgrad == 1 ]]; then
gradfile=usergradient.nc
gmt grdgradient ${data} -G${gradfile} -Nt -A0/45
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -Bxag+l"${labels[0]}" -Bpya40g40+l"${labels[1]}" -JN180/3i -K -P > $psfile
else
gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Bpya40g40+l"${labels[1]}" -JN180/3i -K -P > $psfile
fi
#-C${cptfile}+Uk 使用km色标单位除1000
gmt psscale -Dx0.5i/-0.3i+w2i/0.07i+h -C${cptfile} -Bxa -By+l${unit} -O >> $psfile
gmt psconvert $psfile -A -TeG -E300
# 删除临时文件 使用linux终端rm命令
rm $cptfile $psfile gmt.history gmt.conf
if [[ $plotgrad == 1 ]]; then
rm $gradfile
fi
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
#imgcat $jpgfile
# 打开图片文件 此命令使用MacOS终端open命令
open $jpgfile
fi

108
sph_regional.sh Normal file
View File

@ -0,0 +1,108 @@
#!/bin/bash
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
. gmt_shell_functions.sh
#GMT显示平面数据脚本输入文件为网格文件没有包含网格化语句因为网格化过程中的情况多样化建议在其他脚本中个别添加再调用此脚本
# 初始化参数
data='null'
unit='m'
color='rainbow'
range='null'
overwriteRange='null'
overwrite=0
labels=("longitude (degree)" "latitude (degree)")
plot_para=(0 0 0 0)
plotgrad=0
# 从命令行获取参数
while getopts "hi:r:u:c:a:g" 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 futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (zhangyi.cugwuhan@gmail.com)\n"
printf "usage: ${0##*/} -i<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-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" "-u" "data unit. The default is meter."
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."
exit 0;;
i)
data=$OPTARG;;
u)
unit=$OPTARG;;
c)
color=$OPTARG;;
r)
overwrite=1
overwriteRange=$OPTARG;;
a)
labels=(${OPTARG//,/ });;
g)
plotgrad=1;;
?)
printf "error: unknow argument\nuse -h option to see help information\n"
exit 1;;
esac
done
# 进行必要的参数检查
if [[ $data == "null" ]]; then
printf "error: no input file name\nuse -h option to see help information\n"
exit 1
else
# 初始化临时文件名
cptfile=user.cpt
psfile=${data%.*}.ps
jpgfile=${data%.*}.png
# 获取网格范围
if [[ $overwrite == 1 ]]; then
range=${overwriteRange}
# 别忘了这里要加上括号 才能初始化数组
range_sp=(${range//// })
# 注意bash并不支持浮点运算 所以需要使用bc命令 bc命令是一个计算数学表达式工具 参数是一个数学表达式字符串
plot_para[0]=$(echo "${range_sp[0]} * 0.5 + ${range_sp[1]} * 0.5"|bc)
plot_para[1]=$(echo "${range_sp[2]} * 0.5 + ${range_sp[3]} * 0.5"|bc)
plot_para[2]=$(echo "${plot_para[1]} * 0.5 + ${range_sp[2]} * 0.5"|bc)
plot_para[3]=$(echo "${plot_para[1]} * 0.5 + ${range_sp[3]} * 0.5"|bc)
else
range=$(gmt_get_gridregion ${data})
range_sp=(${range//// })
plot_para[0]=$(echo "${range_sp[0]} * 0.5 + ${range_sp[1]} * 0.5"|bc)
plot_para[1]=$(echo "${range_sp[2]} * 0.5 + ${range_sp[3]} * 0.5"|bc)
plot_para[2]=$(echo "${plot_para[1]} * 0.5 + ${range_sp[2]} * 0.5"|bc)
plot_para[3]=$(echo "${plot_para[1]} * 0.5 + ${range_sp[3]} * 0.5"|bc)
fi
# 设置绘图参数
gmt gmtset \
FONT_ANNOT_PRIMARY=6.5p,Times-Roman,black \
MAP_FRAME_PEN=thinnest,black \
MAP_FRAME_WIDTH=1.5p \
MAP_TICK_LENGTH_PRIMARY=1.5p/1p \
MAP_TICK_PEN_PRIMARY=thinnest,black \
MAP_TITLE_OFFSET=6.5p \
MAP_GRID_PEN_PRIMARY=thinnest,grey,-- \
FONT_LABEL=6.5p,Times-Roman,black \
MAP_FRAME_AXES=WESnZ \
MAP_LABEL_OFFSET=2.5p
gmt grd2cpt ${data} -R${range} -C${color} -Z -D > $cptfile
if [[ $plotgrad == 1 ]]; then
gradfile=usergradient.nc
gmt grdgradient ${data} -G${gradfile} -Nt -A0/45
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/3i -K -P > $psfile
else
gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/3i -K -P > $psfile
fi
#-C${cptfile}+Uk 使用km色标单位除1000
gmt psscale -Dx0.5i/-0.3i+w2i/0.07i+h -C${cptfile} -Bxa -By+l${unit} -O >> $psfile
gmt psconvert $psfile -A -TeG -E300
# 删除临时文件 使用linux终端rm命令
rm $cptfile $psfile gmt.history gmt.conf
if [[ $plotgrad == 1 ]]; then
rm $gradfile
fi
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
#imgcat $jpgfile
# 打开图片文件 此命令使用MacOS终端open命令
open $jpgfile
fi

84
xy_dot.sh Normal file
View File

@ -0,0 +1,84 @@
#!/bin/bash
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
. gmt_shell_functions.sh
# 初始化参数
data='null'
unit='m'
color='rainbow'
range='null'
overwriteRange='null'
overwrite=0
labels=("x (m)" "y (m)")
valuerange="0/1000/10"
# 从命令行获取参数
while getopts "hi:r:u:c:a:d:" arg
do
case $arg in
h)
printf "simple table file mapping using GMT script under x-y plane with colored dots. The template accepts a table 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<table-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] [-c<cpt-file>] [-d<vmin>/<vmax>/<dv>] [-a<x-label>,<y-label>]\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" "-d" "data's value extension. The default is 0/1000/10. this option is used for makeing cpt file."
printf "%s\t%s\n" "-u" "data unit. The default is meter."
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)."
exit 0;;
i)
data=$OPTARG;;
u)
unit=$OPTARG;;
c)
color=$OPTARG;;
r)
overwrite=1
overwriteRange=$OPTARG;;
a)
labels=(${OPTARG//,/ });;
d)
valuerange=$OPTARG;;
?)
printf "error: unknow argument\nuse -h option to see help information\n"
exit 1;;
esac
done
# 进行必要的参数检查
if [[ $data == "null" ]]; then
printf "error: no input file name\nuse -h option to see help information\n"
exit 1
else
# 初始化临时文件名
cptfile=user.cpt
psfile=${data%.*}.ps
jpgfile=${data%.*}.png
# 获取网格范围
if [[ $overwrite == 1 ]]; then
range=${overwriteRange}
else
range=$(gmt_get_region ${data})
fi
# 设置绘图参数
gmt gmtset \
FONT_ANNOT_PRIMARY=7p,Times-Roman,black \
MAP_FRAME_PEN=thin,black \
MAP_TICK_LENGTH_PRIMARY=2p/1p \
MAP_TITLE_OFFSET=7p \
MAP_GRID_CROSS_SIZE_PRIMARY=4p \
FONT_LABEL=7p,Times-Roman,black \
MAP_FRAME_AXES=WeSnZ \
MAP_LABEL_OFFSET=4p
gmt makecpt -C${color} -T${valuerange} > $cptfile
gmt psxy ${data} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JX5i/2.5i -R${range} -C${cptfile} -Sc0.05c -Gblack -P -K -Y6i > $psfile
gmt psscale -Dx0.5i/-0.6i+w4i/0.15i+h -C${cptfile} -Bxag -By+l${unit} -O >> $psfile
gmt psconvert $psfile -A -TeG -E300
# 删除临时文件 使用linux终端rm命令
rm $cptfile $psfile gmt.history gmt.conf
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
#imgcat $jpgfile
# 打开图片文件 此命令使用MacOS终端open命令
open $jpgfile
fi

92
xy_grid.sh Normal file
View File

@ -0,0 +1,92 @@
#!/bin/bash
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
. gmt_shell_functions.sh
#GMT显示平面数据脚本输入文件为网格文件没有包含网格化语句因为网格化过程中的情况多样化建议在其他脚本中个别添加再调用此脚本
# 初始化参数
data='null'
unit='m'
color='rainbow'
range='null'
overwriteRange='null'
overwrite=0
labels=("x (m)" "y (m)")
plotgrad=0
# 从命令行获取参数
while getopts "hi:r:u:c:a:g" arg
do
case $arg in
h)
printf "simple grid file mapping using GMT script under x-y plane. 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<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-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" "-u" "data unit. The default is meter."
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."
exit 0;;
i)
data=$OPTARG;;
u)
unit=$OPTARG;;
c)
color=$OPTARG;;
r)
overwrite=1
overwriteRange=$OPTARG;;
a)
labels=(${OPTARG//,/ });;
g)
plotgrad=1;;
?)
printf "error: unknow argument\nuse -h option to see help information\n"
exit 1;;
esac
done
# 进行必要的参数检查
if [[ $data == "null" ]]; then
printf "error: no input file name\nuse -h option to see help information\n"
exit 1
else
# 初始化临时文件名
cptfile=user.cpt
psfile=${data%.*}.ps
jpgfile=${data%.*}.png
# 获取网格范围
if [[ $overwrite == 1 ]]; then
range=${overwriteRange}
else
range=$(gmt_get_gridregion ${data})
fi
# 设置绘图参数
gmt gmtset \
FONT_ANNOT_PRIMARY=7p,Times-Roman,black \
MAP_FRAME_PEN=thin,black \
MAP_TICK_LENGTH_PRIMARY=2p/1p \
MAP_TITLE_OFFSET=7p \
MAP_GRID_CROSS_SIZE_PRIMARY=4p \
FONT_LABEL=7p,Times-Roman,black \
MAP_FRAME_AXES=WeSnZ \
MAP_LABEL_OFFSET=4p
gmt grd2cpt ${data} -C${color} -Z -D > $cptfile
if [[ $plotgrad == 1 ]]; then
gradfile=usergradient.nc
gmt grdgradient ${data} -G${gradfile} -Nt -A0/45
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JX3i -K -P > $psfile
else
gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JX3i -K -P > $psfile
fi
gmt psscale -Dx3.2i/0.3i+w2.2i/0.1i -C${cptfile} -Bxa -By+l${unit} -O >> $psfile
gmt psconvert $psfile -A -TeG -E300
# 删除临时文件 使用linux终端rm命令
rm $cptfile $psfile gmt.history gmt.conf
if [[ $plotgrad == 1 ]]; then
rm $gradfile
fi
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
#imgcat $jpgfile
# 打开图片文件 此命令使用MacOS终端open命令
open $jpgfile
fi