-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
raster_md5test.sh
executable file
·148 lines (121 loc) · 3.16 KB
/
raster_md5test.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
# Markus Neteler
# Test cases for 2D raster data
# Tests:
# - generate 3x3 map, value 1/1.1
# - calculate md5sum
# - compare with known results
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program."
exit 1
fi
#### check if we have sed
if [ ! -x "`which sed`" ] ; then
echo "$PROG: sed required, please install first" 1>&2
exit 1
fi
#### check if we have md5sum
if [ ! -x "`which md5sum`" ] ; then
echo "$PROG: md5sum required, please install first" 1>&2
exit 1
fi
#### check if we have cut
if [ ! -x "`which cut`" ] ; then
echo "$PROG: cut required, please install first" 1>&2
exit 1
fi
# setting environment, so that awk works properly in all languages
unset LC_ALL
export LC_NUMERIC=C
# enforce ZLIB
export GRASS_COMPRESSOR=ZLIB
eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
MAPSET_PATH=$GISDBASE/$LOCATION_NAME/$MAPSET
# some definitions
PIXEL=3
PID=$$
TMPNAME="`echo ${PID}_tmp_testmap | sed 's+\.+_+g'`"
# some functions - keep order here
cleanup()
{
echo "Removing temporary map"
g.remove -f type=raster name=$TMPNAME > /dev/null
}
# check if a MASK is already present:
MASKTMP=mask.$TMPNAME
USERMASK=usermask_${MASKTMP}
if test -f $MAPSET_PATH/cell/MASK
then
echo "A user raster mask (MASK) is present. Saving it..."
g.rename raster=MASK,$USERMASK > /dev/null
fi
finalcleanup()
{
echo "Restoring user region"
g.region region=$TMPNAME
g.remove -f type=region name=$TMPNAME > /dev/null
#restore user mask if present:
if test -f $MAPSET_PATH/cell/$USERMASK ; then
echo "Restoring user MASK"
g.remove -f type=raster name=MASK > /dev/null
g.rename raster=$USERMASK,MASK > /dev/null
fi
}
check_exit_status()
{
if [ $1 -ne 0 ] ; then
echo "An error occurred."
cleanup ; finalcleanup
exit 1
fi
}
########## test function goes here
check_md5sum()
{
EXPECTED="$1"
FOUND="$2"
# test for NAN
if [ "$FOUND" = "nan" ] ; then
echo "ERROR. $VALUENAME: Expected=$EXPECTED | FOUND=$FOUND"
cleanup ; finalcleanup
exit 1
fi
if [ "$EXPECTED" != "$FOUND" ] ; then
echo "ERROR. The md5sum differs."
cleanup ; finalcleanup
exit 1
fi
}
echo "Saving current & setting test region."
g.region save=$TMPNAME
check_exit_status $?
g.region s=0 n=$PIXEL w=0 e=$PIXEL res=1 tbres=1
check_exit_status $?
########### 2D raster INT tests ###########
VALUE=1
echo "INT/CELL md5sum test."
r.mapcalc "$TMPNAME = 1"
check_exit_status $?
echo "MD5 checksum on output of INT/CELL test."
MD5="`r.out.ascii $TMPNAME precision=15 | md5sum | cut -d' ' -f1`"
check_md5sum "549e7dabe70df893803690571d2e1503" "$MD5"
cleanup
echo "INT/CELL md5sum test successful"
echo "##################################"
########### 2D raster FCELL tests ###########
VALUE=1.1
echo "FLOAT/FCELL md5sum test."
r.mapcalc "$TMPNAME = $VALUE"
check_exit_status $?
echo "MD5 checksum on output of FLOAT/FCELL test."
MD5="`r.out.ascii $TMPNAME precision=15 | md5sum | cut -d' ' -f1`"
check_md5sum "379f3d880b6d509051af6b4ccf470762" "$MD5"
cleanup
echo "FLOAT/FCELL md5sum test successful"
echo "##################################"
###########
# if we arrive here...
finalcleanup
echo "All tests successful. Congrats."
exit 0