/usr/bin/gmt_shell_functions.sh is in gmt 5.2.1+dfsg-3build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/bin/bash
# $Id: gmt_shell_functions.sh 15178 2015-11-06 10:45:03Z fwobbe $
#
# 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 avaiable
# on the command line as well. See documentation for usage.
#
#----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
}
# Return integer total number of lines in the file(s)
gmt_get_nrecords() {
cat $* | wc -l | awk '{print $1}'
}
# Same with backwards compatible name...
gmt_nrecords() {
cat $* | wc -l | awk '{print $1}'
}
# Return integer total number of data records in the file(s)
gmt_get_ndatarecords() {
cat $* | egrep -v '^>|^#' | wc -l | awk '{print $1}'
}
# 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 -C $* | cut -d' ' -f2-5`
}
# 4 obsolete but 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
}
# ame with backwards compatible name...
gmt_map_height() {
gmt mapproject $* -Wh
}
# 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))
}
|