gmtset LABEL_FONT_SIZE 12 ANOT_FONT_SIZE 12 CHAR_ENCODING Standard+ \
       PAPER_MEDIA Letter+ ELLIPSOID WGS-84 LABEL_FONT Helvetica

dirvel=/usr1/chuck/GPS_Vels/Kronos_daily/ITRF05_1yr/
plbdy_dir=/mnt/gps_data/Geophysical_Data/Coasts/
dir=/mnt/gps_data/Geophysical_Data/Topo_V8.2

az1=0 ; az2=90
# shading=NA_col.cpt
shading=col.cpt
arr_scale=0.3

# Create site labels
   gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels

for state in AK AL AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY na cg ca jf nz sa sr sc sw az nb ar eu sm lw wa ea cp in au su yz am ok be ps cr mq np sp
   do
     case $state in
       AK )
         label='Alaska' ;
         arr_scale=0.05 ;
         nlat=71.5 ; slat=51 ;
         wlon=172 ; elon=230 ;;
       AL )
         label='Alabama' ;
         arr_scale=0.3 ;
         nlat=35.5 ; slat=30 ;
         wlon=271 ; elon=276 ;;
       AZ )
         label='Arizona' ;
         arr_scale=0.3 ;
         nlat=37.5 ; slat=31 ;
         wlon=245 ; elon=251.5 ;;
       AR )
         label='Arkansas' ;
         arr_scale=0.3 ;
         nlat=37 ; slat=32.5 ;
         wlon=265 ; elon=271 ;;
       CA )
         label='California' ;
         arr_scale=0.05 ;
         nlat=42.5 ; slat=32 ;
         wlon=235 ; elon=247 ;;
       CO )
         label='Colorado' ;
         arr_scale=0.3 ;
         nlat=41.5 ; slat=36.5 ;
         wlon=250 ; elon=259 ;;
       CT )
         label='Connecticut' ;
         arr_scale=0.3 ;
         nlat=42.3 ; slat=40.7 ;
         wlon=286 ; elon=288.5 ;;
       DE )
         label='Delaware' ;
         arr_scale=0.3 ;
         nlat=40 ; slat=38 ;
         wlon=284 ; elon=285 ;;
       FL )
         label='Florida' ;
         arr_scale=0.3 ;
         nlat=32 ; slat=23 ;
         wlon=272 ; elon=283 ;;
       GA )
         label='Georgia' ;
         arr_scale=0.3 ;
         nlat=35.5 ; slat=30 ;
         wlon=274 ; elon=280 ;;
       HI )
         label='Hawaii' ;
         arr_scale=0.025 ;
         nlat=28.5 ; slat=18 ;
         wlon=182 ; elon=206 ;;
       ID )
         label='Idaho' ;
         arr_scale=0.3 ;
         nlat=49.2 ; slat=41.8 ;
         wlon=241.5 ; elon=249.5 ;;
       IL )
         label='Illinois' ;
         arr_scale=0.3 ;
         nlat=42.7 ; slat=36.8 ;
         wlon=268 ; elon=273 ;;
       IN )
         label='Indiana' ;
         arr_scale=0.3 ;
         nlat=42 ; slat=37.5 ;
         wlon=271.5 ; elon=275.5 ;;
       IA )
         label='Iowa' ;
         arr_scale=0.3 ;
         nlat=43.7 ; slat=40.3 ;
         wlon=263 ; elon=270 ;;
       KS )
         label='Kansas' ;
         arr_scale=0.3 ;
         nlat=40.2 ; slat=36.8 ;
         wlon=257.2 ; elon=265.7 ;;
       KY )
         label='Kentucky' ;
         arr_scale=0.3 ;
         nlat=39.3 ; slat=36.3 ;
         wlon=270 ; elon=279 ;;
       LA )
         label='Louisiana' ;
         arr_scale=0.3 ;
         nlat=33.2 ; slat=28.8 ;
         wlon=265.5 ; elon=271.2 ;;
       ME )
         label='Maine' ;
         arr_scale=0.3 ;
         nlat=47.5 ; slat=43 ;
         wlon=289 ; elon=293.3 ;;
       MD )
         label='Maryland' ;
         arr_scale=0.3 ;
         nlat=39.8 ; slat=37.7 ;
         wlon=280 ; elon=285 ;;
       MA )
         label='Massachusetts' ;
         arr_scale=0.3 ;
         nlat=43 ; slat=41.2 ;
         wlon=286 ; elon=290.3 ;;
       MI )
         label='Michigan' ;
         arr_scale=0.3 ;
         nlat=48.5 ; slat=41.5 ;
         wlon=269 ; elon=278 ;;
       MN )
         label='Minnesota' ;
         arr_scale=0.3 ;
         nlat=49.5 ; slat=43.3 ;
         wlon=262.5 ; elon=271 ;;
       MS )
         label='Mississippi' ;
         arr_scale=0.3 ;
         nlat=35.5 ; slat=29.5 ;
         wlon=268 ; elon=272.5 ;;
       MO )
         label='Missouri' ;
         arr_scale=0.3 ;
         nlat=40.7 ; slat=35.8 ;
         wlon=264 ; elon=271 ;;
       MT )
         label='Montana' ;
         arr_scale=0.3 ;
         nlat=49.2 ; slat=44.2 ;
         wlon=243.5 ; elon=256.5 ;;
       NE )
         label='Nebraska' ;
         arr_scale=0.3 ;
         nlat=43.3 ; slat=39.7 ;
         wlon=255.5 ; elon=265.2 ;;
       NV )
         label='Nevada' ;
         arr_scale=0.05 ;
         nlat=42.2 ; slat=34.8 ;
         wlon=239.7 ; elon=246.3 ;;
       NH )
         label='New Hampshire' ;
         arr_scale=0.3 ;
         nlat=45.5 ; slat=42.5 ;
         wlon=287.3 ; elon=289.5 ;;
       NJ )
         label='New Jersey' ;
         arr_scale=0.3 ;
         nlat=41.5 ; slat=38.7 ;
         wlon=284.3 ; elon=286.5 ;;
       NM )
         label='New Mexico' ;
         arr_scale=0.3 ;
         nlat=37.3 ; slat=31 ;
         wlon=250.7 ; elon=257.3 ;;
       NY )
         label='New York' ;
         arr_scale=0.3 ;
         nlat=45.3 ; slat=40 ;
         wlon=280 ; elon=288.5 ;;
       NC )
         label='North Carolina' ;
         arr_scale=0.3 ;
         nlat=37 ; slat=33.5 ;
         wlon=275 ; elon=281 ;;
       ND )
         label='North Dakota' ;
         arr_scale=0.3 ;
         nlat=49.3 ; slat=45.5 ;
         wlon=255.7 ; elon=264 ;;
       OH )
         label='Ohio' ;
         arr_scale=0.3 ;
         nlat=42 ; slat=38 ;
         wlon=275 ; elon=280 ;;
       OK )
         label='Oklahoma' ;
         arr_scale=0.3 ;
         nlat=37.3 ; slat=33.3 ;
         wlon=256.7 ; elon=266 ;;
       OR )
         label='Oregon' ;
         arr_scale=0.05 ;
         nlat=46.5 ; slat=41.7 ;
         wlon=235 ; elon=244 ;;
       PA )
         label='Pennsylvania' ;
         arr_scale=0.3 ;
         nlat=42.5 ; slat=39.5 ;
         wlon=279 ; elon=286 ;;
       RI )
         label='Rhode Island' ;
         arr_scale=0.3 ;
         nlat=42.1 ; slat=41.2 ;
         wlon=288 ; elon=289 ;;
       SC )
         label='South Carolina' ;
         arr_scale=0.3 ;
         nlat=35.5 ; slat=32 ;
         wlon=276 ; elon=282 ;;
       SD )
         label='South Dakota' ;
         arr_scale=0.3 ;
         nlat=46 ; slat=42.3 ;
         wlon=255.5 ; elon=264 ;;
       TN )
         label='Tennessee' ;
         arr_scale=0.3 ;
         nlat=37 ; slat=34.7 ;
         wlon=269 ; elon=279 ;;
       TX )
         label='Texas' ;
         arr_scale=0.3 ;
         nlat=37 ; slat=25 ;
         wlon=252.5 ; elon=267.5 ;;
       UT )
         label='Utah' ;
         arr_scale=0.3 ;
         nlat=42.3 ; slat=36.7 ;
         wlon=245.7 ; elon=251.3 ;;
       VT )
         label='Vermont' ;
         arr_scale=0.3 ;
         nlat=45.3 ; slat=42.5 ;
         wlon=286.5 ; elon=289 ;;
       VA )
         label='Virginia' ;
         arr_scale=0.3 ;
         nlat=39.7 ; slat=36.3 ;
         wlon=276 ; elon=285 ;;
       WA )
         label='Washington' ;
         arr_scale=0.05 ;
         nlat=49.3 ; slat=45.2 ;
         wlon=235 ; elon=243.5 ;;
       WV )
         label='West Virginia' ;
         arr_scale=0.3 ;
         nlat=40.7 ; slat=37 ;
         wlon=277 ; elon=283 ;;
       WI )
         label='Wisconsin' ;
         arr_scale=0.3 ;
         nlat=47.5 ; slat=42 ;
         wlon=266.5 ; elon=274 ;;
       WY )
         label='Wyoming' ;
         arr_scale=0.3 ;
         nlat=45.3 ; slat=40.7 ;
         wlon=248.7 ; elon=256.3 ;;
       na )
         label='North America' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=80 ; slat=60 ;
         wlon=130 ; elon=210 ;;
       cg )
         label='Canada Greenland Iceland' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=80 ; slat=40 ;
         wlon=215 ; elon=345 ;;
       ca )
         label='Central America' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=35 ; slat=0 ;
         wlon=240 ; elon=300 ;;
       jf )
         label='Juan de Fuca' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=55 ; slat=45 ;
         wlon=225 ; elon=240 ;;
       nz )
         label='Nazca' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/nz_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=10 ; slat=-55 ;
         wlon=240 ; elon=295 ;;
       sa )
         label='South America' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/sa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=20 ; slat=-60 ;
         wlon=275 ; elon=350 ;;
       sr )
         label='Sur' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/sa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-50 ; slat=-65 ;
         wlon=335 ; elon=359 ;;
       sc )
         label='Scotia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/sa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-50 ; slat=-62 ;
         wlon=285 ; elon=345 ;;
       sw )
         label='Sandwich' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/sa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-55 ; slat=-60 ;
         wlon=330 ; elon=345 ;;
       az )
         label='Azores' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/na_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=40 ; slat=35 ;
         wlon=320 ; elon=340 ;;
       nb )
         label='Nubia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/nb_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=45 ; slat=-60 ;
         wlon=-50 ; elon=45 ;;
       ar )
         label='Arabia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/ar_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=45 ; slat=10 ;
         wlon=30 ; elon=70 ;;
       eu )
         label='Eurasia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/eu_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=80 ; slat=15 ;
         wlon=-40 ; elon=150 ;;
       sm )
         label='Somalia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/sm_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=15 ; slat=-40 ;
         wlon=25 ; elon=70 ;;
       lw )
         label='Lwandle' ;
      	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/nb_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-10 ; slat=-55 ;
         wlon=25 ; elon=55 ;;
       wa )
         label='West Antarctic' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/an_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-25 ; slat=-80 ;
         wlon=30 ; elon=180 ;;
       ea )
         label='East Antarctic' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/an_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-25 ; slat=-80 ;
         wlon=-180 ; elon=30 ;;
       cp )
         label='Capricorn' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/au_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=0 ; slat=-30 ;
         wlon=60 ; elon=85 ;;
       in )
         label='India' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/in_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=40 ; slat=-10 ;
         wlon=55 ; elon=100 ;;
       au )
         label='Australia' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/au_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=5 ; slat=-60 ;
         wlon=70 ; elon=200 ;;
       su )
         label='Sundaland' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/au_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=25 ; slat=-15 ;
         wlon=85 ; elon=135 ;;
       yz )
         label='Yangtze' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/eu_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=50 ; slat=20 ;
         wlon=100 ; elon=135 ;;
       am )
         label='Amur' ;
 	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/eu_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=60 ; slat=35 ;
         wlon=85 ; elon=145 ;;
       ok )
         label='Okhotsk' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/pa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=65 ; slat=40 ;
         wlon=140 ; elon=170 ;;
       be )
         label='Bering' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/pa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=70 ; slat=50 ;
         wlon=160 ; elon=210 ;;
       ps )
         label='Philippine Sea' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/ph_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=40 ; slat=0 ;
         wlon=120 ; elon=155 ;;
       cr )
         label='Caroline' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/pa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=10 ; slat=-5 ;
         wlon=125 ; elon=155 ;;
       mq )
         label='Macquarie' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/au_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=-50 ; slat=-65 ;
         wlon=135 ; elon=155 ;;
       np )
         label='North Pacific' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/pa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=62 ; slat=0 ;
         wlon=140 ; elon=260 ;;
       sp )
         label='South Pacific' ;
  	 gawk '{print $1-0.05, $2, "8 0 1 7 ",$8}' ${dirvel}/pa_excluded.gmt > labels ;
         arr_scale=0.05 ;
         nlat=0 ; slat=-70 ;
         wlon=140 ; elon=260 ;;
     esac

