[GRASS-user] shell script

Hi

I’m trying to run the script below but it’s giving me an error saying default region is not set.

Which command should I use to set the default region and do I put it?

#!/bin/sh

#variable to customize:

path to GRASS software main directory

GISBASE=/usr/lib/grass64

path to GRASS database

GISDBASE=$HOME/grassdem

nothing to change below

MAP=$1
LOCATION=$2

generate temporal LOCATION:

TEMPDIR=FLOODS
mkdir -p $GISDBASE/$TEMPDIR/PERMANENT

save existing $HOME/.grassrc6

if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /tmp/$TEMPDIR.grassrc6
fi

echo “LOCATION_NAME: $TEMPDIR” > $HOME/.grassrc6
echo “MAPSET:PERMANENT” >> $HOME/.grassrc6
echo “DIGITIZER: none” >> $HOME/.grassrc6
echo “GISDBASE: $GISDBASE” >> $HOME/.grassrc6
export GISBASE=$GISBASE

Create a WIND file with minimal information and no projection:

echo "proj: 0
zone: 0
north: 1
south: 0
east: 1
west: 0
cols: 1
rows: 1
e-w resol: 1
n-s resol: 1
top: 1
bottom: 0
cols3: 1
rows3: 1
depths: 1
e-w resol3: 1
n-s resol3: 1
t-b resol: 1
" > $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND

Copy WIND-file to DEFAULT_WIND:

cp $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND
$TEMPDIR/$LOCATION_NAME/$MAPSET/DEFAULT_WIND

Set default database driver:

echo "DBF_DRIVER: dbf
DB_DATABASE : $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
" > $TEMPDIR/$LOCATION_NAME/$MAPSET/VAR

export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
export GIS_LOCK=$$
export GISRC=$HOME/.grassrc6
db.connect driver=dbf database=‘$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/’

this should print GRASS version used:

g.version

g.proj --quiet -c epsg=4326

g.region --quiet -s n=90 s=-90 w=-180 e=180 res=1

other calculations go here…

import rainfall data set.

cd /home/tgumede1/grassdem

r.in.gdal input=$HOME/grassdem/TRMMLast1day.tif output=rainfall

g.region rast=rainfall


Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650

Sandile Gumede wrote:

Hi

I'm trying to run the script below but it's giving me an error saying default region is not set.

Which command should I use to set the default region and do I put it?

#!/bin/sh

#variable to customize:
# path to GRASS software main directory
GISBASE=/usr/lib/grass64
# path to GRASS database
GISDBASE=$HOME/grassdem

# nothing to change below
MAP=$1
LOCATION=$2

# generate temporal LOCATION:
TEMPDIR=FLOODS
mkdir -p $GISDBASE/$TEMPDIR/PERMANENT

# save existing $HOME/.grassrc6
if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /tmp/$TEMPDIR.grassrc6
fi

echo "LOCATION_NAME: $TEMPDIR" > $HOME/.grassrc6
echo "MAPSET:PERMANENT" >> $HOME/.grassrc6
echo "DIGITIZER: none" >> $HOME/.grassrc6
echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6
export GISBASE=$GISBASE

# Create a WIND file with minimal information and no projection:
echo "proj: 0
zone: 0
north: 1
south: 0
east: 1
west: 0
cols: 1
rows: 1
e-w resol: 1
n-s resol: 1
top: 1
bottom: 0
cols3: 1
rows3: 1
depths: 1
e-w resol3: 1
n-s resol3: 1
t-b resol: 1
" > $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND
# Copy WIND-file to DEFAULT_WIND:
cp $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND \
$TEMPDIR/$LOCATION_NAME/$MAPSET/DEFAULT_WIND

Where are the variables $LOCATION_NAME and $MAPSET being set? As far as I can see they seem to be empty - could that be the problem?

Paul

Hi,

How do I set $LOCATION_NAME and $MAPSET, I’ve tried but still saying LOCATION_NAME and MAPSET not set?

On Mon, Jun 28, 2010 at 11:51 AM, Paul Kelly <paul-grass@stjohnspoint.co.uk> wrote:

Sandile Gumede wrote:

Hi

I’m trying to run the script below but it’s giving me an error saying default region is not set.

Which command should I use to set the default region and do I put it?

#!/bin/sh

#variable to customize:

path to GRASS software main directory

GISDBASE=/home/tgumede1/grassdata
LOCATION_NAME=Floods
MAPSET=PERMANENT
GISBASE=/usr/lib/grass64

GSIDBASE= ‘g.gisenv GISDBASE’
LOCATION_NAME=‘g.gisenv LOCATION_NAME’
MAPSET=‘g.gisenv MAPSET’

LOCATION=“${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}”

nothing to change below

MAP=$1
LOCATION=$2

generate temporal LOCATION:

TEMPDIR=FLOODS
mkdir -p $GISDBASE/$TEMPDIR/PERMANENT

save existing $HOME/.grassrc6

if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /tmp/$TEMPDIR.grassrc6
fi

echo “LOCATION_NAME: $TEMPDIR” > $HOME/.grassrc6
echo “MAPSET:PERMANENT” >> $HOME/.grassrc6
echo “DIGITIZER: none” >> $HOME/.grassrc6
echo “GISDBASE: $GISDBASE” >> $HOME/.grassrc6
export GISBASE=$GISBASE

Create a WIND file with minimal information and no projection:

echo "proj: 0
zone: 0
north: 1
south: 0
east: 1
west: 0
cols: 1
rows: 1
e-w resol: 1
n-s resol: 1
top: 1
bottom: 0
cols3: 1
rows3: 1
depths: 1
e-w resol3: 1
n-s resol3: 1
t-b resol: 1
" > $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND

Copy WIND-file to DEFAULT_WIND:

cp $TEMPDIR/$LOCATION_NAME/$MAPSET/WIND
$TEMPDIR/$LOCATION_NAME/$MAPSET/DEFAULT_WIND

Where are the variables $LOCATION_NAME and $MAPSET being set? As far as I can see they seem to be empty - could that be the problem?

Paul


Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650