Skip to content

Instantly share code, notes, and snippets.

@ce6n
Created October 22, 2013 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ce6n/7099459 to your computer and use it in GitHub Desktop.
Save ce6n/7099459 to your computer and use it in GitHub Desktop.
#!/bin/bash
##
## select grd files based on coordinates
## call with llx lly urx ury
##
#llx = "2540000"
#set lly = "-350000"
#set urx = "2650000"
#set ury = "-200000"
cd /scratch/clisap/landice/data_sets/ASTER_GDEM_V2/west_shackleton/
llx=$1
lly=$2
urx=$3
ury=$4
# remove old file
rm aster_grds.txt
touch aster_grds.txt
echo "removed old aster_grds.txt"
# counters
count=0
findings=0
for f in *.grd; do
# reset
ll_in=0
ul_in=0
ur_in=0
lr_in=0
vert_stripe=0
hori_stripe=0
# get x_min x_max as floats
x_min_f=`grdinfo $f | grep x_min | awk '{print $3}'`
x_max_f=`grdinfo $f | grep x_min | awk '{print $5}'`
# y_min y_max
y_min_f=`grdinfo $f | grep y_min | awk '{print $3}'`
y_max_f=`grdinfo $f | grep y_min | awk '{print $5}'`
#rounding
for bash_rounded_number in $(printf %.0f $x_min_f); do
x_min=$bash_rounded_number
done
for bash_rounded_number in $(printf %.0f $x_max_f); do
x_max=$bash_rounded_number
done
for bash_rounded_number in $(printf %.0f $y_min_f); do
y_min=$bash_rounded_number
done
for bash_rounded_number in $(printf %.0f $y_max_f); do
y_max=$bash_rounded_number
done
#echo "$x_min"
#echo "$x_max"
#echo "$y_min"
#echo "$y_max"
##############################################################
##
## a corner is within the survey area
##
# lower left
# x_min y_min
# ##
if [ $x_min -ge $llx -a $x_min -le $urx -a $y_min -ge $lly -a $y_min -le $ury ]; then
ll_in=1
fi
# upper left
# x_min y_max
if [ $x_min -ge $llx -a $x_min -le $urx -a $y_max -ge $lly -a $y_max -le $ury ]; then
ul_in=1
fi
# lower right
# x_max y_min
if [ $x_max -ge $llx -a $x_max -le $urx -a $y_min -ge $lly -a $y_min -le $ury ]; then
lr_in=1
fi
# upper right
# x_max y_max
if [ $x_max -ge $llx -a $x_max -le $urx -a $y_max -ge $lly -a $y_max -le $ury ]; then
ur_in=1
fi
#echo "lower left:" $ll_in
#echo "upper left:" $ul_in
#echo "lower right:" $lr_in
#echo "upper right:" $ur_in
###############################################################
##
## vertical stripe
##
## EEE
## EEE
## EEE
## 33338883333
## 33338883333
## 33338883333
## EEE
## EEE
if [ $y_min -le $lly -a $y_max -ge $ury -a $x_min -le $urx -a $x_max -ge $llx ]; then
vert_stripe=1
fi
##
## horizontal stripe
##
if [ $x_min -le $llx -a $x_max -ge $urx -a $y_min -le $ury -a $y_max -ge $lly ]; then
hori_stripe=1
fi
#echo "vertical stripe:" $vert_stripe
#echo "horizontal stripe:" $hori_stripe
#################################################################
##
## if any of these conditions is true, use the grd file
##
select=$((ll_in+ul_in+lr_in+ur_in+vert_stripe+hori_stripe))
# echo $select
if [ $select -ge 1 ]; then
echo "file" $f "is within the region."
echo $f >> aster_grds.txt
findings=$[$findings+1] # count checked files
fi
count=$[$count+1] # count checked files
done
echo "$findings out of $count files are within the region."
echo "wrote filenames to aster_grds.txt"
cd -
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment