Created
April 14, 2017 18:35
-
-
Save khufkens/08d9b7a18d245c4b81ee066102a81b15 to your computer and use it in GitHub Desktop.
MODIS Batch Download Tool (MBDT) - downloads MODIS tiles per year / product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MODIS Batch Download Tool Command Line (MBDTcl) | |
# | |
# Bash script to download all modis hdf files for a particular year | |
# to the current directory. | |
# | |
# Beware this script will only download level 5 products | |
# if other products are selected the script will fail. | |
# | |
# Coded by Koen Hufkens at Boston University 2010 | |
server="http://e4ftl01.cr.usgs.gov" | |
#set +o noclobber | |
# give a MODIS product, year and a tiles file containing | |
# a list of tiles to be downloaded | |
# e.g. ./MBDTcl.sh MCD43A4 2009 tiles.txt | |
# set product subdirectory name based upon product name | |
filename=`echo $1 | cut -c 1-3` | |
echo $filename | |
if [ "$filename" = "MOD" ]; then | |
subset="MOLT" | |
elif [ "$filename" = "MYD" ]; then | |
subset="MOLA" | |
elif [ "$filename" = "MCD" ]; then | |
subset="MOTA" | |
else | |
echo "USE: ./MBDTcl.sh MCD43A4 2009 tiles.txt" | |
exit | |
fi | |
# set product name | |
product=$1 | |
# set year | |
year=$2 | |
# read tiles file | |
tiles=`cat $3` | |
echo "#########################################################################" | |
echo "" | |
echo "Downloading all tiles for $year, of product $product !" | |
echo "" | |
echo "Files completed:" | |
echo "" | |
# list directories | |
doy=`curl --silent ${server}/${subset}/${product}.005/ | cut -c52-61 | grep ${year}` | |
for i in $doy;do | |
for j in $tiles;do | |
mytile=`curl --silent ${server}/${subset}/${product}.005/${i}/ | grep -e "^.*\\.${j}\\..*\\.hdf" | tr '<>\"' ' ' | awk '{print $9}' | grep -v xml` | |
echo $mytile | |
if [ ! -z "$mytile" ];then | |
echo "Downloading: $mytile" | |
curl `echo "${server}/${subset}/${product}.005/${i}/${mytile}"` > ${mytile} | |
else | |
echo "skipping file" | |
fi | |
done | |
done | |
echo "############################# DONE ######################################" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment