~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.mapcalc/testsuite/const_map_test.sh

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Markus Neteler
 
4
# Test cases for 2D raster data
 
5
 
 
6
# Tests:
 
7
#   - generate 3x3 map, value 1/1.1
 
8
#   - calculate statistics
 
9
#   - compare with known results
 
10
 
 
11
#
 
12
# TODO
 
13
#   - how big EPSILON?
 
14
 
 
15
if [ -z "$GISBASE" ] ; then
 
16
    echo "You must be in GRASS GIS to run this program."
 
17
    exit 1
 
18
fi
 
19
 
 
20
#### check if we have awk
 
21
if [ ! -x "`which awk`" ] ; then
 
22
    echo "$PROG: awk required, please install first" 1>&2
 
23
    exit 1
 
24
fi
 
25
 
 
26
# setting environment, so that awk works properly in all languages
 
27
unset LC_ALL
 
28
export LC_NUMERIC=C
 
29
 
 
30
eval `g.gisenv`
 
31
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
 
32
LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
 
33
 
 
34
# some definitions
 
35
PIXEL=3
 
36
# how big EPSILON?
 
37
#    epsilon for doubles in IEEE is 2.220446e-16
 
38
EPSILON=22204460000000000
 
39
PID=$$
 
40
TMPNAME="`echo ${PID}_tmp_testmap | sed 's+\.+_+g'`"
 
41
 
 
42
# some functions - keep order here
 
43
cleanup()
 
44
{
 
45
 echo "Removing temporary map"
 
46
 g.remove -f type=raster name=$TMPNAME > /dev/null
 
47
}
 
48
 
 
49
# check if a MASK is already present:
 
50
MASKTMP=mask.$TMPNAME
 
51
USERMASK=usermask_${MASKTMP}
 
52
if test -f $LOCATION/cell/MASK
 
53
then
 
54
 echo "A user raster mask (MASK) is present. Saving it..."
 
55
 g.rename raster=MASK,$USERMASK > /dev/null
 
56
fi
 
57
 
 
58
finalcleanup()
 
59
{
 
60
 echo "Restoring user region"
 
61
 g.region region=$TMPNAME
 
62
 g.remove -f type=region name=$TMPNAME > /dev/null
 
63
 #restore user mask if present:
 
64
 if test -f $LOCATION/cell/$USERMASK ; then
 
65
  echo "Restoring user MASK"
 
66
  g.remove -f type=raster name=MASK > /dev/null
 
67
  g.rename raster=$USERMASK,MASK > /dev/null
 
68
 fi
 
69
}
 
70
 
 
71
check_exit_status()
 
72
{
 
73
 if [ $1 -ne 0 ] ; then
 
74
  echo "An error occurred."
 
75
  cleanup ; finalcleanup
 
76
  exit 1
 
77
 fi
 
78
}
 
79
 
 
80
########## test function goes here
 
81
compare_result()
 
82
{
 
83
 EXPECTED=$1
 
84
 FOUND=$2
 
85
 VALUENAME=$3
 
86
 
 
87
 # test for NAN
 
88
 if [ "$FOUND" = "nan" ] ; then
 
89
  echo "ERROR. $VALUENAME: Expected=$EXPECTED | FOUND=$FOUND"
 
90
  cleanup ; finalcleanup
 
91
  exit 1
 
92
 fi
 
93
 
 
94
 # check for difference + 1
 
95
 DIFF=`echo $EXPECTED $FOUND $EPSILON | awk '{printf "%16f", ($1 - $2) * $3 }'`
 
96
 #make absolute value
 
97
 DIFF=`echo $DIFF | awk '{printf("%f", sqrt($1 * $1))}'`
 
98
 #round to integer
 
99
 DIFF=`echo $DIFF | awk '{printf("%20d", int($1+0.5))}'`
 
100
 
 
101
 # check if difference > 0
 
102
 if [ $DIFF -gt 0 ] ; then
 
103
  echo "ERROR. $VALUENAME: Expected=$EXPECTED | FOUND=$FOUND"
 
104
  cleanup ; finalcleanup
 
105
  exit 1
 
106
 fi
 
107
}
 
108
 
 
109
#check if a MASK is already present:
 
110
MASKTMP=mask.$TMPNAME
 
111
USERMASK=usermask_${MASKTMP}
 
112
if test -f $LOCATION/cell/MASK
 
113
then
 
114
 echo "A user raster mask (MASK) is present. Saving it..."
 
115
 g.rename raster=MASK,$USERMASK > /dev/null
 
116
 check_exit_status $?
 
117
fi
 
118
 
 
119
echo "Saving current & setting test region."
 
120
g.region save=$TMPNAME
 
121
check_exit_status $?
 
122
g.region s=0 n=$PIXEL w=0 e=$PIXEL res=1 tbres=1
 
123
check_exit_status $?
 
124
 
 
125
########### 2D raster INT tests ###########
 
126
VALUE=1
 
127
echo "INT/CELL test."
 
128
r.mapcalc "$TMPNAME = 1"
 
129
check_exit_status $?
 
130
 
 
131
echo "Univariate statistics of INT/CELL test."
 
132
eval `r.univar -g $TMPNAME`
 
133
check_exit_status $?
 
134
compare_result 9 $n n
 
135
compare_result $VALUE $min min
 
136
compare_result $VALUE $max max
 
137
compare_result 0 $range range
 
138
compare_result $VALUE $mean mean
 
139
compare_result 0 $stddev stddev
 
140
compare_result 0 $variance variance
 
141
compare_result 0 $coeff_var coeff_var
 
142
compare_result 9 $sum sum
 
143
 
 
144
cleanup
 
145
echo "INT/CELL univariate statistics test successful"
 
146
echo "##################################"
 
147
 
 
148
########### 2D raster FCELL tests ###########
 
149
VALUE=1.1
 
150
echo "FLOAT/FCELL test."
 
151
r.mapcalc "$TMPNAME = $VALUE"
 
152
check_exit_status $?
 
153
 
 
154
echo "Univariate statistics of FLOAT/FCELL test."
 
155
eval `r.univar -g $TMPNAME`
 
156
check_exit_status $?
 
157
compare_result 9 $n n
 
158
compare_result $VALUE $min min
 
159
compare_result $VALUE $max max
 
160
compare_result 0 $range range
 
161
compare_result $VALUE $mean mean
 
162
compare_result 0 $stddev stddev
 
163
compare_result 0 $variance variance
 
164
compare_result 0 $coeff_var coeff_var
 
165
compare_result 9.9 $sum sum
 
166
 
 
167
cleanup
 
168
echo "FLOAT/FCELL univariate statistics test successful"
 
169
echo "##################################"
 
170
 
 
171
###########
 
172
# if we arrive here...
 
173
 
 
174
finalcleanup
 
175
echo "All tests successful. Congrats."
 
176
exit 0
 
177