#!/usr/bin/env bash




dataFile=/home/marcos/bcn_ptype/data/msl.nc
dataFileExtrema=/home/marcos/bcn_ptype/data/msl_extrema.nc
dataFileExtremaXYZ=/home/marcos/bcn_ptype/data/msl_extrema_xyz.nc
gmtset PS_MEDIA A3

for TILT in $(seq 0 10 0) ; do

  for AZIMUTH in $(seq 0 90 0) ; do

    for TWIST in $(seq 0 90 0) ; do

      for WIDTH in $(seq 50 10 90) ; do

        for HEIGHT in $(seq 50 10 90) ; do

          for ALTITUDE in $(seq 2000 500 2000) ; do

            # Nombre de la imagen.
            psFile=/home/marcos/tst/azimuth${AZIMUTH}_tilt${TILT}_twist${TWIST}_width${WIDTH}_height${HEIGHT}_altitude${ALTITUDE}.ps

            # Definición de parámetros de la proyección para la opción -J.
            lon0=0
            lat0=40
            altitude=${ALTITUDE} # Altura en km.
            azimuth=${AZIMUTH}  # azimuth is measured to the east of north of view
            tilt=${TILT} # tilt is the upward tilt of the plane of projection
            twist=${TWIST} # Further, specify the clockwise twist, Width, and Height of the viewpoint in degrees.
            Width=${WIDTH} # Anchura en grados.
            Height=${HEIGHT} # Altura en grados.
            width=16c # ancho del mapa en centímetros.
            J=G${lon0}/${lat0}/${altitude}/${azimuth}/${tilt}/${twist}/${Width}/${Height}/${width}

            # Argumentos para GMT.
            R="-10/10/-30/-20"

            #grdinfo -M -R${R} ${dataFile}?msl

            #gmt grdmath -R ${dataFile}?msl DUP EXTREMA 2 EQ MUL DUP 104600 GT MUL 0 NAN = ${dataFileExtrema}
            #gmt grd2xyz -R ${dataFileExtrema} -s > ${dataFileExtremaXYZ}
            #cat ${dataFileExtremaXYZ}


            pscoast -J${J} -R${R} -N1 -N3 -A1000 -Dh -Bp5 -Bg5 -Slightblue -Gdarkgray -W > ${psFile}
            #grdcontour ${dataFile}?msl -J -R -C300 -T-+lLH -S50 -W0p,red  -K -O >> ${psFile}
            #grdcontour ${dataFile}?msl -J -R -C300 -T++lLH -S50 -W0p,blue -K -O >> ${psFile}
            #gmtset FONT_ANNOT "8p,Helvetica,yellow"
            #gmtset FONT_ANNOT_PRIMARY "3p,Helvetica,pink"
            #grdcontour ${dataFile}?msl -J -R -C500 -Gn1 -A500+a0+gwhite -Wred -O -K >> ${psFile}
            #pstext -J -R ${dataFileExtremaXYZ} -O >> ${psFile}
            psconvert -Z -A -P -Tg -Qg4 -Qt4 ${psFile}
          done
        done
      done
    done
  done
done
rm -f ${dataFileExtrema} ${dataFileExtremaXYZ}
