#!/bin/bash
file=Map.ps
grdfile=../DATA/newbathy.grd
#grdfile=../DATA/Bathymetry_GEBCO_30s_world.grd
# Norway map
xmin=0
xmax=33
ymin=54
ymax=73
midlon=`gmt gmtmath -Q $xmin $xmax ADD 2 DIV =`
midlat=`gmt gmtmath -Q $ymin $ymax ADD 2 DIV =`
R="-R$xmin/$xmax/$ymin/$ymax"
J="-JM$midlon/$midlat/16c"

#Make a 1-degree grid
#B="-B1a1f1g1"

# Make a 5-degree grid
B="-B5g5"

gmt grdcut $grdfile $R -Gtmpf.grd
gmt grdinfo tmpf.grd
gmt makecpt -Cglobe -T-8500/8500/50 -Z > cptfile2.cpt

#Create map with top title
gmt psbasemap $B -B+t"Norway" $J $R -K -P > $file
gmt grdgradient tmpf.grd -Nt1 -A225 -Gtmpgrd.grd
gmt grdimage $J $R tmpf.grd -Itmpgrd.grd -O -K -Ccptfile2.cpt >> $file
gmt pscoast $J -B $R -Dh -N1/1.00p,- -K -O -W >> $file

# Draw fault-line
gmt psxy SRN.txt -R -JM -W2,black -O -K >> $file

# Add text on a longitude/latitude on map
gmt pstext -R -J -N -K -O -V -F+f25,1,blue+j << EOF >> $file
8.0 65.6 BR Fault line
EOF

# Draw seismic events
gmt psxy -R -J -O gmtxyz.K2 -Wfaint -i0,1,2,3s0.1 -h3 -Scc -Cquakes.cpt >> $file

# Draw depth-scale
gmt psscale -Cdepth.cpt -B+l"Depth" -Dx2.5/-1.5c+w4.5i/0.2i+h -By+lkm -K -P >> $file 

# Draw focal mec.
gmt psmeca psmeca.out -R -J -V -Sa1.5/-1  -P -O >> $file 

outeps=`echo $file | sed 's/ps/eps/g'`
eps2eps $file $outeps
gmt psconvert $outeps -Tj -P
gv $file
