Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60f0ec6fae | |||
| b00d094cfc | |||
| 1bac935407 | |||
| 3cefd7af1d | |||
| e091b6e87c | |||
| ef851a2a47 | |||
| df0c42a119 | |||
| c6ef63f76a | |||
| b42ec4a550 | |||
| b357e66873 | |||
| 990c750fe6 | |||
| 86d0937b01 | |||
| 1da2101cb2 | |||
| 3498dc2f90 | |||
| bda099fa66 | |||
| d79f700aa5 | |||
| 7852a53d51 | |||
| 4cc753a9a9 | |||
| dec78cc1ff | |||
| d4b15a47d1 | |||
| 6dd66f0e43 | |||
| d212e445c9 | |||
| 3589eddec0 | |||
| 3aaf8edabb | |||
| 264d10e45a | |||
| fc596d03fd | |||
| c094cb2ab1 | |||
| 2a7becdb14 | |||
| 4059dbd96e | |||
| de058863ca | |||
| 33f4662eff | |||
| 1b97379188 | |||
| f1aeb5a41d | |||
| b140889c61 | |||
| 77c2ebdef4 | |||
| 559b238897 | |||
| 52681fcbe5 | |||
| 310366b789 | |||
| 8e8f8bc790 | |||
| e89dd055b2 | |||
| 6aeb300e61 | |||
| 83f7f2ef0a | |||
| ad0ab2846b | |||
| 8989456bab | |||
| acaee58825 | |||
| 1bf8cf76fc | |||
| b080977988 | |||
| f8516ff1a1 | |||
| 451dd6683c | |||
| 2cb99ae1aa | |||
| b1b52bbb81 | |||
| 9306e7551b | |||
| 87718784c9 | |||
| f2939716d8 | |||
| d3b42918fc | |||
| 1cd852b265 | |||
| 9b3cdb2a57 | |||
| df067832a8 | |||
| 007b27ea2d | |||
| 1f2573aa1c | |||
| 345d620785 | |||
| 84f2b77544 | |||
| d5403dc00c | |||
| ed1082c1b6 | |||
| ed59e9f37f | |||
| b131d7c0ba | |||
| acefa3db68 | |||
| 81fa7a0061 | |||
| 42a11bef2d | |||
| 5309c53944 | |||
| fce8728fa1 | |||
| 13b60a3d7e | |||
| b97bee5eae | |||
| a6a58c941e | |||
| 2bc694ec73 | |||
| ab406d33ce | |||
| 3fe4e4a41a | |||
| b442ade8b0 | |||
| 2fca6689da | |||
| 66ac47bb56 | |||
| e703dc876f | |||
| a2a3756ec8 | |||
| 6dc9162849 | |||
| 7f3dc873cc | |||
| 755ba86754 | |||
| f27e997778 | |||
| 81a628f31c | |||
| 392d048f0c | |||
| 20c8ec50b2 | |||
| bf053a21be | |||
| fcfd49e1b5 | |||
| f49bf4e26f | |||
| 888feff508 | |||
| c5772870e4 | |||
| 4f506007dc | |||
| 667cfaf7a8 | |||
| f75af72132 |
16
README.md
16
README.md
@@ -1,2 +1,14 @@
|
||||
# gmt_template
|
||||
shell scripts of GMT templates
|
||||
# shell-templates
|
||||
shell script templates for geophysical data processing and plotting.
|
||||
|
||||
## Dependences
|
||||
|
||||
* [bash shell](https://www.gnu.org/software/bash/): All scripts included in this folder is written under the dicipline of the *bash* shell. Any modifications should follow the dicipline as well.
|
||||
* [GMT5](https://gmt.soest.hawaii.edu) (General Mapping Tools): are an [open-source](https://en.wikipedia.org/wiki/Open-source) collection of computer software tools for processing and displaying xy and xyz datasets, including [rasterisation](https://en.wikipedia.org/wiki/Rasterisation), filtering and other [image processing](https://en.wikipedia.org/wiki/Image_processing) operations, and various kinds of [map projections](https://en.wikipedia.org/wiki/Map_projection).
|
||||
* [imagemagick](https://www.imagemagick.org/script/index.php): is a [free and open-source](https://en.wikipedia.org/wiki/Free_and_open-source_software) [software suite](https://en.wikipedia.org/wiki/Software_suite) for displaying, converting, and [editing](https://en.wikipedia.org/wiki/Image_editing) [raster image](https://en.wikipedia.org/wiki/Raster_graphics) and [vector image](https://en.wikipedia.org/wiki/Vector_graphics) files. It can read and write over 200 [image file formats](https://en.wikipedia.org/wiki/Image_file_formats).
|
||||
* [iTerm2](https://iterm2.com) (optional): is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.10 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.
|
||||
|
||||
## Installation
|
||||
|
||||
Simply run **configure.sh** to symlink all scripts to the directory */usr/local/sbin*. The configure script will create the folder and add it to *PATH* if the directory does not exist. The execuable name for a script will be its name without the *.sh* extension.
|
||||
|
||||
|
||||
56
configure.sh
Executable file
56
configure.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
# 获取当前文件夹地址
|
||||
folderAddress=`pwd`
|
||||
# 获取当前用户的根目录
|
||||
userAddress=`echo $HOME`
|
||||
# 指定安装地址 若不存在则建立
|
||||
objectAddress="/usr/local/sbin"
|
||||
if [[ ! -d $objectAddress ]]; then
|
||||
sudo mkdir $objectAddress
|
||||
fi
|
||||
# 添加安装路径到环境变量中 首先获取当前的环境变量 若安装路径已存在于环境变量中则跳过 否则添加安装地址到环境变量中
|
||||
allPATH=`echo $PATH`
|
||||
if [[ `echo ${allPATH} | grep "${objectAddress}"` ]]; then
|
||||
echo "The installation address is already added to \$PATH. Nothing to be done."
|
||||
else
|
||||
breaked=no
|
||||
# 几个经常使用的用户配置文件
|
||||
profileAddress=("${userAddress}/.bash_profile" "${userAddress}/.profile" "${userAddress}/.zshrc")
|
||||
for one_address in ${profileAddress[@]}; do
|
||||
if [[ -f ${one_address} ]]; then
|
||||
echo "adding the installation address to ${one_address}"
|
||||
cat <<- EOF >> ${one_address}
|
||||
# this is added by configure.sh of shell-template (zhangyi.cugwuhan@gmail.com)
|
||||
export PATH=${objectAddress}:\$PATH
|
||||
EOF
|
||||
source ${one_address}
|
||||
breaked=yes
|
||||
break
|
||||
fi
|
||||
done
|
||||
# 预设的用户配置文件都不存在 则新建一个.bash_profile文件 添加环境变量
|
||||
if [[ ${breaked} == "no" ]]; then
|
||||
echo "made file ${userAddress}/.bash_profile"
|
||||
echo "adding the installation address to ${userAddress}/.bash_profile"
|
||||
cat <<- EOF > ${userAddress}/.bash_profile
|
||||
# this is added by configure.sh of shell-template (zhangyi.cugwuhan@gmail.com)
|
||||
export PATH=${objectAddress}:\$PATH
|
||||
EOF
|
||||
source ${userAddress}/.bash_profile
|
||||
fi
|
||||
fi
|
||||
|
||||
#找到所有后缀名为.sh的脚本名称 存入数组
|
||||
scriptName=( `ls *.sh` )
|
||||
for element in ${scriptName[@]}; do
|
||||
#排除configure.sh
|
||||
if [[ $element != "configure.sh" ]]; then
|
||||
objectName=${element%.*}
|
||||
#若链接不存在 则建立
|
||||
if [[ ! -L ${objectAddress}/${objectName} ]]; then
|
||||
printf "creating links for ${objectName} ... "
|
||||
sudo ln -s ${folderAddress}/${element} ${objectAddress}/${objectName}
|
||||
printf "done\n"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
196
dispOptions.sh
Executable file
196
dispOptions.sh
Executable file
@@ -0,0 +1,196 @@
|
||||
#!/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 dispTitle(){
|
||||
winWidth=`tput cols`
|
||||
message=${2}
|
||||
|
||||
printf "%s\n%-9s" "${1}"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\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 dispAuthorInfo(){
|
||||
winWidth=`tput cols`
|
||||
message=${1}
|
||||
|
||||
printf "%-9s" "Author:"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\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 dispUsage(){
|
||||
winWidth=`tput cols`
|
||||
message=${1}
|
||||
|
||||
printf "%-9s" "Usage:"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\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 dispOptionShort(){
|
||||
winWidth=`tput cols`
|
||||
message=${2}
|
||||
|
||||
printf "%-4s%-5s" " " "${1}"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# 长命令说明 三个参数 短命令符号 长命令符号 命令说明
|
||||
#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
|
||||
#}
|
||||
|
||||
function dispOptionLong(){
|
||||
winWidth=`tput cols`
|
||||
message=${3}
|
||||
|
||||
printf "%-4s%-6s%-11s" " " "${1}" "${2}"
|
||||
|
||||
head_length=32
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-22s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
}
|
||||
10
generic_func.sh
Executable file
10
generic_func.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
function view_file(){
|
||||
sys_name=`uname -s`
|
||||
if [[ ${sys_name} == 'Linux' ]]; then
|
||||
xdg-open ${1}
|
||||
elif [[ ${sys_name} == 'Darwin' ]]; then
|
||||
open ${1}
|
||||
fi
|
||||
}
|
||||
105
gmt-colorBar.sh
Executable file
105
gmt-colorBar.sh
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 包含dispOption脚本
|
||||
. dispOptions.sh
|
||||
#GMT画一个色度条
|
||||
# 初始化参数
|
||||
data='null'
|
||||
unit='m'
|
||||
color='rainbow'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
opFile=0
|
||||
hori=''
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:v:os" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
dispTitle "${0##*/}" "plot a color bar 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."
|
||||
dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)"
|
||||
dispUsage "${0##*/} -i<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-c<cpt-file>] [-o] [-s] [-u<unit>] [-v<bar-tick>]"
|
||||
dispOptionShort "-i" "input grid file."
|
||||
dispOptionShort "-r" "data range. The template will detect the input data range automatically, the use of this option will overwrite the range."
|
||||
dispOptionShort "-c" "color cpt, The default is rainbow."
|
||||
dispOptionShort "-o" "open file in finder, the default is using imgcat."
|
||||
dispOptionShort "-s" "plot the color bar horizontally."
|
||||
dispOptionShort "-u" "data unit. The default is meter."
|
||||
dispOptionShort "-v" "intervals of color bar's labels. the script will set the intervals automatically if -v option is not set."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
o)
|
||||
opFile=1;;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
s)
|
||||
hori='+h';;
|
||||
?)
|
||||
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=thinnest,black \
|
||||
MAP_TICK_LENGTH_PRIMARY=1p/0.5p \
|
||||
MAP_TITLE_OFFSET=7p \
|
||||
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||
FONT_LABEL=7p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=WeSnZ \
|
||||
MAP_LABEL_OFFSET=2p \
|
||||
MAP_ANNOT_OFFSET_PRIMARY=2.5p
|
||||
|
||||
gmt grd2cpt ${data} -C${color} -R${range} -Z -D > $cptfile
|
||||
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
gmt psscale -Dx1.6i/0.1i+w1.2i/0.07i${hori} -C${cptfile}+Uk -Bx${bartick} -By+l${unit} > $psfile
|
||||
else
|
||||
gmt psscale -Dx1.6i/0.1i+w1.2i/0.07i${hori} -C${cptfile} -Bx${bartick} -By+l${unit} > $psfile
|
||||
fi
|
||||
gmt psconvert $psfile -A -TEG -E500
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $cptfile $psfile gmt.history gmt.conf
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
rm $gradfile
|
||||
fi
|
||||
if [[ $opFile == 1 ]]; then
|
||||
# 打开图片文件 此命令使用MacOS终端open命令
|
||||
open $jpgfile
|
||||
else
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
imgcat $jpgfile
|
||||
fi
|
||||
fi
|
||||
564
gmt_shell_functions.sh
Executable file
564
gmt_shell_functions.sh
Executable file
@@ -0,0 +1,564 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# These functions can be used from any sh/bash script by specifying
|
||||
# . gmt_shell_functions.sh
|
||||
# in your script. Placing it in .bashrc makes the functions available
|
||||
# on the command line as well. See documentation for usage.
|
||||
#
|
||||
# Note: Several of the original functions are now obsolete due to
|
||||
# new functionality in GMT. These are still available for use
|
||||
# but no longer documented and are placed at the end of this file
|
||||
# under the OBSOLETE tag.
|
||||
|
||||
#----GMT SHELL FUNCTIONS--------------------
|
||||
# Creates a unique temp directory and points GMT_TMPDIR to it
|
||||
gmt_init_tmpdir () {
|
||||
export GMT_TMPDIR=$(mktemp -d ${TMPDIR:-/tmp}/gmt.XXXXXX)
|
||||
}
|
||||
|
||||
# Remove the temp directory created by gmt_init_tmpdir
|
||||
gmt_remove_tmpdir () {
|
||||
rm -rf $GMT_TMPDIR
|
||||
unset GMT_TMPDIR
|
||||
}
|
||||
|
||||
# Remove all files and directories in which the current process number is part of the file name
|
||||
gmt_cleanup() {
|
||||
rm -rf *$$*
|
||||
if [ $# -eq 1 ]; then
|
||||
rm -rf ${1}*
|
||||
fi
|
||||
}
|
||||
|
||||
# Send a message to stderr
|
||||
gmt_message() {
|
||||
echo "$*" >&2
|
||||
}
|
||||
|
||||
# Print a message to stderr and exit
|
||||
gmt_abort() {
|
||||
echo "$*" >&2
|
||||
exit
|
||||
}
|
||||
|
||||
# Returns the number of fields or arguments
|
||||
gmt_get_nfields() {
|
||||
echo $* | awk '{print NF}'
|
||||
}
|
||||
# Same with backwards compatible name...
|
||||
gmt_nfields() {
|
||||
echo $* | awk '{print NF}'
|
||||
}
|
||||
|
||||
# Returns the given field (arg 1) in current record (arg 2)
|
||||
# Must pass arg 2 inside double quotes to preserve it as one item
|
||||
gmt_get_field() {
|
||||
echo $2 | cut -f$1 -d ' '
|
||||
}
|
||||
|
||||
# Return w/e/s/n from given table file(s)
|
||||
# May also add -Idx/dy to round off answer
|
||||
gmt_get_region() {
|
||||
printf "%s/%s/%s/%s\n" $(gmt info -C $* | cut -d' ' -f1-4)
|
||||
}
|
||||
|
||||
# Return the w/e/s/n from the header in grd file
|
||||
gmt_get_gridregion() {
|
||||
printf "%s/%s/%s/%s\n" $(gmt grdinfo -Cn $* | cut -d' ' -f1-4)
|
||||
}
|
||||
|
||||
# Make output PostScript file name based on script base name
|
||||
gmt_set_psfile() {
|
||||
echo $(basename $1 '.sh').ps
|
||||
}
|
||||
|
||||
# Make output PDF file name based on script base name
|
||||
gmt_set_pdffile() {
|
||||
echo $(basename $1 '.sh').pdf
|
||||
}
|
||||
|
||||
# For animations: Create a lexically increasing file namestem (no extension) based on prefix and frame number
|
||||
# i.e., prefix_######
|
||||
gmt_set_framename() {
|
||||
echo $1 $2 | awk '{printf "%s_%06d\n", $1, $2}'
|
||||
}
|
||||
|
||||
# For animations: Increment frame counter by one
|
||||
gmt_set_framenext() {
|
||||
echo $(($1 + 1))
|
||||
}
|
||||
|
||||
# For KMZ: Package a bunch of *.kml [and *.png] into a single kmz
|
||||
gmt_build_kmz() {
|
||||
if [ $# -eq 0 ]; then
|
||||
cat << EOF >&2
|
||||
gmt_build_kmz - Create a single KMZ file from many KML files
|
||||
|
||||
usage: gmt_build_kmz -p <prefix> [-r] *.kml [*.png]
|
||||
*.kml: The KML files you want to include in the KML file.
|
||||
If these link to local PNG files then list those too.
|
||||
-p Specify a prefix for naming the <prefix>.kmz file
|
||||
-r Remove all provided files after KMZ is built [leave alone]
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
if [ ! "X$1" = "X-p" ]; then
|
||||
echo "gmt_build_kmz: Requires -p <prefix> as first argument" >&2
|
||||
return
|
||||
fi
|
||||
remove=0
|
||||
name=$2 ; shift ; shift;
|
||||
if [ "X$1" = "X-r" ]; then
|
||||
remove=1
|
||||
shift
|
||||
fi
|
||||
mkdir -p kml; mv -f $* kml
|
||||
cat <<- EOF > doc.kml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||
<Document>
|
||||
EOF
|
||||
ls kml/*.kml > /tmp/$$.lis
|
||||
while read file; do
|
||||
name=$(basename $file .kml)
|
||||
cat << EOF >> doc.kml
|
||||
<NetworkLink>
|
||||
<name>$name</name>
|
||||
<Link>
|
||||
<href> $file </href>
|
||||
</Link>
|
||||
</NetworkLink>
|
||||
EOF
|
||||
done < /tmp/$$.lis
|
||||
cat << EOF >> doc.kml
|
||||
</Document>
|
||||
</kml>
|
||||
EOF
|
||||
zip -rq9 $name.kmz doc.kml kml
|
||||
if [ $remove -eq 0 ]; then
|
||||
mv -f kml/* ..
|
||||
fi
|
||||
rm -rf kml doc.kml /tmp/$$.lis
|
||||
}
|
||||
|
||||
# For animations: Build animated gif from stills
|
||||
gmt_build_gif() {
|
||||
if [ $# -eq 0 ]; then
|
||||
cat << EOF >&2
|
||||
gmt_build_gif - Process stills to animated gif with convert
|
||||
|
||||
usage: gmt_build_gif [-d <directory>] [-l <loop>] [-r <rate>] <prefix>
|
||||
<prefix> is the prefix of the still images and the resulting movie
|
||||
-d Specify path to of directory with the stills [current directory]
|
||||
-l Specify number of times to loop, 0 for continuous [0]
|
||||
-r Set frame rate in images per second [24]
|
||||
-n Dry-run. Do not run convert command, just print it
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
command -v ${GRAPHICSMAGICK-gm} >/dev/null 2>&1 || { echo "gmt_build_gif: Cannot find graphicsmagick in your path - exiting." >&2; return; }
|
||||
rate=24; dir=.; loop=0; dryrun=0
|
||||
while [ $# -ne 1 ]; do
|
||||
case "$1" in
|
||||
"-d") dir=$2 ; shift ;;
|
||||
"-l") loop=$2 ; shift ;;
|
||||
"-n") dryrun=1 ;;
|
||||
"-r") rate=$2 ; shift ;;
|
||||
*) echo "gmt_build_gif: No such option ($1)" >&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
delay=$(gmt math -Q 100 $rate DIV RINT =) # Delay to nearest 1/100 s
|
||||
if [ $dryrun -eq 1 ]; then
|
||||
cat <<- EOF
|
||||
${GRAPHICSMAGICK-gm} convert -delay $delay -loop $loop +dither "$dir/${1}_*.*" ${1}.gif
|
||||
EOF
|
||||
else
|
||||
${GRAPHICSMAGICK-gm} convert -delay $delay -loop $loop +dither "$dir/${1}_*.*" ${1}.gif
|
||||
echo "gmt_build_gif: GIF file is called ${1}.gif" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# For animations: Build a m4v movie from stills
|
||||
gmt_build_movie() {
|
||||
if [ $# -eq 0 ]; then
|
||||
cat << EOF >&2
|
||||
gmt_build_movie - Process stills to MP4 movie with ffmpeg
|
||||
Note: M4V Requires images to have an even pixel width
|
||||
|
||||
usage: gmt_build_movie [-d <directory>] [-n] [-r <rate>] [-v] <prefix>
|
||||
<prefix> is the prefix of the still images and the resulting movie
|
||||
-d Specify path to of directory with the stills [current directory]
|
||||
-r Set frame rate in images per second [24]
|
||||
-n Dry-run. Do not run ffmpeg command, just print it
|
||||
-v Verbose. Give progress messages
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
command -v ffmpeg >/dev/null 2>&1 || { echo "gmt_build_movie: Cannot find ffmpeg in your path - exiting." >&2; return; }
|
||||
rate=24; dir=.; dryrun=0; blabber=quiet
|
||||
while [ $# -ne 1 ]; do
|
||||
case "$1" in
|
||||
"-d") dir=$2 ; shift ;;
|
||||
"-n") dryrun=1 ;;
|
||||
"-r") rate=$2 ; shift ;;
|
||||
"-v") blabber=verbose ;;
|
||||
*) echo "gmt_build_movie: No such option ($1)" >&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if [ $dryrun -eq 1 ]; then
|
||||
cat <<- EOF
|
||||
ffmpeg -loglevel $blabber -f image2 -pattern_type glob -framerate $rate -y -i "$dir/$1_*.*" -pix_fmt yuv420p ${1}.m4v
|
||||
EOF
|
||||
else
|
||||
ffmpeg -loglevel $blabber -f image2 -pattern_type glob -framerate $rate -y -i "$dir/$1_*.*" -pix_fmt yuv420p ${1}.m4v
|
||||
echo "gmt_build_movie: MP4 file is called ${1}.m4v" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# For animations: Build an animation script template
|
||||
gmt_movie_script() {
|
||||
if [ $# -eq 0 ]; then
|
||||
cat << EOF >&2
|
||||
gmt_movie_script - Create template script for animation
|
||||
|
||||
usage: gmt_movie_script [-c <canvas>] [-e <dpi>] [-f <format>] [-g <fill>] [-h <height>]
|
||||
[-m <margin>] [-n <frames>] [-r <rate>] [-w <width>] <prefix>
|
||||
|
||||
-c Specify a standard canvas size: 360p, 480p, 720p, 1080p, or 4k
|
||||
The dpi will be set automatically for a ~pagesize plot
|
||||
Alternatively, specify -e -h and -w separately
|
||||
-e Image resolution in dots per inch [100]
|
||||
-f Video format: GIF, MP4, none [none]
|
||||
-g Canvas color [white]
|
||||
-h Specify image height [in inches]
|
||||
-m Plot margins [1 inch]
|
||||
-n Number of frames to produce [1]
|
||||
-r Set frame rate per second [1]
|
||||
-w Specify image width [in inches]
|
||||
-u Create Web page template [no web page]. Requires -f
|
||||
|
||||
<prefix> is the required naming prefix of the animation products.
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
all_args="$*"
|
||||
dpi=100; fill=white; nframes=1; margin=1; rate=1; vformat=none; web=0; width=""; height=""
|
||||
while [ $# -ne 1 ]; do
|
||||
case "$1" in
|
||||
"-c") canvas=$2 ; shift ;;
|
||||
"-e") dpi=$2 ; shift ;;
|
||||
"-g") fill=$2 ; shift ;;
|
||||
"-f") vformat=$2 ; shift ;;
|
||||
"-h") height=$2 ; shift ;;
|
||||
"-n") nframes=$2 ; shift ;;
|
||||
"-m") margin=$2 ; shift ;;
|
||||
"-r") rate=$2 ; shift ;;
|
||||
"-w") width=$2 ; shift ;;
|
||||
"-u") web=1 ;;
|
||||
*) echo "gmt_movie_script: No such option ($1)" >&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
name=$1
|
||||
if [ "X$width" = "X" ]; then # Gave canvas, must set width, height, dpi
|
||||
if [ "$canvas" = "360p" ]; then
|
||||
width=4.80; height=3.60
|
||||
elif [ "$canvas" = "480p" ]; then
|
||||
width=6.40; height=4.80
|
||||
elif [ "$canvas" = "720p" ]; then
|
||||
width=12.80; height=7.20
|
||||
elif [ "$canvas" = "1080p" ]; then
|
||||
width=9.60; height=5.40; dpi=200
|
||||
elif [ "$canvas" = "4k" ]; then
|
||||
width=9.60; height=5.40; dpi=400
|
||||
fi
|
||||
fi
|
||||
w=$(gmt math -Q ${width} ${margin} 2 MUL SUB =)
|
||||
h=$(gmt math -Q ${height} ${margin} 2 MUL SUB =)
|
||||
iw=$(gmt math -Q ${width} $dpi MUL =)
|
||||
ih=$(gmt math -Q ${height} $dpi MUL =)
|
||||
now=$(date)
|
||||
you=$(finger $LOGNAME | head -1 | awk -F': ' '{print $3}')
|
||||
cat << EOF > $name.sh
|
||||
#!/usr/bin/env bash
|
||||
# Author: $you
|
||||
# Purpose: Make an animation of ...
|
||||
# Date: $now
|
||||
# Command: gmt_movie_script $all_args
|
||||
#
|
||||
. gmt_shell_functions.sh # Load in the gmt functions
|
||||
#---------------------------------------------------------------------------------
|
||||
# 1. INITIALIZATIONS:
|
||||
#---------------------------------------------------------------------------------
|
||||
# 1a. Set animation parameters:
|
||||
# Canvas settings:
|
||||
CANVAS_WIDTH=${width} # The width of your paper canvas [in inch]
|
||||
CANVAS_HEIGHT=${height} # The height of your paper canvas [in inch]
|
||||
CANVAS_FILL=${fill} # The color of your paper canvas [in inch]
|
||||
# Video settings:
|
||||
VIDEO_DPI=$dpi # Rasterization in dots per inch [$dpi]
|
||||
VIDEO_FORMAT=$vformat # Type of animation product [GIF|MP4|none]
|
||||
VIDEO_FRAMES=$nframes # Number of frames in the movie
|
||||
VIDEO_RATE=$rate # Frame rate (frames per sec)
|
||||
VIDEO_PREFIX=$name # The prefix of the movie products
|
||||
# Plot settings:
|
||||
PLOT_WIDTH=${w}i # The maximum map width given your margins [in inch]
|
||||
PLOT_HEIGHT=${h}i # The maximum map height given your margins [in inch]
|
||||
PLOT_PDF=yes # Make a PDF of the first frame and stop [yes|no]
|
||||
PLOT_XMARGIN=${margin}i # Spacing between edge and map frame on left [in inch]
|
||||
PLOT_YMARGIN=${margin}i # Spacing between edge and map frame on bottom [in inch]
|
||||
R=0/100/0/60 # Your data region [CHANGE THIS]
|
||||
J=X\${PLOT_WIDTH}/\${PLOT_HEIGHT} # Your projection [CHANGE THIS]
|
||||
#---------------------------------------------------------------------------------
|
||||
# 1b. Set the common -R -J -O -K sequence as string RJOK:
|
||||
RJOK="-R\${R} -J\${J} -O -K"
|
||||
|
||||
# 1c. Make a clean folder that will hold all the frame images
|
||||
rm -rf \${VIDEO_PREFIX}; mkdir -p \${VIDEO_PREFIX}
|
||||
|
||||
# Design your plot(s) to fit inside the canvas size. It is up to you
|
||||
# to select reasonable -R -J settings so that items fit. Ultimately, the
|
||||
# size of each video frame will be determined by the expression
|
||||
# w x h = [\${CANVAS_WIDTH} * \$VIDEO_DPI] by [\${CANVAS_HEIGHT} * \$VIDEO_DPI]
|
||||
# which currently is $iw x $ih pixels. Add your plot code between the
|
||||
# FRAME PLOT BEGIN -- END lines, using overlay mode (-O -K).
|
||||
# Temporary files named <prefix>.\$\$\.<extension> will be deleted automatically.
|
||||
|
||||
# 1d. Frame-independent assignments and calculations go here:
|
||||
|
||||
# 1e. Create filled canvas as first layer in the GMT cake, then set origin.
|
||||
gmt psbasemap -R0/\${CANVAS_WIDTH}/0/\${CANVAS_HEIGHT} -Jx1i -P -K -X0 -Y0 -B+n+g\${CANVAS_FILL} \\
|
||||
--PS_MEDIA=\${CANVAS_WIDTH}ix\${CANVAS_HEIGHT}i > background.\$\$.ps
|
||||
gmt psxy -R -J -O -K -T -X\${PLOT_XMARGIN} -Y\${PLOT_YMARGIN} >> background.\$\$.ps
|
||||
|
||||
# 1f. Add frame-independent background layers to background.\$\$.ps
|
||||
# The next line is an example that can be modified or removed.
|
||||
gmt psbasemap \${RJOK} -Baf -B+gpink >> background.\$\$.ps
|
||||
|
||||
# 1g. Add frame-indendent foreground layers to foreground.\$\$.ps
|
||||
# Place more plotting commands BEFORE next line, if needed.
|
||||
gmt psxy -R -J -O -T >> foreground.\$\$.ps
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 2. MAIN FRAME LOOP
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
let frame=0
|
||||
while [ \$frame -lt \${VIDEO_FRAMES} ]; do
|
||||
echo "Working on frame \$frame" >&2
|
||||
# 2a. Set current frame prefix for lexically increasing file name
|
||||
ps=\$(gmt_set_framename \${VIDEO_PREFIX} \$frame\).ps
|
||||
|
||||
# 2b. Perform any calculations that depends on the frame number
|
||||
|
||||
# 2c. Start the current frame with the background layer
|
||||
cp background.\$\$.ps \$ps
|
||||
|
||||
# 2d. Append overlays to file \$ps; add \$RJOK to all commands
|
||||
# FRAME PLOT BEGIN
|
||||
# ==> Add your frame-specific plotting here
|
||||
# FRAME PLOT END
|
||||
|
||||
# 2e. Append the foreground layer
|
||||
cat foreground.\$\$.ps >> \$ps
|
||||
|
||||
if [ \$frame -eq 0 ] && [ "\${PLOT_PDF}" == "yes" ]; then
|
||||
# 2f. Make a PDF of first frame only and break out
|
||||
pdf=\${VIDEO_PREFIX}
|
||||
gmt psconvert -Tf -P -Z -F\$pdf \$ps
|
||||
echo "Made PDF of first frame: \$pdf.pdf" >&2
|
||||
echo "[Set PLOT_PDF to no to build all frames]" >&2
|
||||
break
|
||||
fi
|
||||
|
||||
# 2g. Convert frame to PNG and save to image folder
|
||||
gmt psconvert -Tg -E\${VIDEO_DPI} -P -D\${VIDEO_PREFIX} -Z \$ps
|
||||
let frame=frame+1 # Increment frame counter
|
||||
done
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 3. CONVERT IMAGES TO AN ANIMATION FORMAT
|
||||
#---------------------------------------------------------------------------------
|
||||
if [ "\${PLOT_PDF}" == "no" ]; then
|
||||
if [ "\${VIDEO_FORMAT}" = "GIF" ]; then
|
||||
# Make an animated GIF:
|
||||
gmt_build_gif -d \${VIDEO_PREFIX} -r \${VIDEO_RATE} -l 0 \${VIDEO_PREFIX}
|
||||
elif [ "\${VIDEO_FORMAT}" = "MP4" ]; then
|
||||
# Make a MP4 movie:
|
||||
gmt_build_movie -d \${VIDEO_PREFIX} -r \${VIDEO_RATE} \${VIDEO_PREFIX}
|
||||
fi
|
||||
echo "The individual frames can be found in directory \${VIDEO_PREFIX}" >&2
|
||||
fi
|
||||
#---------------------------------------------------------------------------------
|
||||
# 4. REMOVE ALL TEMPORARY FILES WITH PROCESS ID IN THE NAME
|
||||
#---------------------------------------------------------------------------------
|
||||
rm -f *.\$\$.*
|
||||
EOF
|
||||
chmod +x $name.sh
|
||||
echo "gmt_movie_script: Animation script template $name.sh created" >&2
|
||||
if [ "${vformat}" = "none" ]; then
|
||||
web=0
|
||||
fi
|
||||
# Generate the HTML template if a graphics format was selected
|
||||
if [ $web -eq 1 ]; then
|
||||
cat << EOF > $name.html
|
||||
<HTML>
|
||||
<TITLE>Title of the Web Page</TITLE>
|
||||
<BODY bgcolor="ffffff">
|
||||
<CENTER>
|
||||
<H1>Title of the Web Page</H1>
|
||||
EOF
|
||||
if [ "${vformat}" = "GIF" ]; then
|
||||
echo "<IMG src=\"$name.gif\">" >> $name.html
|
||||
else
|
||||
cat << EOF >> $name.html
|
||||
<video controls>
|
||||
<source src="$name.m4v" type="video/mp4">
|
||||
Your browser does not appear to support video controls
|
||||
</video>
|
||||
EOF
|
||||
fi
|
||||
cat << EOF >> $name.html
|
||||
</CENTER>
|
||||
Please add a movie caption here.
|
||||
<HR>
|
||||
<I>Created by $you on $(date)</I>
|
||||
</BODY>
|
||||
</HTML>
|
||||
EOF
|
||||
echo "gmt_movie_script: Animation web template $name.html created" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# For spreading numerous commands across many CPUs in clusters of N lines
|
||||
gmt_launch_jobs() {
|
||||
# gmt_launch_jobs -c <n_cpu> -j <nlines_per_cluster> <commandfile>
|
||||
# Split the non-comment records in <commandfile> into <n_cpu> files
|
||||
# so that number of lines per file is a multiple of <nlines_per_cluster>.
|
||||
n_cpu=$(gmt --show-cores)
|
||||
if [ $# -eq 0 ]; then
|
||||
cat << EOF >&2
|
||||
gmt_launch_jobs - Run chunks of commands in parallel
|
||||
|
||||
usage: gmt_launch_jobs [-c <n_cpu>] [-l <nlines_per_cluster>] [-n] [-v] [-w] <commandfile>
|
||||
<commandfile> is a file with a list of all the commands
|
||||
-c Specify how many separate cores to use [$n_cpu]
|
||||
-l Specify how many lines constitute one job cluster [1]
|
||||
-n Dry-run. Do not launch jobs but leave core scripts as /tmp/gmt_launch_jobs.##.sh
|
||||
-r Remove core scripts when the jobs complete
|
||||
-v Verbose. Give progress messages
|
||||
-w Wait for completion of all core jobs before exiting
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
n_lines=1; do_wait=0; do_remove=0; dryrun=0; blabber=0
|
||||
while [ $# -ne 1 ]; do
|
||||
case "$1" in
|
||||
"-c") n_cpu=$2 ; shift ;;
|
||||
"-l") n_lines=$2 ; shift ;;
|
||||
"-n") dryrun=1 ;;
|
||||
"-r") do_remove=1 ;;
|
||||
"-v") blabber=1 ;;
|
||||
"-w") do_wait=1 ;;
|
||||
*) echo "gmt_launch_jobs: No such option ($1)" >&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
egrep -v '^#|^$' $1 > /tmp/$$.sh
|
||||
nL=$(wc -l /tmp/$$.sh | awk '{printf "%d\n", $1}')
|
||||
n_chunks=$(gmt math -Q $nL $n_lines DIV =)
|
||||
bad=$(gmt math -Q $n_chunks DUP RINT SUB ABS 1e-10 GT =)
|
||||
if [ $bad -eq 1 ]; then
|
||||
echo "gmt_launch_jobs: Your number of commands is not a multiple of $n_lines" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $n_chunks -lt $n_cpu ]; then
|
||||
echo "gmt_launch_jobs: Less chunks than cores; only using $n_cpu processors" >&2
|
||||
let n_cpu=n_chunks
|
||||
fi
|
||||
if [ $dryrun -eq 1 ]; then
|
||||
tag=
|
||||
else
|
||||
tag="."$$
|
||||
fi
|
||||
# Create n_cpu empty files for execution
|
||||
let cpu=0
|
||||
while [ $cpu -lt $n_cpu ]; do
|
||||
printf "#!/usr/bin/env bash\n# gmt_launch_jobs command file chunk # ${cpu}\n#---------------------------------\n" > /tmp/gmt_launch_jobs${tag}.$cpu.sh
|
||||
let cpu=cpu+1
|
||||
done
|
||||
# Distribute $n_lines from the commands across these core scripts
|
||||
let chunk=0; let cpu=0; let sub=n_lines-1; let last=0
|
||||
while [ $chunk -lt $n_chunks ]; do
|
||||
let last=last+n_lines
|
||||
let first=last-sub
|
||||
sed -n ${first},${last}p /tmp/$$.sh >> /tmp/gmt_launch_jobs${tag}.$cpu.sh
|
||||
let cpu=cpu+1
|
||||
if [ $cpu -eq $n_cpu ]; then
|
||||
let cpu=0
|
||||
fi
|
||||
let chunk=chunk+1
|
||||
done
|
||||
# Launch the $n_cpu scripts
|
||||
let cpu=0
|
||||
while [ $cpu -lt $n_cpu ]; do
|
||||
if [ $blabber -eq 1 ]; then
|
||||
echo "gmt_launch_jobs: Starting /tmp/gmt_launch_jobs${tag}.$cpu.sh" >&2
|
||||
fi
|
||||
if [ $do_remove -eq 1 ]; then
|
||||
echo "rm -f /tmp/gmt_launch_jobs${tag}.$cpu.sh" >> /tmp/gmt_launch_jobs${tag}.$cpu.sh
|
||||
fi
|
||||
if [ $dryrun -eq 0 ]; then
|
||||
bash /tmp/gmt_launch_jobs${tag}.$cpu.sh &
|
||||
fi
|
||||
let cpu=cpu+1
|
||||
done
|
||||
rm -f /tmp/$$.sh
|
||||
if [ $do_wait -eq 1 ] && [ $dryrun -eq 0 ]; then
|
||||
wait # Wait until all jobs launched by this script have completed
|
||||
if [ $blabber -eq 1 ]; then
|
||||
echo "gmt_launch_jobs: All $n_cpu jobs completed" >&2
|
||||
fi
|
||||
fi
|
||||
}
|
||||
#===================================================================================
|
||||
# OBSOLETE: These functions are supported but obsoleted by new GMT built-in features
|
||||
#===================================================================================
|
||||
|
||||
# Backwards compatible functions in use before -W was introduced in mapproject 5.2:
|
||||
# Return the current map width (expects -R and -J settings)
|
||||
gmt_get_map_width() {
|
||||
gmt mapproject $* -Ww
|
||||
}
|
||||
# Same with backwards compatible name...
|
||||
gmt_map_width() {
|
||||
gmt mapproject $* -Ww
|
||||
}
|
||||
|
||||
# Return the current map height (expects -R and -J settings)
|
||||
gmt_get_map_height() {
|
||||
gmt mapproject $* -Wh
|
||||
}
|
||||
# and with backwards compatible name...
|
||||
gmt_map_height() {
|
||||
gmt mapproject $* -Wh
|
||||
}
|
||||
# Return integer total number of lines in the file(s). Obsolete since 5.4.0
|
||||
gmt_get_nrecords() {
|
||||
gmt info -Fi -o4 $*
|
||||
}
|
||||
# Same with backwards compatible name...
|
||||
gmt_nrecords() {
|
||||
gmt info -Fi -o4 $*
|
||||
}
|
||||
|
||||
# Return integer total number of data records in the file(s). Obsolete since 5.4.0
|
||||
gmt_get_ndatarecords() {
|
||||
gmt info -Fi -o2 $*
|
||||
}
|
||||
153
gmtsph-JA.sh
Executable file
153
gmtsph-JA.sh
Executable file
@@ -0,0 +1,153 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 包含dispOption脚本
|
||||
. dispOptions.sh
|
||||
#GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本
|
||||
# 初始化参数
|
||||
data='null'
|
||||
gridData='null'
|
||||
unit='m'
|
||||
color='rainbow -Z'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("longitude (degree)" "latitude (degree)")
|
||||
plotgrad=0
|
||||
nocpt=0
|
||||
plotsun=0
|
||||
clon=("0/0/115" "180/0/115")
|
||||
polyfile='null'
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:a:v:G:l:p:gsn" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
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<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-l<clon>/<clat>/<horizon>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-v<c-tick>] [-g] [-s] [-G<grad-data>] [-p<polygon-file>]"
|
||||
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;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
n)
|
||||
nocpt=1;;
|
||||
s)
|
||||
plotsun=1;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
l)
|
||||
clon=(${OPTARG//,/ });;
|
||||
a)
|
||||
labels=(${OPTARG//,/ });;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
G)
|
||||
gridData=$OPTARG;;
|
||||
p)
|
||||
polyfile=$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_gridregion ${data})
|
||||
fi
|
||||
# 设置绘图参数
|
||||
gmt gmtset \
|
||||
FONT_ANNOT_PRIMARY=8p,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_PEN_PRIMARY=thinnest,black,-- \
|
||||
MAP_GRID_PEN_SECONDARY=thinnest,black,-- \
|
||||
FONT_LABEL=8p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=WESnZ \
|
||||
MAP_LABEL_OFFSET=2.5p
|
||||
|
||||
# 设置色标文件
|
||||
if [[ $nocpt == 1 ]]; then
|
||||
cptfile=${color}
|
||||
else
|
||||
gmt grd2cpt ${data} -R${range} -C${color} -D -M > $cptfile
|
||||
fi
|
||||
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
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
|
||||
gradPlotCommand=-I${gradfile}
|
||||
else
|
||||
gradPlotCommand=""
|
||||
fi
|
||||
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} $gradPlotCommand -Bxa30g30+l"${labels[0]}" -Bpya30g30+l"${labels[1]}" -JA${clon[0]}/1.5i -K -P > $psfile
|
||||
if [[ $plotsun == 1 ]]; then
|
||||
gmt pssolar -R${range} -JA${clon[0]}/1.5i -Td+d2016-02-09T16:00:00 -Gblack@75 -K -O >> $psfile
|
||||
fi
|
||||
if [[ $polyfile != 'null' ]]; then
|
||||
gmt psxy $polyfile -JA${clon[0]}/1.5i -R${range} -L -K -O >> $psfile
|
||||
fi
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} $gradPlotCommand -Bxa30g30+l"${labels[0]}" -Bpya30g30+l"${labels[1]}" -JA${clon[1]}/1.5i -X1.7i -K -O >> $psfile
|
||||
if [[ $plotsun == 1 ]]; then
|
||||
gmt pssolar -R${range} -JA${clon[1]}/1.5i -Td+d2016-02-09T16:00:00 -Gblack@75 -K -O >> $psfile
|
||||
fi
|
||||
if [[ $polyfile != 'null' ]]; then
|
||||
gmt psxy $polyfile -JA${clon[1]}/1.5i -R${range} -L -K -O >> $psfile
|
||||
fi
|
||||
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
gmt psscale -I -Dx0.85i/-0.2i+w1.5i/0.05i+h -C${cptfile}+Uk -Bx${bartick} -By+l"km" -X-1.7i -O >> $psfile
|
||||
else
|
||||
gmt psscale -I -Dx0.85i/-0.2i+w1.5i/0.05i+h -C${cptfile} -Bx${bartick} -By+l${unit} -X-1.7i -O >> $psfile
|
||||
fi
|
||||
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
|
||||
2
sph_global_dot.sh → gmtsph-global-dot.sh
Normal file → Executable file
2
sph_global_dot.sh → gmtsph-global-dot.sh
Normal file → Executable file
@@ -79,7 +79,7 @@ else
|
||||
gmt psxy ${data} -i${cols} -Bxag+l"${labels[0]}" -B+ggrey -Bpya40g40+l"${labels[1]}" -JN0/3i -R${range} -C${cptfile} -Sc0.04c -Gblack -P -K > $psfile
|
||||
#-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
|
||||
gmt psconvert $psfile -A -TEG -E300
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $cptfile $psfile gmt.history gmt.conf
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
137
gmtsph-global.sh
Executable file
137
gmtsph-global.sh
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 包含dispOption脚本
|
||||
. dispOptions.sh
|
||||
#GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本
|
||||
# 初始化参数
|
||||
data='null'
|
||||
gridData='null'
|
||||
unit='m'
|
||||
color='rainbow'
|
||||
direct_cpt='user.cpt'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("longitude (degree)" "latitude (degree)")
|
||||
plotgrad=0
|
||||
clon=0
|
||||
polyfile='null'
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:C:a:G:l:p:v:g" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
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<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-l<lon>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-g] [-G<grad-data>] [-p<polygon-file>]"
|
||||
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 "-C" "color cpt. Use the input cpt file directly."
|
||||
dispOptionShort "-v" "intervals of color bar's labels. the script will set the intervals automatically if -v option is not set."
|
||||
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;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
C)
|
||||
direct_cpt=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
l)
|
||||
clon=$OPTARG;;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
a)
|
||||
labels=(${OPTARG//,/ });;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
G)
|
||||
gridData=$OPTARG;;
|
||||
p)
|
||||
polyfile=$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=${direct_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=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=7p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=WESnZ \
|
||||
MAP_LABEL_OFFSET=2.5p
|
||||
|
||||
if [[ $cptfile == 'user.cpt' ]]; then
|
||||
gmt grd2cpt ${data} -C${color} -Z -D > $cptfile
|
||||
fi
|
||||
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
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}/2i -K -P > $psfile
|
||||
else
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Bpya40g40+l"${labels[1]}" -JN${clon}/2i -K -P > $psfile
|
||||
fi
|
||||
if [[ $polyfile != 'null' ]]; then
|
||||
#-L force closed polygon
|
||||
#gmt psxy $polyfile -JN${clon}/2i -R${range} -L -K -O >> $psfile
|
||||
gmt psxy $polyfile -JN${clon}/2i -R${range} -W0.1p -K -O >> $psfile
|
||||
fi
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
gmt psscale -Dx0.4i/-0.3i+w1.2i/0.05i+h -C${cptfile}+Uk -Bx${bartick} -By+l"km" -O >> $psfile
|
||||
else
|
||||
gmt psscale -Dx0.4i/-0.3i+w1.2i/0.05i+h -C${cptfile} -Bx${bartick} -By+l${unit} -O >> $psfile
|
||||
fi
|
||||
gmt psconvert $psfile -A -TEG -E300
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
if [[ $cptfile == 'user.cpt' ]]; then
|
||||
rm $cptfile
|
||||
fi
|
||||
rm $psfile gmt.history gmt.conf
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
rm $gradfile
|
||||
fi
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
#imgcat $jpgfile
|
||||
# 打开图片文件 此命令使用MacOS终端open命令
|
||||
open $jpgfile
|
||||
fi
|
||||
7
gmtsph-profile.sh
Normal file → Executable file
7
gmtsph-profile.sh
Normal file → Executable file
@@ -69,19 +69,20 @@ else
|
||||
# 设置绘图参数
|
||||
gmt gmtset \
|
||||
COLOR_NAN=grey \
|
||||
FONT_ANNOT_PRIMARY=7p,Times-Roman,black \
|
||||
FONT_ANNOT_PRIMARY=10.5p,Times-Roman,black \
|
||||
MAP_FRAME_PEN=thin,black \
|
||||
MAP_TICK_LENGTH_PRIMARY=2p/1p \
|
||||
MAP_TITLE_OFFSET=7p \
|
||||
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||
FONT_LABEL=7p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=wEsNZ \
|
||||
COLOR_NAN=white \
|
||||
MAP_LABEL_OFFSET=4p
|
||||
|
||||
gmt grd2cpt ${data} -C${color} -Z -D > $cptfile
|
||||
gmt grd2cpt ${data} -C${color} -Z -D -M > $cptfile
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JPa3i/${offangle}z -K -Y1i -P > $psfile
|
||||
gmt psscale -Dx0.4i/-0.25i+w2.2i/0.1i+h -C${cptfile} -Bxa -By+l${unit} -O >> $psfile
|
||||
gmt psconvert $psfile -A -TeG -E300
|
||||
gmt psconvert $psfile -A -TEG -E300
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $cptfile $psfile gmt.history gmt.conf
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
|
||||
189
gmtsph-regional.sh
Executable file
189
gmtsph-regional.sh
Executable file
@@ -0,0 +1,189 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
#GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本
|
||||
# 初始化参数
|
||||
data='null'
|
||||
gridData='null'
|
||||
unit='m'
|
||||
color='rainbow'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("longitude (degree)" "latitude (degree)")
|
||||
plot_para=(0 0 0 0)
|
||||
plotgrad=0
|
||||
nocpt=0
|
||||
inverseCPT=0
|
||||
coastline=0
|
||||
axistick=("a" "a") #横纵坐标轴间隔 a表示自动
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
polyfile='null'
|
||||
# 不同图幅的绘图参数
|
||||
pageChoice='small' # 默认尺寸为small
|
||||
exSmallpage="1i,0.08i/-0.25i,0.85i/0.03i"
|
||||
smallPage="1.5i,0.125i/-0.3i,1.2i/0.05i" # 图大小,色标位置,色标尺寸
|
||||
middlePage="2i,0.2i/-0.35i,1.5i/0.05i"
|
||||
largePage="2.5i,0.35i/-0.4i,1.75i/0.08i"
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:a:t:v:l:G:s: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<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] [-c<cpt-file>] [-a<x-label>,<y-label>] [-t<x-tick>,<y-tick>] [-v<c-tick>] [-l<size>] [-g] [-G<grad-data>] [-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."
|
||||
printf "%s\t%s\n" "-c" "color cpt. The default is rainbow. The script will use grd2cpt to recalculate the color scale file, use -n option to disable the use of grd2cpt."
|
||||
printf "%s\t%s\n" "-a" "axis labels. The deafults are x (m) and y (m)."
|
||||
printf "%s\t%s\n" "-t" "intervals of axis's labels. the script will set the intervals automatically if -t option is not set."
|
||||
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" "-l" "image layout and size. three available options are exsmall, 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."
|
||||
printf "%s\t%s\n" "-s" "plot polygons via a file."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
a)
|
||||
labels=(${OPTARG//,/ });;
|
||||
t)
|
||||
axistick=(${OPTARG//,/ });;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
l)
|
||||
pageChoice=$OPTARG;;
|
||||
b)
|
||||
coastline=1;;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
G)
|
||||
gridData=$OPTARG;;
|
||||
n)
|
||||
nocpt=1;;
|
||||
p)
|
||||
inverseCPT=1;;
|
||||
s)
|
||||
polyfile=$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=${data%.*}.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=7.5p,Times-Roman,black \
|
||||
MAP_FRAME_PEN=thinnest,black \
|
||||
MAP_FRAME_WIDTH=1p \
|
||||
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=8p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=WESnZ \
|
||||
COLOR_NAN=white \
|
||||
MAP_LABEL_OFFSET=1p\
|
||||
MAP_ANNOT_OFFSET_PRIMARY=2.5p
|
||||
# 设置色标文件
|
||||
if [[ $nocpt == 1 ]]; then
|
||||
cptfile=${color}
|
||||
else
|
||||
if [[ $inverseCPT == 1 ]]; then
|
||||
gmt grd2cpt ${data} -R${range} -C${color} -D -M -I > $cptfile
|
||||
else
|
||||
gmt grd2cpt ${data} -R${range} -C${color} -D -M > $cptfile
|
||||
fi
|
||||
fi
|
||||
# 设置绘图尺寸 如果识别参数失败 则还是按small处理
|
||||
if [[ $pageChoice == 'small' ]]; then
|
||||
pagePara=(${smallPage//,/ })
|
||||
elif [[ $pageChoice == 'exsmall' ]]; then
|
||||
pagePara=(${exSmallpage//,/ })
|
||||
elif [[ $pageChoice == 'middle' ]]; then
|
||||
pagePara=(${middlePage//,/ })
|
||||
elif [[ $pageChoice == 'large' ]]; then
|
||||
pagePara=(${largePage//,/ })
|
||||
else
|
||||
pagePara=(${smallPage//,/ })
|
||||
fi
|
||||
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
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} -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
|
||||
fi
|
||||
|
||||
if [[ $coastline == 1 ]]; then
|
||||
gmt pscoast -R${range} -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/${pagePara[0]} -W0.25p -Dc -A5000 -K -O -P >> $psfile
|
||||
fi
|
||||
|
||||
if [[ $polyfile != 'null' ]]; then
|
||||
gmt psxy ${polyfile} -JL${plot_para[0]}/${plot_para[1]}/${plot_para[2]}/${plot_para[3]}/${pagePara[0]} -W0.25p -R${range} -L -K -O >> $psfile
|
||||
fi
|
||||
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
gmt psscale -Dx${pagePara[1]}+w${pagePara[2]}+h -C${cptfile}+Uk -Bx${bartick} -By+l"km" -O >> $psfile
|
||||
else
|
||||
gmt psscale -Dx${pagePara[1]}+w${pagePara[2]}+h -C${cptfile} -Bx${bartick} -By+l${unit} -O >> $psfile
|
||||
fi
|
||||
gmt psconvert $psfile -A -TEG -E300
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $psfile gmt.history gmt.conf
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
rm $gradfile
|
||||
fi
|
||||
if [[ $nocpt == 0 ]]; then
|
||||
rm $cptfile
|
||||
fi
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
#imgcat $jpgfile
|
||||
# 打开图片文件 此命令使用MacOS终端open命令
|
||||
open $jpgfile
|
||||
fi
|
||||
14
xy_dot.sh → gmtxy-dot.sh
Normal file → Executable file
14
xy_dot.sh → gmtxy-dot.sh
Normal file → Executable file
@@ -10,9 +10,10 @@ overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("x (m)" "y (m)")
|
||||
valuerange="0/1000/10"
|
||||
noshow=0
|
||||
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:a:d:" arg
|
||||
while getopts "hqi:r:u:c:a:d:" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
@@ -25,6 +26,7 @@ For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (z
|
||||
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" "-q" "do not show the output figure."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
@@ -39,6 +41,8 @@ For futher explanations, please look for GMT's manuscripts.\nAuthor: Yi Zhang (z
|
||||
labels=(${OPTARG//,/ });;
|
||||
d)
|
||||
valuerange=$OPTARG;;
|
||||
q)
|
||||
noshow=1;;
|
||||
?)
|
||||
printf "error: unknow argument\nuse -h option to see help information\n"
|
||||
exit 1;;
|
||||
@@ -72,13 +76,15 @@ else
|
||||
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 psxy ${data} -Bxag+l"${labels[0]}" -Byag+l"${labels[1]}" -JX5i -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
|
||||
gmt psconvert $psfile -A -TEG -E300
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $cptfile $psfile gmt.history gmt.conf
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
#imgcat $jpgfile
|
||||
# 打开图片文件 此命令使用MacOS终端open命令
|
||||
open $jpgfile
|
||||
if [[ ${noshow} == 0 ]]; then
|
||||
open $jpgfile
|
||||
fi
|
||||
fi
|
||||
124
gmtxy-image.sh
Executable file
124
gmtxy-image.sh
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
#GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本
|
||||
# 初始化参数
|
||||
data='null'
|
||||
gridData='null'
|
||||
unit='m'
|
||||
color='rainbow'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("x (m)" "y (m)")
|
||||
plotgrad=0
|
||||
axistick=("a" "a") #横纵坐标轴间隔 a表示自动
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:u:c:a:G:t:v: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 further 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" "-t" "intervals of axis's labels. the script will set the intervals automatically if -t option is not set."
|
||||
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" "-a" "axis labels separated by semicolons. 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;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
t)
|
||||
axistick=(${OPTARG//,/ });;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
a)
|
||||
OLD_IFS="${IFS}"
|
||||
IFS=";"
|
||||
labels=(${OPTARG})
|
||||
IFS="${OLD_IFS}";;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
G)
|
||||
gridData=$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_gridregion ${data})
|
||||
fi
|
||||
#根据横纵坐标的范围计算图片的长和高 我们默认图片宽度为1.5i
|
||||
range_coor=(${range//// })
|
||||
pic_height=`echo "scale=4; 1.5 * (${range_coor[3]} - ${range_coor[2]})/(${range_coor[1]} - ${range_coor[0]})"|bc`
|
||||
# 设置绘图参数
|
||||
gmt gmtset \
|
||||
FONT_ANNOT_PRIMARY=10.5p,Times-Roman,black \
|
||||
MAP_FRAME_PEN=thinnest,black \
|
||||
MAP_GRID_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_LENGTH_PRIMARY=1p/0.5p \
|
||||
MAP_TITLE_OFFSET=7.5p \
|
||||
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||
FONT_LABEL=10.5p,Times-Roman,black \
|
||||
MAP_FRAME_AXES=wEsNZ \
|
||||
MAP_LABEL_OFFSET=2.5p \
|
||||
MAP_ANNOT_OFFSET_PRIMARY=2.5p
|
||||
|
||||
gmt grd2cpt ${data} -C${color} -R${range} -Z -D > $cptfile
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
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} -Bx${axistick[0]}g${axistick[0]}+l"${labels[0]}" -By${axistick[1]}g${axistick[1]}+l"${labels[1]}" -JX1.5i/${pic_height}i -K -P > $psfile
|
||||
else
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -Bx${axistick[0]}g${axistick[0]}+l"${labels[0]}" -By${axistick[1]}g${axistick[1]}+l"${labels[1]}" -JX1.5i/${pic_height}i -K -P > $psfile
|
||||
fi
|
||||
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -C${cptfile}+Uk -Bx${bartick} -By+l${unit} -O >> $psfile
|
||||
else
|
||||
gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -C${cptfile} -Bx${bartick} -By+l${unit} -O >> $psfile
|
||||
fi
|
||||
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
|
||||
308
gmtxy-image2.sh
Executable file
308
gmtxy-image2.sh
Executable file
@@ -0,0 +1,308 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 包含dispOption脚本
|
||||
. dispOptions.sh
|
||||
. generic_func.sh
|
||||
# 定义一个函数 执行输入的语句或者将其显示在屏幕上
|
||||
RunOrEcho()
|
||||
{
|
||||
first_str=`echo ${2// /''}`
|
||||
if [[ x${3} != x ]]; then
|
||||
sec_str=`echo ${3// /''}`
|
||||
fi
|
||||
|
||||
if [[ ${1} == 1 ]]; then
|
||||
${first_str}
|
||||
if [[ x${3} != x ]]; then
|
||||
${sec_str}
|
||||
fi
|
||||
else
|
||||
if [[ x${3} != x ]]; then
|
||||
printf "%s\n%s\n" "${first_str}" "${sec_str}"
|
||||
else
|
||||
printf "%s\n" "${first_str}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# GMT显示平面数据脚本,输入文件为网格文件,没有包含网格化语句因为网格化过程中的情况多样化,建议在其他脚本中个别添加再调用此脚本
|
||||
# 准备几个常用的排版参数组 记录的参数包括 图片的宽度 默认坐标标示设定 色标位置 色标的大小 标示字体大小
|
||||
com_layouts=("1.5i,WesNZ,0.1i/-0.2i,1.3i/0.05i+h,10.5p" \
|
||||
"1.5i,WeSnZ,1.65i/0.05i,1.3i/0.05i,10.5p" \
|
||||
"1.2i,WesNZ,0.1i/-0.1i,1.0i/0.03i+h,7.5p" \
|
||||
"1.2i,WeSnZ,1.3i/0.05i,1.0i/0.05i,7.5p")
|
||||
# 初始化参数
|
||||
data='null'
|
||||
outpsfile='null'
|
||||
gridData='null'
|
||||
unit='m'
|
||||
color='rainbow'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
labels=("x (m)" "y (m)")
|
||||
plotgrad=0
|
||||
axistick=("a" "a") #横纵坐标轴间隔 a表示自动
|
||||
bartick="a" #色标轴标轴间隔 a表示自动
|
||||
frameset="null"
|
||||
plot_colorbar=1
|
||||
annotation="null"
|
||||
keep_open=0
|
||||
from_open=">"
|
||||
image_origin=("0.5" "0.5")
|
||||
bar_origin=("0" "0")
|
||||
polyfile='null'
|
||||
lay_num=0
|
||||
run_command=1
|
||||
close_poly='-L'
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:o:L:r:u:c:l:G:t:v:f:a:p:X:x:gnKOSP" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
dispTitle "${0##*/}" "Image mapping of grid file(s) using the GMT software under the x-y plane. \
|
||||
This script accepts one or several grid (.nc or .grd) files as inputs and outputs \
|
||||
image files (.png and .eps files). The script could also output data specified shell scripts for \
|
||||
further modification. For detailed explanations of relevant arguments, please look for the GMT's manuscripts. \
|
||||
This software comes with ABSOLUTE NO WARRANTY. Use it at your own caution."
|
||||
dispAuthorInfo "Dr. Yi Zhang (yizhang-geo@zju.edu.cn). Contact me if you have questions or suggestions."
|
||||
dispUsage "${0##*/} -i<grid-data> [-o<img-file>] [-L<number>] [-r<xmin>/<xmax>/<ymin>/<ymax>] [-u<unit>] \
|
||||
[-c<cpt-file>] [-t<number>,<number>] [-v<number>] [-l<x-label>;<y-label>] [-g] [-G<grad-file>] \
|
||||
[-f<WesNZ>] [-p<poly-file>] [-n] [-a<x-coor>,<y-coor>,<annotation>] [-K] [-O] [-S] \
|
||||
[-X<x-offset>,<y-offset>] [-x<x-offset>,<y-offset>]"
|
||||
dispOptionShort "-i" "Input grid file. This is the only mandatory option that the script has. Just enter a filename \
|
||||
and you get an image."
|
||||
dispOptionShort "-o" "Output image files. Name extension is not needed. the input filename will be \
|
||||
used if this option is not set. NOTE: set this option for plotting multiple images."
|
||||
dispOptionShort "-L" "Select layout template that will be used for plotting. The script has four inbuilt templates \
|
||||
you can choose from (0 (default) - 3). Please try out to see their difference. You can also add more templates by \
|
||||
editing the script. Just make sure that you know what you are doing."
|
||||
dispOptionShort "-r" "Range of the input data. The script will detect the full range of the data automatically and \
|
||||
the use of this option will overwrite the argument."
|
||||
dispOptionShort "-u" "Data unit. The default is meter (m)."
|
||||
dispOptionShort "-c" "Filename of the color scale. The default is rainbow.cpt."
|
||||
dispOptionShort "-t" "Intervals of axis's ticks. the script will set the intervals automatically \
|
||||
if this option is not set."
|
||||
dispOptionShort "-v" "Intervals of color bar's labels. the script will set the intervals \
|
||||
automatically if this option is not set."
|
||||
dispOptionShort "-l" "Axis' labels separated by semicolons. The defaults are x (m) and y (m)."
|
||||
dispOptionShort "-g" "Plot a over layer of directional illumination. The default is false."
|
||||
dispOptionShort "-G" "Use a input grid data for applying directional illumination. \
|
||||
This should be used with the '-g' option at the same time."
|
||||
dispOptionShort "-f" "Set frames for plotting axises. The default is WesNZ for layout template 0."
|
||||
dispOptionShort "-n" "Don't plot color bar."
|
||||
dispOptionShort "-a" "Add an annotation on the map. you need to enter a string contains both \
|
||||
coordinates and text of the annotation, such as '10,10,(a)'. For more than one annotations, \
|
||||
please output a data specified script using the -S option, then edit the script accordingly."
|
||||
dispOptionShort "-p" "Take inputs from a table file and plot polygons. Each line of the file \
|
||||
represents a 2D point's coordinates."
|
||||
dispOptionShort "-P" "Keep the polygon plotted by the -p option open."
|
||||
dispOptionShort "-K" "Keep the .ps file open. This option must be set for plotting multiple images to a single output file."
|
||||
dispOptionShort "-O" "Continue from a previous .ps file. This option must be set for plotting multiple images to a single output file."
|
||||
dispOptionShort "-X" "Move the starting point for mapping the image. Use this option for plotting sub-figures."
|
||||
dispOptionShort "-x" "Move the starting point for mapping the color bar. Use this option for plotting sub-figures."
|
||||
dispOptionShort "-S" "Instead of running the script for actually plotting, print an executable shell script on screen. \
|
||||
This option is designed to help building data specified shell scripts for further modification."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
o)
|
||||
outpsfile=$OPTARG;;
|
||||
L)
|
||||
lay_num=$OPTARG;;
|
||||
u)
|
||||
unit=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
t)
|
||||
axistick=(${OPTARG//,/ });;
|
||||
X)
|
||||
image_origin=(${OPTARG//,/ });;
|
||||
x)
|
||||
bar_origin=(${OPTARG//,/ });;
|
||||
v)
|
||||
bartick=$OPTARG;;
|
||||
f)
|
||||
frameset=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
l)
|
||||
OLD_IFS="${IFS}"
|
||||
IFS=";"
|
||||
labels=(${OPTARG})
|
||||
IFS="${OLD_IFS}";;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
n)
|
||||
plot_colorbar=0;;
|
||||
G)
|
||||
gridData=$OPTARG;;
|
||||
a)
|
||||
annotation=$OPTARG;;
|
||||
p)
|
||||
polyfile=$OPTARG;;
|
||||
P)
|
||||
close_poly='';;
|
||||
K)
|
||||
keep_open=1;;
|
||||
O)
|
||||
from_open="-O >>";;
|
||||
S)
|
||||
run_command=0;;
|
||||
?)
|
||||
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
|
||||
if [[ ${outpsfile} == 'null' ]]; then
|
||||
psfile=${data%.*}.ps
|
||||
jpgfile=${data%.*}.png
|
||||
else
|
||||
psfile=${outpsfile}.ps
|
||||
jpgfile=${outpsfile}.png
|
||||
fi
|
||||
|
||||
# 获取排版
|
||||
layouts=(${com_layouts[${lay_num}]//,/ })
|
||||
# 获取坐标轴设置
|
||||
if [[ ${frameset} == 'null' ]]; then
|
||||
frameset=${layouts[1]}
|
||||
fi
|
||||
|
||||
# 获取网格范围
|
||||
if [[ $overwrite == 1 ]]; then
|
||||
range=${overwriteRange}
|
||||
else
|
||||
range=$(gmt_get_gridregion ${data})
|
||||
fi
|
||||
#根据横纵坐标的范围计算图片的长和高 我们默认图片宽度为1.5i
|
||||
range_coor=(${range//// })
|
||||
pic_height=`echo "scale=4; ${layouts[0]%i} * (${range_coor[3]} - ${range_coor[2]})/(${range_coor[1]} - ${range_coor[0]})"|bc`
|
||||
|
||||
# 输出一个bash脚本的头部到屏幕
|
||||
if [[ ${run_command} == 0 && ${from_open} == '>' ]]; then
|
||||
echo "#!/bin/bash"
|
||||
fi
|
||||
|
||||
# 设置绘图参数
|
||||
if [[ ${from_open} == '>' ]]; then
|
||||
RunOrEcho ${run_command} "gmt gmtset \
|
||||
FONT_ANNOT_PRIMARY=${layouts[4]},Times-Roman,black \
|
||||
MAP_FRAME_PEN=thinnest,black \
|
||||
MAP_GRID_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_LENGTH_PRIMARY=1p/0.5p \
|
||||
MAP_TITLE_OFFSET=7.5p \
|
||||
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||
FONT_LABEL=${layouts[4]},Times-Roman,black \
|
||||
MAP_LABEL_OFFSET=2.5p \
|
||||
MAP_ANNOT_OFFSET_PRIMARY=2.5p"
|
||||
fi
|
||||
|
||||
RunOrEcho ${run_command} "gmt gmtset MAP_FRAME_AXES=${frameset}"
|
||||
|
||||
# 处理-B选项的参数
|
||||
if [[ ${axistick[0]} == 'a' ]]; then
|
||||
axistick[0]=${axistick[0]}g
|
||||
axistick[1]=${axistick[1]}g
|
||||
else
|
||||
axistick[0]=${axistick[0]}g${axistick[0]}
|
||||
axistick[1]=${axistick[1]}g${axistick[1]}
|
||||
fi
|
||||
|
||||
RunOrEcho ${run_command} "gmt grd2cpt ${data} -C${color} -R${range} -Z -D > ${cptfile}"
|
||||
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
gradfile=${data%.*}Grad.nc
|
||||
if [[ $gridData == 'null' ]]; then
|
||||
RunOrEcho ${run_command} "gmt grdgradient ${data} -G${gradfile} -Nt -A0/45"
|
||||
else
|
||||
RunOrEcho ${run_command} "gmt grdgradient ${gridData} -G${gradfile} -Nt -A0/45"
|
||||
fi
|
||||
|
||||
if [[ ${run_command} == 0 ]]; then
|
||||
echo "gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} \
|
||||
-Bx${axistick[0]}+l\"${labels[0]}\" -By${axistick[1]}+l\"${labels[1]}\" \
|
||||
-JX${layouts[0]}/${pic_height}i -X${image_origin[0]}i -Y${image_origin[1]}i -K -P ${from_open} $psfile"
|
||||
else
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} \
|
||||
-Bx${axistick[0]}+l"${labels[0]}" -By${axistick[1]}+l"${labels[1]}" \
|
||||
-JX${layouts[0]}/${pic_height}i -X${image_origin[0]}i -Y${image_origin[1]}i -K -P ${from_open} $psfile
|
||||
fi
|
||||
else
|
||||
if [[ ${run_command} == 0 ]]; then
|
||||
echo "gmt grdimage ${data} -R${range} -C${cptfile} -Bx${axistick[0]}+l\"${labels[0]}\" \
|
||||
-By${axistick[1]}+l\"${labels[1]}\" -JX${layouts[0]}/${pic_height}i \
|
||||
-X${image_origin[0]}i -Y${image_origin[1]}i -K -P ${from_open} $psfile"
|
||||
else
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -Bx${axistick[0]}+l"${labels[0]}" \
|
||||
-By${axistick[1]}+l"${labels[1]}" -JX${layouts[0]}/${pic_height}i \
|
||||
-X${image_origin[0]}i -Y${image_origin[1]}i -K -P ${from_open} $psfile
|
||||
fi
|
||||
fi
|
||||
|
||||
# 画多边形
|
||||
if [[ $polyfile != 'null' ]]; then
|
||||
RunOrEcho ${run_command} "gmt psxy ${polyfile} -JX${layouts[0]}/${pic_height}i -W0.25p,black,- -R${range} ${close_poly} -K -O >> $psfile"
|
||||
fi
|
||||
|
||||
#添加号码
|
||||
if [[ ${annotation} != 'null' ]]; then
|
||||
if [[ ${run_command} == 0 ]]; then
|
||||
echo "gmt pstext -R${range} -JX${layouts[0]}/${pic_height}i -K -O <<- EOF >> $psfile"
|
||||
echo ${annotation}
|
||||
echo "EOF"
|
||||
else
|
||||
gmt pstext -R${range} -JX${layouts[0]}/${pic_height}i -K -O <<- EOF >> $psfile
|
||||
${annotation}
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||
#如果unit等于km则在cptfile后面添加+Uk
|
||||
if [[ ${plot_colorbar} == 1 ]]; then
|
||||
if [[ ${unit} == 'km+Uk' ]]; then
|
||||
RunOrEcho ${run_command} "gmt psscale -Dx${layouts[2]}+w${layouts[3]} -C${cptfile}+Uk -Bx${bartick} -By+l${unit} \
|
||||
-X${bar_origin[0]}i -Y${bar_origin[1]}i -O -K >> $psfile"
|
||||
else
|
||||
RunOrEcho ${run_command} "gmt psscale -Dx${layouts[2]}+w${layouts[3]} -C${cptfile} -Bx${bartick} -By+l${unit} \
|
||||
-X${bar_origin[0]}i -Y${bar_origin[1]}i -O -K >> $psfile"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${keep_open} == 0 ]]; then
|
||||
# 这一句什么都不做 唯一的作用就是关闭ps文件
|
||||
if [[ ${run_command} == 0 ]]; then
|
||||
echo "gmt pstext -R${range} -JX -O <<- EOF >> $psfile"
|
||||
echo "EOF"
|
||||
else
|
||||
gmt pstext -R${range} -JX -O <<- EOF >> $psfile
|
||||
EOF
|
||||
fi
|
||||
|
||||
# 输出 eps 和 png 文件
|
||||
RunOrEcho ${run_command} "gmt psconvert $psfile -A -TEG -E300"
|
||||
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
RunOrEcho ${run_command} "rm $cptfile $psfile gmt.history gmt.conf"
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
RunOrEcho ${run_command} "rm $gradfile"
|
||||
fi
|
||||
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
#imgcat $jpgfile
|
||||
# 打开图片文件 此命令使用MacOS终端open命令 和Linux下的xdg-open命令
|
||||
if [[ ${run_command} == 1 ]]; then
|
||||
view_file ${jpgfile}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
96
gmtxy-texture.sh
Executable file
96
gmtxy-texture.sh
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 包含dispOption脚本
|
||||
. dispOptions.sh
|
||||
#GMT绘制纹理图层,输入文件为网格文件
|
||||
# 初始化参数
|
||||
data='null'
|
||||
gradData='null'
|
||||
color='rainbow'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
plotgrad=0
|
||||
size='4i/2i'
|
||||
opFile=0
|
||||
# 从命令行获取参数
|
||||
while getopts "hi:r:c:G:s:go" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
dispTitle "${0##*/}" "simple texture images plotting 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."
|
||||
dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)"
|
||||
dispUsage "${0##*/} -i<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-c<cpt-file>] [-g] [-G<grad-data>] [-s<x-size>/<y-size>] [-o]"
|
||||
dispOptionShort "-i" "input grid file."
|
||||
dispOptionShort "-r" "data range. The template will detect the input data range automatically, the use of this option will overwrite the range."
|
||||
dispOptionShort "-c" "color cpt, The default is rainbow."
|
||||
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 "-s" "specify the size ratio of the output files, the default is 4i/2i."
|
||||
dispOptionShort "-o" "open file in finder, the default is using imgcat."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
c)
|
||||
color=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
g)
|
||||
plotgrad=1;;
|
||||
G)
|
||||
gradData=$OPTARG;;
|
||||
s)
|
||||
size=$OPTARG;;
|
||||
o)
|
||||
opFile=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 grd2cpt ${data} -C${color} -R${range} -Z -D > $cptfile
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
gradfile=${data%.*}Grad.nc
|
||||
if [[ $gradData == 'null' ]]; then
|
||||
gmt grdgradient ${data} -G${gradfile} -Nt -A0/45
|
||||
else
|
||||
gmt grdgradient ${gradData} -G${gradfile} -Nt -A0/45
|
||||
fi
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -JX${size} -P > $psfile
|
||||
else
|
||||
gmt grdimage ${data} -R${range} -C${cptfile} -JX${size} -P > $psfile
|
||||
fi
|
||||
|
||||
gmt psconvert $psfile -A -TEG -E500
|
||||
# 删除临时文件 使用linux终端rm命令
|
||||
rm $cptfile $psfile gmt.history
|
||||
if [[ $plotgrad == 1 ]]; then
|
||||
rm $gradfile
|
||||
fi
|
||||
if [[ $opFile == 1 ]]; then
|
||||
# 打开图片文件 此命令使用MacOS终端open命令
|
||||
open $jpgfile
|
||||
else
|
||||
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||
imgcat $jpgfile
|
||||
fi
|
||||
fi
|
||||
99
imgcat.sh
Executable file
99
imgcat.sh
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
|
||||
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
|
||||
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
|
||||
# only accepts ESC backslash for ST.
|
||||
function print_osc() {
|
||||
if [[ $TERM == screen* ]] ; then
|
||||
printf "\033Ptmux;\033\033]"
|
||||
else
|
||||
printf "\033]"
|
||||
fi
|
||||
}
|
||||
|
||||
# More of the tmux workaround described above.
|
||||
function print_st() {
|
||||
if [[ $TERM == screen* ]] ; then
|
||||
printf "\a\033\\"
|
||||
else
|
||||
printf "\a"
|
||||
fi
|
||||
}
|
||||
|
||||
# print_image filename inline base64contents
|
||||
# filename: Filename to convey to client
|
||||
# inline: 0 or 1
|
||||
# base64contents: Base64-encoded contents
|
||||
function print_image() {
|
||||
print_osc
|
||||
printf '1337;File='
|
||||
if [[ -n "$1" ]]; then
|
||||
printf 'name='`echo -n "$1" | base64`";"
|
||||
fi
|
||||
if $(base64 --version 2>&1 | grep GNU > /dev/null)
|
||||
then
|
||||
BASE64ARG=-d
|
||||
else
|
||||
BASE64ARG=-D
|
||||
fi
|
||||
echo -n "$3" | base64 $BASE64ARG | wc -c | awk '{printf "size=%d",$1}'
|
||||
printf ";inline=$2"
|
||||
printf ":"
|
||||
echo -n "$3"
|
||||
print_st
|
||||
printf '\n'
|
||||
}
|
||||
|
||||
function error() {
|
||||
echo "ERROR: $*" 1>&2
|
||||
}
|
||||
|
||||
function show_help() {
|
||||
echo "Usage: imgcat filename ..." 1>& 2
|
||||
echo " or: cat filename | imgcat" 1>& 2
|
||||
}
|
||||
|
||||
## Main
|
||||
|
||||
if [ -t 0 ]; then
|
||||
has_stdin=f
|
||||
else
|
||||
has_stdin=t
|
||||
fi
|
||||
|
||||
# Show help if no arguments and no stdin.
|
||||
if [ $has_stdin = f -a $# -eq 0 ]; then
|
||||
show_help
|
||||
exit
|
||||
fi
|
||||
|
||||
# Look for command line flags.
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-h|--h|--help)
|
||||
show_help
|
||||
exit
|
||||
;;
|
||||
-*)
|
||||
error "Unknown option flag: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
if [ -r "$1" ] ; then
|
||||
print_image "$1" 1 "$(base64 < "$1")"
|
||||
else
|
||||
error "imgcat: $1: No such file or directory"
|
||||
exit 2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Read and print stdin
|
||||
if [ $has_stdin = t ]; then
|
||||
print_image "" 1 "$(cat | base64)"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
28
imgchange.sh
Executable file
28
imgchange.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
data='null'
|
||||
outdata='null'
|
||||
while getopts "hi:r" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
printf "some commonly used tricks of imagemagick \n"
|
||||
printf "usage: ${0##*/} -i<image-file> [-r] \n"
|
||||
printf "%s\t%s\n" "-i" "input image file"
|
||||
printf "%s\t%s\n" "-r" "remove white background of the input image and apply a transparent background."
|
||||
exit 0;;
|
||||
i)
|
||||
data=$OPTARG;;
|
||||
|
||||
r)
|
||||
outdata=${data%.*}-nobg.png
|
||||
convert ${data} -bordercolor white -border 1x1 -matte -fill none -fuzz 20% -draw 'matte 0,0 floodfill' -shave 1x1 ${outdata};;
|
||||
?)
|
||||
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
|
||||
fi
|
||||
35
mkproj-c.sh
Executable file
35
mkproj-c.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
#创建一个cpp项目 包括三个文件夹src bin 和 doc 文件makefile main.cpp
|
||||
#获取项目名称
|
||||
proj_name=${1}
|
||||
#创建项目文件夹
|
||||
mkdir ${proj_name}
|
||||
mkdir ${proj_name}/src
|
||||
mkdir ${proj_name}/bin
|
||||
mkdir ${proj_name}/doc
|
||||
#创建文件
|
||||
cat << EOF > ${proj_name}/src/main.cpp
|
||||
#include "insert_headfile_here"
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat << EOF > ${proj_name}/makefile
|
||||
CC = g++-8
|
||||
PROM = ./bin/${proj_name}.ex
|
||||
CFLAGS = -I.
|
||||
DEPS = \$(shell find ./src -name "*.h")
|
||||
SRC = \$(shell find ./src -name "*.cpp")
|
||||
OBJ = \$(SRC:%.cpp=%.o)
|
||||
|
||||
\$(PROM): \$(OBJ)
|
||||
\$(CC) -o \$(PROM) \$(OBJ) \$(CFLAGS) -O2
|
||||
|
||||
%.o:%.cpp \$(DEPS)
|
||||
\$(CC) -c \$< -o \$@ \$(CFLAGS) -O2
|
||||
|
||||
clean:
|
||||
rm -rf \$(OBJ)
|
||||
EOF
|
||||
318
post2blog.sh
Executable file
318
post2blog.sh
Executable file
@@ -0,0 +1,318 @@
|
||||
#!/bin/bash
|
||||
#define functions for display help information
|
||||
function dispTitle(){
|
||||
winWidth=`tput cols`
|
||||
message=${2}
|
||||
|
||||
printf "%s\n%-9s" "${1}"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
function dispAuthorInfo(){
|
||||
winWidth=`tput cols`
|
||||
message=${1}
|
||||
|
||||
printf "%-9s" "Author:"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
function dispUsage(){
|
||||
winWidth=`tput cols`
|
||||
message=${1}
|
||||
|
||||
printf "%-9s" "Usage:"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
function dispOptionShort(){
|
||||
winWidth=`tput cols`
|
||||
message=${2}
|
||||
|
||||
printf "%-4s%-5s" " " "${1}"
|
||||
|
||||
head_length=19
|
||||
print_length=${head_length}
|
||||
for segment in ${message[@]}; do
|
||||
print_length=`expr ${print_length} + ${#segment} + 1`
|
||||
if [[ ${print_length} -le ${winWidth} ]]; then
|
||||
printf " %s" "${segment}"
|
||||
else
|
||||
print_length=`expr ${head_length} + ${#segment} + 1`
|
||||
printf "\n%-10s%s" " " "${segment}"
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
#change initial parameters depending on your own file system
|
||||
_my_repository_addresses=("/Users/zhangyi/Code/GitHub/YiZhangCUG.github.io" "/Users/zhangyi/Documents/GitHub/YiZhangCUG.github.io")
|
||||
_repository_address=${_my_repository_addresses[0]}
|
||||
_author="Yi Zhang"
|
||||
_posts_address="_posts/" #directory of your posts
|
||||
_assets_address="assets/" #directory of your assets
|
||||
_posts_sub_address=`date +"%Y-%m/"` #sub-directory of your posts
|
||||
_mfile='README.md' #default input filename
|
||||
_layout='post' #default post layout
|
||||
_categories='Null' #default category
|
||||
_tags='Null' #default tag
|
||||
#
|
||||
#end of self configuration. revise the left script with caution
|
||||
#
|
||||
_nowtime=`date +"%Y-%m-%d %H:%M:%S %z"` #get your current date, time and timezone
|
||||
_outfile=`date +"%Y-%m-%d-"` #initial output filename
|
||||
_title='Null'
|
||||
_outfile_end='Null'
|
||||
_savefile=0
|
||||
_link_string=""
|
||||
_no_questions=0
|
||||
_repository_id=0
|
||||
#get arguments from terminal
|
||||
while getopts "hSVi:l:T:c:t:s:r:" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
dispTitle "${0##*/}" "Post a markdown file to a personal blog hosted on the github.pages. The site is powered by the Jekyll (https://jekyllrb.com)."
|
||||
dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)"
|
||||
dispUsage "${0##*/} [-i<markdown-file>] [-l<layout>] [-T<title>] [-c<categories>] [-t<tags>] [-s<sub-directory>] [-S] [-h]"
|
||||
dispOptionShort "-i" "Input markdown file. The default is '${_mfile}'."
|
||||
dispOptionShort "-l" "Page layout defined in the Jekyll's styles. The default is '${_layout}'."
|
||||
dispOptionShort "-T" "Blog title. The default will use the h1 level title in the input markdown file. The use of this option will overwrite the default. The output filename will use the current date plus the blog title. Note that following symbols in the title will be replaced by the '-' symbol: '.',!','@','#','$','%','^','&','*','_',':'."
|
||||
dispOptionShort "-c" "Blog categories that are separated by commas. The default is/are '${_categories}'."
|
||||
dispOptionShort "-t" "Blog tags that are separated by commas. The default is/are '${_tags}'."
|
||||
dispOptionShort "-s" "Sub-directory of the posts. The main directory of the posts is placed under '${_posts_address}' folder of your github.io directory. The default is '${_posts_sub_address}'."
|
||||
dispOptionShort "-S" "Save output markdown file. The default will remove the output file after committing the blog to Github."
|
||||
dispOptionShort "-V" "Don't ask me questions."
|
||||
dispOptionShort "-r" "choose repository your want to use, The default will use the first one."
|
||||
dispOptionShort "-h" "Show help information."
|
||||
exit 0;;
|
||||
i)
|
||||
_mfile=$OPTARG;;
|
||||
l)
|
||||
_layout=$OPTARG;;
|
||||
T)
|
||||
_title=$OPTARG;;
|
||||
c)
|
||||
_categories=$OPTARG;;
|
||||
t)
|
||||
_tags=$OPTARG;;
|
||||
s)
|
||||
_posts_sub_address=$OPTARG;;
|
||||
S)
|
||||
_savefile=1;;
|
||||
V)
|
||||
_no_questions=1;;
|
||||
r)
|
||||
_repository_id=$OPTARG;;
|
||||
?)
|
||||
printf "\e[1m\e[31mError ==>\e[0m Unknow argument.\n"
|
||||
printf "Use -h option to see help information.\n"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ${_repository_id} != 0 ]]; then
|
||||
_repository_address=${_my_repository_addresses[${_repository_id}]}
|
||||
fi
|
||||
|
||||
#check if _title is set or not. If so, skip getting _title and _outfile_end from the input file
|
||||
if [[ ${_title} != 'Null' ]]; then
|
||||
#read input file and put it into a temporary file
|
||||
if [[ -f ${_mfile} ]]; then
|
||||
_tmpfile=`mktemp tmp.XXXX`
|
||||
while read _oneline
|
||||
do
|
||||
#first get all hyper links, including websites, images and files. save them to a single string separated by whitespace
|
||||
_link_string=${_link_string}`echo "${_oneline}" | grep -Eo "!?\[[^]]*\]\([^)]*\)"`" "
|
||||
echo "${_oneline}" >> ${_tmpfile}
|
||||
done < ${_mfile}
|
||||
else
|
||||
printf "\e[1m\e[31mError ==>\e[0m File not found: ${_mfile}\n"
|
||||
exit 1
|
||||
fi
|
||||
# remove special symbols from the title
|
||||
_outfile_end=${_title//[.:_!@#\$\%\^\&\*]/''}
|
||||
_outfile_end=${_outfile_end// /-}
|
||||
else
|
||||
#read input file and put it into a temporary file
|
||||
if [[ -f ${_mfile} ]]; then
|
||||
_tmpfile=`mktemp tmp.XXXX`
|
||||
while read _oneline
|
||||
do
|
||||
if [[ `echo ${_oneline} | grep "^# "` ]]; then
|
||||
_outfile_end=${_oneline:2}
|
||||
else
|
||||
#first get all hyper links, including websites, images and files. save them to a single string separated by whitespace
|
||||
_link_string=${_link_string}`echo "${_oneline}" | grep -Eo "!?\[[^]]*\]\([^)]*\)"`" "
|
||||
echo "${_oneline}" >> ${_tmpfile}
|
||||
fi
|
||||
done < ${_mfile}
|
||||
else
|
||||
printf "\e[1m\e[31mError ==>\e[0m File not found: ${_mfile}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#check if _outfile_end is found or not
|
||||
if [[ ${_outfile_end} != 'Null' ]]; then
|
||||
_title=${_outfile_end}
|
||||
# remove special symbols from the h1 title
|
||||
_outfile_end=${_outfile_end//[.:_!@#\$\%\^\&\*]/''}
|
||||
_outfile_end=${_outfile_end// /-}
|
||||
else
|
||||
printf "\e[1m\e[31mError ==>\e[0m No h1 level title found in: ${_mfile}.\n"
|
||||
printf "Please set the blog title and output file name manually.\n"
|
||||
printf "\e[1m\e[32m==>\e[0m "
|
||||
read _outfile_end
|
||||
_title=${_outfile_end}
|
||||
# remove special symbols from the input title
|
||||
_outfile_end=${_outfile_end//[.:_!@#\$\%\^\&\*]/''}
|
||||
_outfile_end=${_outfile_end// /-}
|
||||
fi
|
||||
fi
|
||||
|
||||
#combine output filename
|
||||
_outfile=${_outfile}${_outfile_end}.md
|
||||
|
||||
#echo ${_link_string}
|
||||
#get link names from _link_string and save a string
|
||||
_link_names_string=`echo ${_link_string} | grep -Eo "\[[^]]*\]"`
|
||||
#change whitespace in every link name into -
|
||||
_link_names_string=${_link_names_string//" "/"-"}
|
||||
#delete symbols \[ and \] in link names
|
||||
_link_names_string=${_link_names_string//[\[|\]]/''}
|
||||
_link_names_string=${_link_names_string//'.'/'-'}
|
||||
#convert _link_names_string to an array
|
||||
_link_names=(${_link_names_string})
|
||||
#for i in ${_link_names[@]}; do
|
||||
# echo ${i}
|
||||
#done
|
||||
|
||||
#get link addresses from _link_string and save a string
|
||||
_link_addresses_string=`echo ${_link_string} | grep -Eo "\([^)]*\)"`
|
||||
#echo ${_link_addresses_string}
|
||||
#change whitespace in every link address into -
|
||||
_link_addresses_string=${_link_addresses_string//" "/"-"}
|
||||
#delete symbols \( and \) in link names
|
||||
_link_addresses_string=${_link_addresses_string//[\(|\)]/''}
|
||||
#convert _link_addresses_string to an array
|
||||
_link_addresses=(${_link_addresses_string})
|
||||
#for i in ${_link_addresses[@]}; do
|
||||
# echo ${i}
|
||||
#done
|
||||
|
||||
#exclude http[s] links to get _copy_names and _copy_addresses
|
||||
#we use year-month to sort files by month
|
||||
unset _copy_names
|
||||
unset _copy_addresses
|
||||
for (( i = 0; i < ${#_link_names[@]}; i++ )); do
|
||||
if [[ ! `echo ${_link_addresses[i]} | grep -E "https?://"` ]]; then
|
||||
_copy_names+=(`date +"%Y-%m/"`"${_link_names[i]}.${_link_addresses[i]##*.}")
|
||||
_copy_addresses+=("${_link_addresses[i]}")
|
||||
fi
|
||||
done
|
||||
|
||||
#read temporary file and change file link address, then input it into another temporary file
|
||||
_tmpfile2=`mktemp tmp.XXXX`
|
||||
while read _oneline
|
||||
do
|
||||
#check every line for saved file links and replace theme with _copy_names
|
||||
for (( i = 0; i < ${#_copy_addresses[@]}; i++ )); do
|
||||
_oneline=${_oneline//${_copy_addresses[i]}/"/${_assets_address}${_copy_names[i]}"}
|
||||
done
|
||||
echo "${_oneline}" >> ${_tmpfile2}
|
||||
done < ${_tmpfile}
|
||||
rm ${_tmpfile}
|
||||
|
||||
#combine head information and temporary file into the output, then remove the temporary one
|
||||
echo "---" > ${_outfile}
|
||||
echo "layout: ${_layout}" >> ${_outfile}
|
||||
echo "title: \"${_title}\"" >> ${_outfile}
|
||||
echo "date: ${_nowtime}" >> ${_outfile}
|
||||
echo "author: ${_author}" >> ${_outfile}
|
||||
echo "category: ${_categories}" >> ${_outfile}
|
||||
echo "tags: [${_tags}]" >> ${_outfile}
|
||||
echo "---" >> ${_outfile}
|
||||
echo "" >> ${_outfile}
|
||||
echo "* content" >> ${_outfile}
|
||||
echo "{:toc}" >> ${_outfile}
|
||||
echo "" >> ${_outfile}
|
||||
echo "" >> ${_outfile}
|
||||
cat ${_tmpfile2} >> ${_outfile}
|
||||
rm ${_tmpfile2}
|
||||
|
||||
if [[ ${_no_questions} == 0 ]]; then
|
||||
printf "Output file generated. Please check it. Is every thing ok? (y/n) "
|
||||
read _check_result
|
||||
else
|
||||
_check_result='y'
|
||||
fi
|
||||
|
||||
if [[ ${_check_result} == 'y' ]]; then
|
||||
#copy files to github.io directory. Check directory exists or not
|
||||
#"${_repository_address}/${_assets_address}`date +"%Y-%m"`"
|
||||
if [[ ! -d "${_repository_address}/${_assets_address}`date +"%Y-%m"`" ]]; then
|
||||
mkdir ${_repository_address}/${_assets_address}`date +"%Y-%m"`
|
||||
fi
|
||||
|
||||
if [[ ! -d "${_repository_address}/${_posts_address}${_posts_sub_address}" ]]; then
|
||||
mkdir ${_repository_address}/${_posts_address}${_posts_sub_address}
|
||||
fi
|
||||
|
||||
for (( i = 0; i < ${#_copy_addresses[@]}; i++ )); do
|
||||
cp ${_copy_addresses[i]} ${_repository_address}/${_assets_address}${_copy_names[i]}
|
||||
done
|
||||
|
||||
#pull your git repository
|
||||
git --git-dir=${_repository_address}/.git --work-tree=${_repository_address} pull
|
||||
#copy output markdown file to posts directory
|
||||
cp ${_outfile} ${_repository_address}/${_posts_address}${_posts_sub_address}
|
||||
#add file to git
|
||||
git --git-dir=${_repository_address}/.git --work-tree=${_repository_address} add ${_posts_address}${_posts_sub_address}${_outfile}
|
||||
for (( i = 0; i < ${#_copy_names[@]}; i++ )); do
|
||||
git --git-dir=${_repository_address}/.git --work-tree=${_repository_address} add ${_assets_address}${_copy_names[i]}
|
||||
done
|
||||
#commit changes
|
||||
git --git-dir=${_repository_address}/.git --work-tree=${_repository_address} commit -m "post blog ${_outfile}"
|
||||
#push to remote
|
||||
git --git-dir=${_repository_address}/.git --work-tree=${_repository_address} push
|
||||
fi
|
||||
|
||||
#check if the output file should be saved
|
||||
if [[ ${_savefile} == 0 ]]; then
|
||||
rm ${_outfile}
|
||||
fi
|
||||
89
showxyz.sh
Executable file
89
showxyz.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||
. gmt_shell_functions.sh
|
||||
# 本脚本的功能为显示一个规则网的三列数据
|
||||
# 我们会用到之前编写的另几个脚本来生成结果图片 这里专门提供了一个参数来传递参数到调用的相应脚本中
|
||||
|
||||
data='null'
|
||||
range='null'
|
||||
overwriteRange='null'
|
||||
overwrite=0
|
||||
interval='null'
|
||||
cols='0,1,2'
|
||||
script='null'
|
||||
outname='null'
|
||||
geoframe=0
|
||||
nogridfile=0
|
||||
while getopts "ht:o:r:i:c:s:gn" arg
|
||||
do
|
||||
case $arg in
|
||||
h)
|
||||
printf "plot xyz like data \nAuthor: Yi Zhang (zhangyi.cugwuhan@gmail.com)\n"
|
||||
printf "usage: ${0##*/} -t<table-file> -i<interval>/<interval> [-o<outfile-name>] [-r<w>/<e>/<s>/<n>] [-c<col0>,<col1>,<col2>...] [-s<scripts>] [-g] [-n] \n"
|
||||
printf "%s\t%s\n" "-t" "input table file."
|
||||
printf "%s\t%s\n" "-o" "output file name, the input table name will be used if this option is absent."
|
||||
printf "%s\t%s\n" "-i" "data intervals in x and y directions."
|
||||
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" "-c" "select data columns will be used for plotting, the default is 0,1,2."
|
||||
printf "%s\t%s\n" "-s" "additional commands that will be pasted down to plotting scripts."
|
||||
printf "%s\t%s\n" "-g" "the default poltting script used here is \"gmtxy-image\", set -g option to use \"gmtsph-regional\"."
|
||||
printf "%s\t%s\n" "-n" "do not save .nc file, the default will save a output .nc grid file."
|
||||
exit 0;;
|
||||
t)
|
||||
data=$OPTARG;;
|
||||
o)
|
||||
outname=$OPTARG;;
|
||||
i)
|
||||
interval=$OPTARG;;
|
||||
r)
|
||||
overwrite=1
|
||||
overwriteRange=$OPTARG;;
|
||||
c)
|
||||
cols=$OPTARG;;
|
||||
s)
|
||||
script=$OPTARG;;
|
||||
g)
|
||||
geoframe=1;;
|
||||
n)
|
||||
nogridfile=1;;
|
||||
?)
|
||||
printf "error: unknow argument\nuse -h option to see help information\n"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $data == 'null' || $interval == 'null' ]]; then
|
||||
printf "error: no input file name or no -i option setted\nuse -h option to see help information\n"
|
||||
exit 1
|
||||
else
|
||||
if [[ $outname == 'null' ]]; then
|
||||
ncfile=${data%.*}.nc
|
||||
else
|
||||
ncfile=${outname}
|
||||
fi
|
||||
# 获取网格范围
|
||||
if [[ $overwrite == 1 ]]; then
|
||||
range=${overwriteRange}
|
||||
else
|
||||
range=$(gmt_get_region ${data})
|
||||
fi
|
||||
|
||||
xyz2grd ${data} -G${ncfile} -R${range} -I${interval} -i${cols}
|
||||
if [[ $geoframe == 1 ]]; then
|
||||
if [[ $script == 'null' ]]; then
|
||||
gmtsph-regional -i ${ncfile}
|
||||
else
|
||||
gmtsph-regional -i ${ncfile} ${script}
|
||||
fi
|
||||
else
|
||||
if [[ $script == 'null' ]]; then
|
||||
gmtxy-image -i ${ncfile}
|
||||
else
|
||||
gmtxy-image -i ${ncfile} ${script}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $nogridfile == 1 ]]; then
|
||||
rm ${ncfile}
|
||||
fi
|
||||
fi
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/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
108
sph_regional.sh
@@ -1,108 +0,0 @@
|
||||
#!/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
|
||||
23
stow-config.sh
Executable file
23
stow-config.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
package=gmttemplates
|
||||
stow_address=/opt/stow
|
||||
tar_address=/usr/local
|
||||
|
||||
# Prepare the working directory
|
||||
if [[ ! -d ${stow_address}/${package}/sbin ]]; then
|
||||
sudo mkdir ${stow_address}/${package}
|
||||
sudo mkdir ${stow_address}/${package}/sbin
|
||||
fi
|
||||
|
||||
#找到所有后缀名为.py的脚本名称 存入数组
|
||||
scriptName=( `ls *.sh` )
|
||||
for element in ${scriptName[@]}; do
|
||||
#排除configure.sh
|
||||
if [[ $element != "configure.sh" && $element != "stow-config.sh" ]]; then
|
||||
sudo cp ${element} ${stow_address}/${package}/sbin
|
||||
fi
|
||||
done
|
||||
|
||||
# 使用stow创建链接
|
||||
sudo stow -d ${stow_address} -t ${tar_address} -S ${package}
|
||||
92
xy_grid.sh
92
xy_grid.sh
@@ -1,92 +0,0 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user