xs=6.5 ; ys=8.5

scl_ew=`echo $elon $wlon | gawk '{ print '"${xs}"' / ($1 - $2) }'`
ysize=`echo $scl_ew $nlat $slat |gawk '{ print ($1 * ($2 - $3))/cos(3.1415926536*$3/180) }'`
scale=`echo $scl_ew $ysize | gawk '{if ($2 <= '"${ys}"' ) print $1 ; else print $1 * '"${ys}"'/$2 }'`

     frame=${wlon}/${elon}/${slat}/${nlat}
  echo $state $frame
     plot=${state}.ps

  if test ! -f /mnt/usr1/chuck/Web_Topo/${state}.grd ; then \
     img2grd $dir/topo_10.1.img -G${state}.grd -M -R$frame -D -m1 -S1 -T1 -V 
     grdgradient ${state}.grd -G${state}.grad -V -Nt -A$az1/$az2
  fi

grd2cpt /mnt/usr1/chuck/Web_Topo/${state}.grd -Ctopo -D -E20 > col.cpt
psbasemap -Y1 -R$frame -Jm$scale -Bf1a2::/a2f1::nSeW -K -P > $plot
grdimage -Jx$scale /mnt/usr1/chuck/Web_Topo/${state}.grd -I/mnt/usr1/chuck/Web_Topo/${state}.grad -C$shading -K -O >> $plot
pscoast -N1/2 -N2/2 -A100 -R -Jm -Df -W2 -O -K >> $plot

