#!/bin/bash
cd /home/slin/enduro-trails/data/srtm

for t in N56E040 N57E037 N57E038 N57E039 N57E040 N58E037 N58E038 N58E039 N58E040 N59E038 N59E039 N59E040 N59E041 N60E040 N60E041 N60E042 N54E042 N54E043 N54E044 N54E045 N53E042 N53E043 N53E044 N53E045 N52E042 N52E043 N52E044 N52E045 N51E038 N51E039 N51E040 N51E041 N50E038 N50E039 N50E040 N50E041 N55E047 N55E048 N55E049 N55E050 N54E047 N54E048 N54E049 N54E050 N56E047 N56E048 N56E049 N56E050; do
  if [ -f "${t}.hgt" ]; then
    echo "SKIP ${t}"
    continue
  fi
  lat="${t:1:2}"
  url="https://s3.amazonaws.com/elevation-tiles-prod/skadi/${lat}/${t}.hgt.gz"
  echo "DL ${t}"
  curl -s -o "${t}.hgt.gz" -w "%{http_code}" --max-time 90 --retry 5 --retry-delay 3 "$url" >/dev/null
  if [ -s "${t}.hgt.gz" ]; then
    gunzip -f "${t}.hgt.gz"
    if [ -f "${t}.hgt" ]; then
      echo "OK ${t}"
    else
      echo "FAIL ${t} (gunzip)"
    fi
  else
    echo "FAIL ${t} (empty)"
    rm -f "${t}.hgt.gz"
  fi
done

echo ""
echo "Total .hgt files: $(ls *.hgt 2>/dev/null | wc -l)"
