[GRASS-dev] small patch for lib/vector/transform/

I needed some functionality to print the transformation matrix, very simple
patch - it might be useful to others.

It prints out the matrix along with a small note:

Transformation Matrix
---------------------
28155.882288 0.013530 1.002469
-5301.399323 0.997547 -0.009172
---------------------

the patch is attached.

Perhaps diagnostics like this might be a general use.

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341

(attachments)

print_matrix-patch-transform.c (477 Bytes)

On Friday 01 June 2007 12:33, Dylan Beaudette wrote:

I needed some functionality to print the transformation matrix, very simple
patch - it might be useful to others.

It prints out the matrix along with a small note:

Transformation Matrix
---------------------
28155.882288 0.013530 1.002469
-5301.399323 0.997547 -0.009172
---------------------

the patch is attached.

Perhaps diagnostics like this might be a general use.

ack. attached is a better version, with the ordering better spelled out. Note
that this matrix output is in the format that other applications like R and
PostGIS create / expect.

cheers

--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

(attachments)

print_matrix-patch-transform.c (538 Bytes)

Dylan Beaudette wrote:

On Friday 01 June 2007 12:33, Dylan Beaudette wrote:

I needed some functionality to print the transformation matrix, very simple
patch - it might be useful to others.

It prints out the matrix along with a small note:

Transformation Matrix
---------------------
28155.882288 0.013530 1.002469
-5301.399323 0.997547 -0.009172
---------------------

the patch is attached.

Please add it to patches tracker.

Maciek

Dylan Beaudette wrote:

I needed some functionality to print the transformation matrix, very simple
patch - it might be useful to others.

It prints out the matrix along with a small note:

Transformation Matrix
---------------------
28155.882288 0.013530 1.002469
-5301.399323 0.997547 -0.009172
---------------------

the patch is attached.

Perhaps diagnostics like this might be a general use.

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
Index: lib/vector/transform/transform.c

RCS file: /home/grass/grassrepository/grass6/lib/vector/transform/transform.c,v
retrieving revision 1.2
diff -r1.2 transform.c
146a147,152
> printf("Transformation Matrix\n");
> printf("------------------------------------------\n");
> printf("%f %f %f \n", B0, B1, B2);
> printf("%f %f %f \n", B3, B4, B5);
> printf("------------------------------------------\n");

First, patches should use either unified or context format (preferably
unified). However ...

Library code shouldn't be unconditionally printing diagnostic
information (especially not to stdout); use G_debug() instead.

If you need to print this information in normal use (without debugging
enabled), add a separate get_transformation_matrix() function to that
file.

Alternatively, you can implement it within your module using
transform_b_into_a(), i.e.:

  double B0, B1, B2, B3, B4, B5;

  transform_b_into_a(0, 0, &B0, &B3);
  transform_b_into_a(1, 0, &B1, &B4);
  B1 -= B0; B4 -= B3;
  transform_b_into_a(0, 1, &B2, &B5);
  B2 -= B0; B5 -= B3;

--
Glynn Clements <glynn@gclements.plus.com>

Hi Glynn, thanks for the pointers. Still a relatively new user of the
conventional dev tools...

On Saturday 02 June 2007 04:35, Glynn Clements wrote:

Dylan Beaudette wrote:
> I needed some functionality to print the transformation matrix, very
> simple patch - it might be useful to others.
>
> It prints out the matrix along with a small note:
>
> Transformation Matrix
> ---------------------
> 28155.882288 0.013530 1.002469
> -5301.399323 0.997547 -0.009172
> ---------------------
>
> the patch is attached.
>
> Perhaps diagnostics like this might be a general use.
>
>
> --
> Dylan Beaudette
> Soils and Biogeochemistry Graduate Group
> University of California at Davis
> 530.754.7341
> Index: lib/vector/transform/transform.c
> ===================================================================
> RCS file:
> /home/grass/grassrepository/grass6/lib/vector/transform/transform.c,v
> retrieving revision 1.2
> diff -r1.2 transform.c
> 146a147,152
>
> > printf("Transformation Matrix\n");
> > printf("------------------------------------------\n");
> > printf("%f %f %f \n", B0, B1, B2);
> > printf("%f %f %f \n", B3, B4, B5);
> > printf("------------------------------------------\n");

