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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#!/bin/sh
############################################################################
#
# MODULE: g3.setregion.sh for GRASS 5.7
# AUTHOR(S): Markus Neteler (neteler itc it)
# PURPOSE: sets WIND3 file; a sort of g3.region with parser support.
# COPYRIGHT: (C) 2004 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
#TODO:
#
#%Module
#% description: g3.setregion modifies current 3D region
#%End
#%option
#% key: n
#% type: double
#% description: North extent
#% required : no
#%end
#%option
#% key: s
#% type: double
#% description: South extent
#% required : no
#%end
#%option
#% key: w
#% type: double
#% description: West extent
#% required : no
#%end
#%option
#% key: e
#% type: double
#% description: East extent
#% required : no
#%end
#%option
#% key: b
#% type: integer
#% description: Bottom height
#% required : no
#%end
#%option
#% key: t
#% type: integer
#% description: Top height
#% required : no
#%end
#%option
#% key: res
#% type: double
#% description: Horizontal resolution (2D)
#% required : no
#%end
#%option
#% key: dres
#% type: integer
#% description: Depth resolution (3D)
#% required : no
#%end
#%flag
#% key: u
#% description: update WIND3 from WIND/DEFAULT_WIND3
#%end
if [ -z $GISBASE ] ; then
echo "You must be in GRASS GIS to run this program."
exit 1
fi
if [ "$1" != "@ARGS_PARSED@" ] ; then
exec g.parser "$0" "$@"
fi
eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
UPDATE=0
if test ! -f $LOCATION/WIND3
then
echo "No 3D region settings present. Run g3.createwind first!"
exit
fi
north=`cat $LOCATION/WIND | awk ' /north:/ { print $2 }'`
south=`cat $LOCATION/WIND | awk ' /south:/ { print $2 }'`
east=`cat $LOCATION/WIND | awk ' /east:/ { print $2 }'`
west=`cat $LOCATION/WIND | awk ' /west:/ { print $2 }'`
res=`cat $LOCATION/WIND | awk ' /e-w resol:/ { print $3 }'`
#catch from default:
top=`cat $LOCATION/WIND3 | awk ' /Top:/ { printf "%.0f", $2 }'`
bottom=`cat $LOCATION/WIND3 | awk ' /Bottom:/ { printf "%.0f", $2 }'`
dres=`cat $LOCATION/WIND3 | awk ' /t-b resol:/ { printf "%.0f", $3 }'`
# add crash check here, then previously run g3.createwind
echo "Previous settings:"
echo "n:$north s:$south w:$west e:$east t:$top b:$bottom r:$res dres:$dres"
if [ $GIS_FLAG_u -ne 1] ; then
north=$GIS_OPT_n
south=$GIS_OPT_s
east=$GIS_OPT_e
west=$GIS_OPT_w
top=$GIS_OPT_t
bottom=$GIS_OPT_b
res=$GIS_OPT_res
dres=$GIS_OPT_dres
fi
#reset 2D region:
g.region n=$north s=$south w=$west e=$east res=$res
if [ $? -eq 1 ] ; then
echo "Check coordinate settings!"
exit
fi
#re-read new settings (don't want to calculate here):
north=`cat $LOCATION/WIND | awk ' /north:/ { print $2 }'`
south=`cat $LOCATION/WIND | awk ' /south:/ { print $2 }'`
east=`cat $LOCATION/WIND | awk ' /east:/ { print $2 }'`
west=`cat $LOCATION/WIND | awk ' /west:/ { print $2 }'`
res=`cat $LOCATION/WIND | awk ' /e-w resol:/ { print $3 }'`
echo ""
echo "Creating now WIND3 region with following parameters:"
cat $LOCATION/WIND | awk ' /proj:/ { print "Proj: "$2 }' > $LOCATION/WIND3
cat $LOCATION/WIND | awk ' /zone:/ { print "Zone: "$2 }' >> $LOCATION/WIND3
echo "North: $north" >> $LOCATION/WIND3
echo "South: $south" >> $LOCATION/WIND3
echo "East: $east" >> $LOCATION/WIND3
echo "West: $west" >> $LOCATION/WIND3
layer_number=`echo $bottom $top $dres | awk '{print ($2-$1)/$3}'`
echo "Top: $top" >> $LOCATION/WIND3
echo "Bottom: $bottom" >> $LOCATION/WIND3
echo " Top: $top"
echo " Bottom: $bottom"
# we need this later
number_rows=`cat $LOCATION/WIND | awk ' /rows:/ { print $2 }'`
echo "nofRows: $number_rows" >> $LOCATION/WIND3
number_cols=`cat $LOCATION/WIND | awk ' /cols:/ { print $2 }'`
echo "nofCols: $number_cols" >> $LOCATION/WIND3
echo "nofDepths: $layer_number" >> $LOCATION/WIND3
echo " nofDepths: $layer_number"
cat $LOCATION/WIND | awk ' /e-w/ { print "e-w resol: "$3 }' >> $LOCATION/WIND3
cat $LOCATION/WIND | awk ' /n-s/ { print "n-s resol: "$3 }' >> $LOCATION/WIND3
echo "t-b resol: $dres" >> $LOCATION/WIND3
echo " t-b resol: $dres"
# check bottom_height > top_height:
if [ $bottom -ge $top ]
then
echo "----- ERROR: bottom_height must be less than top_height."
rm -f $LOCATION/WIND3
exit
fi
number=`echo $number_rows $number_cols $layer_number | awk '{print ($1 * $2 * $3)}'`
echo "WIND3 file created/updated."
echo "You have defined a volume of $number tiles (cubes)."
# this needs to be improved!!:
#do we need this? yes, g3.region reads DEFAULT_WIND3 only!!
cp $LOCATION/WIND3 $LOCATION/../PERMANENT/DEFAULT_WIND3
echo ""
#echo "Please check the file:"
#echo "$LOCATION/WIND3"
#echo "Additionally check:"
#echo "$LOCATION/../PERMANENT/DEFAULT_WIND3"
echo "New settings:"
echo "n:$north s:$south w:$west e:$east t:$top b:$bottom r:$res dres:$dres"
echo "Now check with"
echo " g3.region"
|