add three scripts
add imgcat imgchange and showxyz
This commit is contained in:
parent
f49bf4e26f
commit
fcfd49e1b5
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
|
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
|
Loading…
Reference in New Issue
Block a user