[GRASS-dev] GRASS 7 raster coding best practices

Glynn Clements glynn at gclements.plus.com
Sat May 3 18:15:57 EDT 2008


Yann Chemin wrote:

> Same goes for G_OPT_R_OUTPUT, but I could not find it for parameters
> in float format (G_OPT_F_INPUT?) for example...

Huh? What would be the settings for such an option?

> In another module (r.slope.aspect), I found an interesting code opennew():
> #include <stdlib.h>
> #include <grass/gis.h>
> #include <grass/glocale.h>
> int opennew (char *name, RASTER_MAP_TYPE wr_type){
>     int fd;
>     if (G_legal_filename (name) < 0)
>         G_fatal_error (_("<%s> is an illegal file name"), name);
>     if(wr_type < 0) /* default fp type */
>        fd = G_open_fp_cell_new (name);
>     else
>        fd = G_open_raster_new (name, wr_type);
>     if (fd < 0)
>         G_fatal_error (_("Failed in attempt to open %s"), name);
>     return fd;
> }
> 
> Sorry, i squashed it a bit for the email.
> Well, this could be interesting to also include a similar code in main GRASS,
> so we could reduce some coding length and ultimately clarify it.

I'm not sure that the above warrants a separate function.

First, the G_legal_filename() call is redundant; G_open_*_new()
already contain that check.

Second, I would prefer it if G_open_*_new() simply called
G_fatal_error() themselves if an error occured. It's not as if there's
any reasonable alternative way to handle the error.

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


More information about the grass-dev mailing list