-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_fmask.sh
75 lines (55 loc) · 1.48 KB
/
run_fmask.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
shopt -s nullglob
MCROOT=/usr/local/MATLAB/MATLAB_Runtime/v910
# parse command line
if [ $# -lt 2 ] || [ "$1" == "--help" ]; then
echo "Usage: run_fmask.sh SCENE_ID GRANULE FMASK_OPTIONS"
exit 0
fi
SCENE_ID="$1"
shift
GRANULE="$1"
shift
INDIR=/mnt/input-dir/$SCENE_ID.SAFE
WORKDIR=/work/$SCENE_ID.SAFE
OUTDIR=/mnt/output-dir
if [ ! -d "$INDIR" ]; then
echo "Error: no SAFE file found for scene ID $SCENE_ID"
exit 1
fi
# ensure that workdir is clean
if [ -d $WORKDIR ]; then
rm -rf $WORKDIR
fi
mkdir -p $WORKDIR
# symlink safe data into workdir
for f in $INDIR/*; do
if [ "$(basename $f)" != "GRANULE" ]; then
ln -s $(readlink -f $f) $WORKDIR/$(basename $f)
fi
done
# run fmask for every granule in SAFE
for granule_path in "$INDIR/GRANULE/$GRANULE"; do
granule=$(basename $granule_path)
echo "Processing granule $granule"
granuledir=$WORKDIR/GRANULE/$granule
mkdir -p $granuledir
# symlink granule data into workdir
for f in $INDIR/GRANULE/$granule/*; do
ln -s $(readlink -f $f) $granuledir/$(basename $f)
done
# call fmask
cd $granuledir
/usr/GERS/Fmask_4_5/application/run_Fmask_4_5.sh $MCROOT "$@"
if [ ! -d $granuledir/FMASK_DATA ]; then
echo "Error while running FMask on granule $granule"
exit 1
fi
# copy outputs from workdir
mkdir -p $OUTDIR/$granule
for f in $granuledir/FMASK_DATA/*; do
cp $f $OUTDIR/$granule
done
done
rm -rf $WORKDIR