[GRASS-dev] adding units and vertical datum metadata to raster maps

Paul Kelly paul-grass at stjohnspoint.co.uk
Wed May 9 08:03:30 EDT 2007


Hello Hamish

On Wed, 9 May 2007, Hamish wrote:

> (wish #392)
>
> Hi,
>
> I have hacked together the attached code to add units and vertical datum
> metadata to raster maps. It still needs some cleanup before going into
> CVS, but right now I am interested in comments on the approach taken.
> [it works]

I remember Helena saying something about wanting a module to be able to 
check what units an input raster map was in, so it could warn the user if 
there was a subtle error. But if the units are totally free-form then this 
is likely to be unreliable. I'm wondering if there is some kind of 
standard for specifying units in an ASCII text string, and if we should 
investigate this and add wrapper functions to these new functions that try 
to ensure the units are in a prescribed format where possible. Of course 
people could still put anything in using your functions directly, if they 
had special requirements. But perhaps the modules Helena identified as 
having a serious need for storing and checking units should have some 
higher level functions to do that for them?

>
> TODO: buffer overflow checking
>
>
> TODO: create a fn in r.info to take care of G_asprint() work, right now
> the "fancy output" section of the module is an ugly mess.
> [non-functional code, due to me being lost WRT passing pointers]

G_asprintf() takes a pointer to a pointer for the first argument, and the 
compose_line() function takes a pointer for the first argument. But below 
compose_line is being passed a pointer to a pointer (& operator used on
something that was already a pointer) and G_asprintf() is only being 
passed a pointer. I think changing it so "line" is passed to compose_line 
and "&line" to G_asprintf would work.

>
> /*
>        if (G_asprintf(&line, "Location: %s", G_location()) > 0)
>            printline(line);
>        else
>            G_fatal_error(_("Cannot allocate memory for string"));
> */
>        compose_line( &line, "Location: %s", G_location() );
>        printline(line);
> ....
>
> void compose_line(char *line, const char *fmt, ...)
> {
>    va_list ap;
>
>    line = NULL;
>    va_start(ap, fmt);
>
>    if( G_asprintf(line, fmt, ap) <= 0 )
>        G_fatal_error(_("Cannot allocate memory for string"));
>
>    va_end(ap);
> }
>
>
> Hamish
>




More information about the grass-dev mailing list