[GRASS5] Small glitch in d.measure

I just encountered a new, minor glitch in d.measure.

From GIS Manager menus, execute d.measure starts the tcltk gui for the
command. However, the output is pretty meaningless while the command is
running. Here is an example:

d.measure
e[He[2Je[He[2Je[He[2J

AFTER you quit, you get a nice screen of information that looks like this

Buttons:
Left: where am i
Middle: set FIRST vertex
Right: quit this
EAST: 711127.4334203
NORTH: 4285945.20996221
EAST: 711185.34103458
NORTH: 4285943.14183313

Left: where am i
Middle: set NEXT vertex
Right: FINISH
LEN: 120.33 meters
LEN: 268.38 meters
LEN: 449.68 meters

Buttons:
Left: DO ANOTHER
Middle:
Right: quit this

LEN: 449.68 meters
AREA: 0.33 hectares
AREA: 0.0013 square miles
AREA: 3340.46 square meters

This information (except for the final totals) needs to be shown during the
measurement session. This was the case in recent version of d.measure.

For now, I'll just have d.measure open in an xterm from the GUI, where it
works fine. I'll get this fixed in the CVS tomorrow and update the package
on my website soon (hopefully tomorrow).

Probably related to this, you now cannot get d.measure to open its tcltk
dialog from the command line. It only seems to operate in xterm mode. Seems
like some switch needs to be set differently.

Michael Barton

____________________
C. Michael Barton, Professor
School of Human Diversity and Social Change
PO Box 872402
Arizona State University
Tempe, AZ 85287-2402
USA

Phone: 480-965-6262
Fax: 480-965-7671
www: <www.public.asu.edu/~cmbarton>

Michael Barton wrote:

I just encountered a new, minor glitch in d.measure.

>From GIS Manager menus, execute d.measure starts the tcltk gui for the
command. However, the output is pretty meaningless while the command is
running. Here is an example:

d.measure
e[He[2Je[He[2Je[He[2J

That's because d.measure calls G_clear_screen(), which calls
system("clear"). Those are the "clear screen" sequence for xterm:

  $ infocmp xterm | fgrep clear
    clear=\E[H\E[2J, cnorm=\E[?25h, cr=^M,

AFTER you quit, you get a nice screen of information that looks like this

This information (except for the final totals) needs to be shown during the
measurement session. This was the case in recent version of d.measure.

This is a buffering issue. By default, stdout is block-buffered if it
is associated with a pipe, which is the case when it is run from the
Tcl/Tk dialog.

However, if you use "d.measure -s", the G_clear_screen() calls are
suppressed, and the information is written to stderr rather than
stdout. stderr is always unbuffered.

AFACIT, it isn't possible to merge stderr and stdout so that both are
sent back to Tcl. You can redirect stderr to a file or to an existing
descriptor; however, the pipe to which stdout is connected is created
by the open call, so you can't use it in the argument to open.

I suggest making two changes to d.measure:

1. Only call G_clear_screen() if stdout is a tty; although, this
change should probably go into G_clear_screen() itself.

2. Either explicitly make stdout line-buffered, or call fflush() after
writing each block of data.

Probably related to this, you now cannot get d.measure to open its tcltk
dialog from the command line. It only seems to operate in xterm mode. Seems
like some switch needs to be set differently.

d.measure is another one of those programs which has an argc check:

  if (argc > 1 && G_parser(argc,argv))
      exit(1);

This is because all of the parameters are optional; typical usage is
to run d.measure without arguments. You can use "d.measure --ui" to
force the dialog to be displayed.

--
Glynn Clements <glynn.clements@virgin.net>