[GRASS-user] v.rast.stats2 bug?

I just checked out v.rast.stats2 (Feb.28) and when I run it I get the
following error.

Do I need to file a ticket, or am I missing something obvious? While
it says 'done', the table is unpopulated.

awk: {printf "\nUPDATE acoe_jd SET dist_n
awk: ^ unterminated string
sed: couldn't write 176 items to stdout: Broken pipe
Restoring previous MASK...
Statistics calculated from raster map <streams_distance_ft@PERMANENT>
and uploaded to attribute table of vector map <acoe_jd>.
Done.

Much thanks,
Mark

On Tue, Mar 1, 2011 at 2:02 AM, Mark Seibel <mseibel@gmail.com> wrote:

I just checked out v.rast.stats2 (Feb.28) and when I run it I get the
following error.

Do I need to file a ticket, or am I missing something obvious? While
it says 'done', the table is unpopulated.

awk: {printf "\nUPDATE acoe_jd SET dist_n
awk: ^ unterminated string
sed: couldn't write 176 items to stdout: Broken pipe

I can confirm this bug.

The offending line is
sed -e '1d' "$STATSTMP" | awk -F "|" '{printf "\nUPDATE '${TABLE}' SET
'${col[0]}' = %i , '${col[1]}' = %.2f , '${col[2]}' = %.2f ,
'${col[3]}' = %.2f , '${col[4]}' = %.2f , '${col[5]}' = %.2f ,
'${col[6]}' = %.2f , '${col[7]}' = %.2f , '${col[8]}' = %.2f WHERE
'${KEYCOL}' = %i;", $2,$3,$4,$5,$6,$7,$8,$9,$10,$1}'

which fails due to a bad management of the used array:

++ cat /home/neteler/grassdata/spearfish60/neteler/.tmp/north/12201.0.col
++ tr '\n' ' '
+ col='dem_n dem_min dem_max dem_range dem_mean dem_stddev dem_varian
dem_cf_var dem_sum '
+ g.message -v 'Creating SQL file ...'
+ '[' 0 -eq 1 ']'
+ sed -e 1d /home/neteler/grassdata/spearfish60/neteler/.tmp/north/12201.0.csv
+ awk -F '|' '{printf "\nUPDATE myfields SET dem_n' dem_min dem_max
dem_range dem_mean dem_stddev dem_varian dem_cf_var dem_sum ' = %i ,
= %.2f , = %.2f , = %.2f , = %.2f , = %.2f , = %.2f , = %.2f ,
= %.2f WHERE cat = %i;", $2,$3,$4,$5,$6,$7,$8,$9,$10,$1}'
awk: {printf "\nUPDATE myfields SET dem_n
awk: ^ unterminated string

Actually I don't know how to fix the use of col[1] etc. (I tried a while).

Markus

Markus wrote:

I can confirm this bug.

The offending line is
sed -e '1d' "$STATSTMP" | awk -F "|" '{printf "\nUPDATE '${TABLE}' SET
'${col[0]}' = %i , '${col[1]}' = %.2f , '${col[2]}' = %.2f,
'${col[3]}' = %.2f , '${col[4]}' = %.2f , '${col[5]}' = %.2f ,
'${col[6]}' = %.2f , '${col[7]}' = %.2f , '${col[8]}' = %.2f WHERE
'${KEYCOL}' = %i;", $2,$3,$4,$5,$6,$7,$8,$9,$10,$1}'

...

Actually I don't know how to fix the use of col[1] etc. (I
tried a while).

it is trying to use shell $VARIABLES inside 'single quotes', so the $ is
treated literally instead of getting substituted.

the awk string either needs to be using double quotes like "{printf( .. )}"
or (better) you need to pass each variable to awk on the command line using
the -v flag:

    -v var=val
    --assign var=val
           Assign the value val to the variable var, before execution
           of the program begins. Such variable values are available
           to the BEGIN block of an AWK program.

thus

$ TABLE=abc
$ awk -v TBL="$TABLE" 'BEGIN {print TBL}'
abc

(BEGIN is used to avoid it waiting for stdin)

...also quoting like ${TABLE} does nothing in this situation besides
clutter the readability. "quotes" must to used to protect from spaces in
the string:

$ VAL="a b"

$ ls "$VAL"
ls: a b: No such file or directory

$ ls ${VAL}
ls: a: No such file or directory
ls: b: No such file or directory

$ ls ${VAL}_123
ls: a: No such file or directory
ls: b_123: No such file or directory

$ ls "${VAL}_123"
ls: a b_123: No such file or directory

Hamish

On Thu, Mar 3, 2011 at 9:54 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus wrote:

I can confirm this bug.

For the record: Markus Metz has fixed it in SVN.

Markus