# Label the sites
pstext labels -Jm -R -O -K >> $plot

# Show all station velocities EXCEPT PROBLEM SITES, which are removed
# below using the grep -v command
cat $dirvel/ITRF05_vels.gmt | grep -v 'SHRV' | grep -v 'SA30' | \
  grep -v 'NMKM' | grep -v 'NOLA' | grep -v 'NCJV' | grep -v 'MSPO' | \
  grep -v 'PIT2' | grep -v 'PIT3' | grep -v '1NSU' | grep -v '1LSU' | \
  grep -v 'AZCL' | grep -v 'AZKR' | grep -v 'DSTR' | grep -v 'LSUA' | grep -v 'MSNA' | \
  grep -v 'NCGO' | grep -v 'HDF1' | \
  gawk '{print $1, $2}' | psxy -Sc0.06i -G255 -W2 -O -R -K -Jm >> $plot

cat $dirvel/na_excluded.gmt | grep -v 'SHRV' | grep -v 'SA30' | \
  grep -v 'NMKM' | grep -v 'NOLA' | grep -v 'NCJV' | grep -v 'MSPO' | \
  grep -v 'PIT2' | grep -v 'PIT3' | grep -v '1NSU' | grep -v '1LSU' | \
  grep -v 'AZCL' | grep -v 'AZKR' | grep -v 'DSTR' | grep -v 'LSUA' | grep -v 'MSNA' | \
  grep -v 'NCGO' | grep -v 'HDF1' | grep -v 'FOXV' | \
   psvelo -A0.025/0.12/0.07i -Jm -R -O -K -Sr${arr_scale}/0.68/0 -W1/255/255/255 -G255/0/0 >> $plot

pstext -G255/0/0 -Y-0.4 -N << END -Jm -R -O -K >> $plot
$wlon $slat 14 0 3 9 Velocity scale
END
psvelo -N -Y-0.12 -X2.3 -G255/0/0 -W3/255/0/0 -A0.025/0.12/0.07i << END -Jm -R -O -Sr${arr_scale}/0.68/13 >> $plot
$wlon $slat 2.0 0.0 0.1 0.1 0.0 2 mm yr@+-1@+
END

cat $plot | convert - -quality 100% -shave 30x20 -frame 20x20+12+0 /mnt/usr1/chuck/public_html/GPS_UWMadison/StateMaps/${state}.png 
#cat $plot | convert - -shave 30x20 -frame 20x20+12+0 -quality 100% ${state}.jpg 
rm -rf $plot
   done
rm -f labels col.cpt
