My boiler GMT script


I keep a blank c-shell script that contains comments about conversion of files and an outline of how my script is going to read. You can download my GMT5 boiler script by clicking here. You can download my GMT4 boiler script by clicking here. Both of my script assumes that you have added GMT to you csh path.  A shorter version of my boiler script is shown below so that I give in depth details about each command:


#!/bin/csh

gmt gmtset FORMAT_GEO_MAP DD

gmt gmtset MAP_FRAME_TYPE plain

gmt gmtset FONT_TITLE 24p

gmt gmtset MAP_TITLE_OFFSET -0.4

gmt gmtset FONT_LABEL 16p

gmt gmtset MAP_LABEL_OFFSET 0.3c

gmt gmtset FONT_ANNOT_PRIMARY 12p

set region =

set projection =

set open = "-K -V"

set add = "-O -K -V"

set close = "-O -V"

set psFile =

set pdfFile =

#gmt ps2raster $psFile -A -P -V -Tj -E300

ps2pdf $psFile $pdfFile

open -a Preview $pdfFile

echo "end of file”


First of all in order to understand the script you have to understand a little bit about csh. All c-shell files must start with the the #!/path_to_csh. I use c-shell variables so that it improves the readability of my scripts. In order to set a c-shell variable you use the command set. To recall a variable anywhere within the c-shell it is indicated with a dollar sign ($). The commands above are usually common and required for most GMT commands. The region variable represents the -R flag s and the projection command represents the -J flag. These flags are usually required for most commands.


Description of commands


gmtset FORMAT_GEO_MAP DD

This command sets the labels on the map to decimal degrees (DD)


gmtset MAP_FRAME_TYPE plain

This command makes the outline of the map a single line marked with tick marks.


gmtset FONT_TITLE 24p

This command sets the size of the tile font.


gmtset MAP_TITLE_OFFSET -0.4c

This command moves the map title offset down by 0.4 centimeters.


gmtset FONT_LABEL 16p 

This command sets the size of the label fonts.


gmtset MAP_LABEL_OFFSET 0.3c

This command moves the offset of of the label fonts up by 0.3 centimeters.


gmtset FONT_ANNOT_PRIMARY 12p

This command sets the size of the primary annotation font to 12 point.


set region =

I use this command to set the -R flag. For example if I were generating a mercator map I would set this value as: “-R-105/-104/40/41”. Where -105 is the longitude of the left, -104 is the longitude of the right, 40 is the latitude of the bottom and 41 is the latitude of the top of the map. I put the flag in quotations so that the c-shell variable is a string variable.


set projection =

I use this command to set the -J flag. For example to set the map above I would set this value as: “-JM6i”. This would indicate a mercador projection with the longest axis being 6 inches. I put the flag in quotations so that the c-shell variable is a string variable.


set open = “-K -V”

Since GMT stacks the commands into a postScript file it has flags to let it know if it is opening the file, adding to the file or closing the file. I use this command on the first command that is writing ( >! ) to the postScript file. The -V represent verbose. So anytime this variable is added to a command it will write out the progress to the terminal.


set add = “ -O -K -V”

I use this variable whenever I am writing ( >>) another object to my map. Once again it has the -V flag so that output from the command is printed to the terminal.


set close “-O -V”

I use this variable whenever I am writing ( >> ) the last object on my map. This command is important if you want to convert the postScript file to a jpeg. If the postScript file is not close properly then the ps2raster command will not be able to convert your postScript file to another format.


set psFile = 

This is the varible that represents the output file name. For example: “outFile.ps”.


set pdfFile =

This is the same name as the psFile variable but ending in pdf. For example: “outFile.pdf”. If you do not have ps2pdf installed then this variable will be of no use to you. I like to convert all of my postScript images to pdf’s because they open quicker in Preview.


#gmt ps2raster $psFile -A -P -V -Tj -E300

This command is commented out because it will not work properly unless the postScript file is properly close. So after my last command, i.e. contains the $close variable, I uncomment this line. This command will take the postscript file and convert it to a jpeg file with a resolution of 300 dpi.


ps2pdf $psFile $pdfFile

This is not a GMT command but you can install it via Fink. This command converts the postScript file to a pdf file.


open -a Preview  $pdfFile

This command (assuming your on a mac) will open the converted pdf in Preview as soon as the script is done running.


echo “end of file”

This just prints out the message to the terminal letting the user know the script has finished successfully.


© Brady Flinchum 2016