First, patches should use either unified or context format (preferably
unified). However ...

ok, I will read up on how to do this.

Library code shouldn't be unconditionally printing diagnostic
information (especially not to stdout); use G_debug() instead.

good call, that was definitely bad style on my part. Instead of debug, a flag
might be a good option?

If you need to print this information in normal use (without debugging
enabled), add a separate get_transformation_matrix() function to that
file.

This sounds reasonable. If possible it might be nice as a flag to v.transform.

Alternatively, you can implement it within your module using
transform_b_into_a(), i.e.:

  double B0, B1, B2, B3, B4, B5;

  transform_b_into_a(0, 0, &B0, &B3);
  transform_b_into_a(1, 0, &B1, &B4);
  B1 -= B0; B4 -= B3;
  transform_b_into_a(0, 1, &B2, &B5);
  B2 -= B0; B5 -= B3;

I will submit the new patch to the tracker.

thanks!

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341

Dylan Beaudette wrote:

> First, patches should use either unified or context format (preferably
> unified). However ...

ok, I will read up on how to do this.

Add the -u or -c flags to "diff" or "cvs diff". For CVS, you can add
"diff -u" to ~/.cvsrc to make it the default.

Some useful ~/.cvsrc settings:

  cvs -z3
  checkout -P
  update -dP
  diff -u

> Library code shouldn't be unconditionally printing diagnostic
> information (especially not to stdout); use G_debug() instead.

good call, that was definitely bad style on my part. Instead of debug, a flag
might be a good option?

Within the module, you can use G_verbose_message() for messages which
should only printed when --verbose is used. Or you could add a
specific flag.

The main point is that library code shouldn't have undesirable
side-effects. What is desirable varies between modules, so library
functions generally shouldn't do anything "extra"; that should be done
by individual modules.

--
Glynn Clements <glynn@gclements.plus.com>

Dylan:

> good call, that was definitely bad style on my part. Instead of
> debug, a flag might be a good option?

Glynn:

Within the module, you can use G_verbose_message() for messages which
should only printed when --verbose is used. Or you could add a
specific flag.

Output intended to be parsable should use fprintf(stdout, "..." ,);

G_*_message() and G_debug() will output to stderr and are more for
messages than outputing data.

A flag for output is a nice idea, whichever stdout or stderr you feel is
more appropriate.

Hamish

On Monday 04 June 2007 01:14, Hamish wrote:

Dylan:
> > good call, that was definitely bad style on my part. Instead of
> > debug, a flag might be a good option?

Glynn:
> Within the module, you can use G_verbose_message() for messages which
> should only printed when --verbose is used. Or you could add a
> specific flag.

Output intended to be parsable should use fprintf(stdout, "..." ,);

This looks like the best approach: however, I am getting a compile error
on 'stdout' not being defined... ideas?

G_*_message() and G_debug() will output to stderr and are more for
messages than outputing data.

A flag for output is a nice idea, whichever stdout or stderr you feel is
more appropriate.

I have implemented it as a flag. Patch is attached

If this looks ok, I can re-submit it to the grass tracker

thanks!

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341

(attachments)

v.transform.patch (4.32 KB)

On Saturday 02 June 2007 20:12, Glynn Clements wrote:

Dylan Beaudette wrote:
> > First, patches should use either unified or context format (preferably
> > unified). However ...
>
> ok, I will read up on how to do this.

Add the -u or -c flags to "diff" or "cvs diff". For CVS, you can add
"diff -u" to ~/.cvsrc to make it the default.

Some useful ~/.cvsrc settings:

  cvs -z3
  checkout -P
  update -dP
  diff -u

> > Library code shouldn't be unconditionally printing diagnostic
> > information (especially not to stdout); use G_debug() instead.
>
> good call, that was definitely bad style on my part. Instead of debug, a
> flag might be a good option?

Within the module, you can use G_verbose_message() for messages which
should only printed when --verbose is used. Or you could add a
specific flag.

The main point is that library code shouldn't have undesirable
side-effects. What is desirable varies between modules, so library
functions generally shouldn't do anything "extra"; that should be done
by individual modules.

Thanks for the tips Glynn. I have re-submitted some new ideas to the dev list.

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341