Several Important Commands in GMT

pscoast - To plot grayshaded, colored, or textured land-masses, water-masses, coastlines, borders, and rivers.
(http://gmt.soest.hawaii.edu/gmt/doc/html/pscoast.html)
psxy - To read (x,y) pairs from files [or standard input] and generates PostScript code that will plot lines, polygons, or symbols at those locations on a map.
(http://gmt.soest.hawaii.edu/gmt/doc/html/psxy.html)
pstext - To plot textstrings of variable size, font type, and orientation.
(http://gmt.soest.hawaii.edu/gmt/doc/html/pstext.html)
grdimage - To read a 2-D gridded file and produces a gray-shaded (or colored) map by assigning each contour interval a gray-shade (or color).
(http://gmt.soest.hawaii.edu/gmt/doc/html/grdimage.html)
xyz2grd - Converting an ASCII or binary table to grd file format.
(http://gmt.soest.hawaii.edu/gmt/doc/html/xyz2grd.html)

Two useful options in GMT commands

The -K -O options control the generation of PostScript code for multiple overlay plots. Most of the unexpected plot results can be traced to the incorrect use of these two options. -K needs be used in every command to create the output file except the last command. However -O needs to be used in all commands except first command. The detail can be seen in the following webpage:
(http://gmt.soest.hawaii.edu/gmt/doc/html/tutorial/node29.html)

Example for CPT files

# cpt file created by: makecpt -T0/6/1 -Crainbow
#COLOR_MODEL = RGB
-8    8    51    113    -6    38    1    183
-6    38    1    183    -4    12    120    238
-4    12    120    238    -2    50    238    235
-2    50    238    235    0    180    238    135
0    180    238    135    2    238    199    100
2    238    199    100    4    134    97    42
B    134    97    42
F    8    51    113
N    255    255    255

______________________________________________________________________


Plot Example 1

#!/bin/csh -v

# observed file has: decimal_year year month obs_data
# RIO GRANDE AT COSTILLA_CK

set SIMFL = ../../rout_out/COSTILLA_CK/COSTI.month
set OBSFL = ../../obs_flows/COSTI_obs_mon
set LOCSTR = COSTILLA_CK

set PROJ = -JX7/4
set COORD = -R1965/1969/0/
set MAX = 165
set OUTF = $LOCSTR.ps

# -- plot --------------------------------------------------

awk '{if ($1>=1965 && $1<1970)printf("%.3f %.3f\n", $1, $4)}' $OBSFL | \psxy -P -K -B1/80:.:SWne $COORD$MAX $PROJ -W3 -Y5 >! $OUTF

awk '{if ($1>=1965 && $1<1970) printf("%.3f %.3f\n", $1+$2/12, $3)}' $SIMFL | psxy -O -K $COORD$MAX $PROJ -W1/255/0/0:td >> $OUTF

pstext -N -O -K $COORD$MAX $PROJ << END >> $OUTF
1965.8 150 12 0 5 5 $LOCSTR monthly mean flow (cfs)
END


# plot legend -----------------------------------------------------

pstext -R0/1/0/1 $PROJ -N -K -O -Y-1.5 << END >> $OUTF
0.2 0.20 12 0 5 6 simulated
0.6 0.20 12 0 5 6 observed
END
psxy -O -K -N -R0/1/0/1 $PROJ -W1/255/0/0:td << END >> $OUTF
0.3 0.20
0.4 0.20
END
psxy -O -N -R0/1/0/1 $PROJ -W3 << END >> $OUTF
0.7 0.20
0.8 0.20
END

gs $OUTF
_______________________________________________________________________

* The key command is "psxy", which can be used to plot line connecting all the data point .

_______________________________________________________________________


Plot Example 2


#!/bin/csh

set INF = sm_lonlat
set SOILF = junk
set COORD = -R-122/-118.1/44.75/46
set OUTF = domain.ps
set PROJ = -Jm2.4

pscoast $PROJ $COORD -B1f.125/1f.125 -Di \
-K -X0.5 -Y3.0 -N1 -N2 >! $OUTF

awk '{print $1, $2,"10 315 4 5",NR}' $SOILF | pstext $PROJ $COORD -O -K >> $OUTF

gs $OUTF

exit
________________________________________________________________________

* This plot can be used to choose the grid cells in the domain you want. The key command is "pstext". The input file is the lon, lat file of the domain. By plotting the NR ( number of row ) of each lon & lat on the grid cell location, you can choose all the lon & lat in the domain you want.

_________________________________________________________________________


Plot Example 3


#!/bin/csh

# set fonts
gmtset ANOT_FONT_SIZE 12 LABEL_FONT_SIZE 12 HEADER_FONT_SIZE 16
set outfil=mon_tempe_pcm_vic.ps
set coord=-126/-67/25/52
set coord2 = 0.5/12.5/0
set size=6
set blue=200/200/255
set pixsize=0.1
set proj = -JX9/6.5d
set proj2 = -JX.7/.54
set llfile = lonlat_temp1

set XX = ( 0.75 1.8 2.15 -3.1 1.2 1.5 1.7 2.3 -7.65 1.8 2.15 1.85 1.6 -7.4 1.8 1.8 1.8 1.5 -7.0 1.2 1.8 1.0 1.8 -5.0 1.8 2.2 1.8 -5.05 1.7 1.3 1.6 -3.2 1.6 1.8)
set YY = ( 5.5 0 0 -0.7 0 0 0 0 -0.7 0 0 0 0 -0.7 0 0 0 0 -0.68 0 0 0 0 -0.65 0 0 0 -0.7 0 0 0 -0.67 0 -0.60)
set YMX = (150 150 150 150 150 150 100 150 150 200 150 150 150 150 150 200 150 150 150 100 270 185 150 90 250 150 150 100 200 150 155 255 200 265)
set OBSFL = ( 34vic_aver_Tair2 )

set SIMFL = ( 34pcm_aver_TREFHT )
set common = /nfs/sphere/raid/aww/acpi/data/cl_mod/pcm/images/location/

pscoast $proj -R$coord -B4f1/2f1 -Di -N1/5/255/200/80 -N2/1/250/230/230 -S$blue -K -V -C$blue >! $outfil
pstext $proj -R$coord -V -O -K -N <<END>> $outfil
-97 54 16 0 5 6 Monthly average temperature: PCM B0622 vs VIC-Observed (1950-1999)
END
psxy $llfile $proj -R$coord -O -K -Ss0.15 -N -G200/200/0 >> $outfil


# ----------- loop through cell dist plots ------------------------
gmtset ANOT_FONT_SIZE 6 LABEL_FONT_SIZE 8 TICK_LENGTH 0.01i
gmtset ANOT_OFFSET 0.015i FRAME_WIDTH 0.025i

set II = 0
while ( $II < 33 ) # leave room for lt averages
@ II ++

set coordvar = 0.5/12.5/250/305

awk '{print $1,$('$II'+1)}' $OBSFL | \
psxy -O -K -X$XX[$II] -Y$YY[$II] -R$coordvar $proj2 -W2/0/180/0 -B3/25WeSn >> $outfil

awk '{print $1,$('$II'+1)}' $SIMFL | \
psxy -O -K -R$coordvar $proj2 -W2/0/0/200 -V >> $outfil

end # --------- end loop through cells -------------------

awk '{print $1,$2}' $llfile | \
psxy -O -K -X1.0 -Y-0.6 -R0/1/0/1 -JX2.2/0.75 -G255 -L -W2/100/100/100 -V >> $outfil
pstext -X-6.85 -Y-1.45 $proj -R0/1/0/1 -V -O <<END>> $outfil
0.885 .32 12 0 5 6 Green\=Observed; Blue\=PCM
0.89 .285 12 0 5 6 X axis: month (Jan.- Dec.)
0.89 .25 12 0 5 6 Y axis: Temperature in Kelvin
END


gs $outfil

exit
_______________________________________________________________________

* The key point is setting loop and set the locations of each small plot by using XX, YY as in the script. The input file is in the format of mon, temperature in location 1, temperature in location 2,······, temperature in location 34.

_______________________________________________________________________


Plot Example 4


#!/bin/csh

# program to plot a column file in 2D, color
# uses awk, gmt and other unix commands, so run on a machine that can access these

# set fonts
gmtset ANOT_FONT_SIZE 10 LABEL_FONT_SIZE 10 HEADER_FONT_SIZE 16
set outfil = aver_FSNS_assaw.ps
set COORD = -126.052/-67/25/52.905
set SIZE = 2.812/2.7905
set proj = JX2.4/1.8d

set SH = 2.5
set BSH = -5
set YY = -1.85

set BARa = 0/2400/400
set BARad = -1000/1000/400
set BARs = 0/1000/200
set BARsd = -500/700/200

set COMMON = /nfs/sphere/usr1/chunmei/from_norway/agu/common/cpt_file
set CPTa = $COMMON/str_weak_5_80-230.cpt
set CPTad = $COMMON/str-weak_5_-10-90.cpt
set CPTs = $COMMON/str-weak_5_0-350.cpt
set CPTsd = $COMMON/str_weak_6_-50-130.cpt

set TITLE = ("PCM B0622" "Observed" "PCM - VIC")
set season = ("MAM" "JJA" "SON" "DJF")

set PCMFL = (ann_pcm_SWnet.50-99\
      spr_pcm_SWnet.50-99\
       sum_pcm_SWnet.50-99\
       fall_pcm_SWnet.50-99\
      win_pcm_SWnet.50-99)

set OBSFL = (ann_vic_SWnet.50-99\
      spr_vic_SWnet.50-99\
      sum_vic_SWnet.50-99\
      fall_vic_SWnet.50-99\
      win_vic_SWnet.50-99)

set NCDF = (ann_pcm_SWnet.50-99:r.ncdf )

set II = 0
while ( $II < 5 ) # leave room for lt averages
@ II ++

set NCDFP$II = $PCMFL[$II]:r.ncdf
set NCDFO$II = $OBSFL[$II]:r.ncdf

awk '{print $1, $2, $3}' $PCMFL[$II] | xyz2grd -GNCDFP$II -F -I$SIZE -R$COORD
awk '{print $1, $2, $3}' $OBSFL[$II] | xyz2grd -GNCDFO$II -F -I$SIZE -R$COORD
grdmath NCDFP$II NCDFO$II SUB = diff$II.ncdf

end

grdimage NCDFP1 -R$COORD -Bwsne -$proj -Y9.0 -X0.5 -K -P -C$CPTa <! $outfil
pscoast -R$COORD -$proj -O -V -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage NCDFO1 -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTa >> $outfil
pscoast -R$COORD -$proj -O -V -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage diff1.ncdf -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTad >> $outfil
pscoast -R$COORD -$proj -O -V -K -N1 -N2 -W1 -A10000 >> $outfil

# add legend
psscale -C$CPTa -X-4.5 -Y-0.6 -E -D2.0/0.5/4.0/0.1h -B:"Average FSNS (W/m^2)": -O -K >> $outfil
psscale -C$CPTad -X3.7 -Y0.5 -E -D2.0/0/2.0/0.1h -B:"Difference (W/m^2)": -O -K >> $outfil


grdimage NCDFP2 -R$COORD -$proj -Bwsne -Y-2.5 -X-4.2 -O -K -C$CPTs >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage NCDFO2 -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTs >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage diff2.ncdf -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTsd >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil


set II = 2
while ( $II < 5 ) # leave room for lt averages
@ II ++

grdimage NCDFP$II -R$COORD -$proj -Bwsne -Y$YY -X$BSH -O -K -C$CPTs >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage NCDFO$II -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTs >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil

grdimage diff$II.ncdf -R$COORD -Bwsne -$proj -X$SH -O -K -C$CPTsd >> $outfil
pscoast -R$COORD -$proj -O -K -N1 -N2 -W1 -A10000 >> $outfil

end

# add legend
psscale -C$CPTs -X-4.5 -Y-0.6 -E -D2.0/0.5/4.0/0.1h -B:"Average FSNS (W/m^2)": -O -K >> $outfil
psscale -C$CPTsd -X3.7 -Y0.5 -E -D2.0/0/2.0/0.1h -B:"Difference (W/m^2)": -O >> $outfil

\rm *.ncdf

gs $outfil
_______________________________________________________________________