A cure to all these woes is the isolation mode introduced in GMT version 4.2.2. This mode allows you to run a GMT script without leaving any traces other than the resulting PostScript or data files, and not altering the .gmtdefaults4 or .gmtcommands4 files. Those files will be placed in a temporary directory instead. And if properly set up, this temporary directory will only be used by a single script, even if another GMT script is running simultaneously. This also provides the opportunity to create any other temporary files that the script might create in the same directory.
The example below shows how isolation mode works.
#!/bin/sh # GMT Appendix P, example 1 # # Purpose: Illustrates the use of isolation mode # GMT progs: gmtset, grdimage, grdmath, makecpt, pscoast # Unix progs: mktemp, rm # ps=GMT_App_P_1.ps # Create a temporary directory. $GMT_TMPDIR will be set to its pathname. # XXXXXX is replaced by a unique random combination of characters. export GMT_TMPDIR=`mktemp -d /tmp/gmt.XXXXXX` # These settings will be local to this script only since it writes to # $GMT_TMPDIR/.gmtdefaults4 gmtset COLOR_MODEL rgb ANNOT_FONT_SIZE_PRIMARY 14p # Make grid file and color map in temporary directory grdmath -Rd -I1 Y = $GMT_TMPDIR/lat.nc makecpt -Crainbow -T-90/90/60 -Z > $GMT_TMPDIR/lat.cpt # The grdimage command creates the history file $GMT_TMPDIR/.gmtcommands4 grdimage $GMT_TMPDIR/lat.nc -Sl -JK6.5i -C$GMT_TMPDIR/lat.cpt -P -K > $ps pscoast -R -J -O -Dc -A5000 -Gwhite -B60g30/30g30 >> $ps # Clean up all temporary files and the temporary directory rm -rf $GMT_TMPDIR
The files .gmtdefaults4 and .gmtcommands4 are automatically created in the temporary directory $GMT_TMPDIR. The script is also adjusted such that the temporary grid file lat.nc and colormap lat.cpt are created in that directory as well. To make things even more easy, GMT now provides a set of handy shell functions in gmt_shell_functions.sh: simply include that file in the script and the creation and the removal of the temporary directory is reduced to a single command.
#!/bin/sh # GMT Appendix P, example 2 # # Purpose: Illustrates the use of isolation mode # GMT progs: gmtset, grdimage, grdmath, makecpt, pscoast # GMT funcs: gmt_init_tmpdir, gmt_remove_tmpdir # ps=GMT_App_P_2.ps # Make GMT shell functions accessible the the script . gmt_shell_functions.sh # Create a temporary directory. $GMT_TMPDIR will be set to its pathname. gmt_init_tmpdir # These settings will be local to this script only since it writes to # $GMT_TMPDIR/.gmtdefaults4 gmtset ANNOT_FONT_SIZE_PRIMARY 14p # Make grid file and color map in temporary directory grdmath -Rd -I1 Y = $GMT_TMPDIR/lat.nc makecpt -Crainbow -T-90/90/60 -Z > $GMT_TMPDIR/lat.cpt # The grdimage command creates the history file $GMT_TMPDIR/.gmtcommands4 grdimage $GMT_TMPDIR/lat.nc -Sl -JK6.5i -C$GMT_TMPDIR/lat.cpt -P -K > $ps pscoast -R -J -O -Dc -A5000 -Gwhite -B60g30/30g30 >> $ps # Clean up all temporary files and the temporary directory gmt_remove_tmpdir