[GRASS-dev] GRASS 7 raster coding best practices

Yann Chemin yann.chemin at gmail.com
Sat May 3 20:00:26 EDT 2008


2008/5/4 Glynn Clements <glynn at gclements.plus.com>:
>
>  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?
>
       input = G_define_option(G_OPT_F(D?)_INPUT) ;
       input->key        =_("parameter");
       input->type       = TYPE_DOUBLE;
       input->required   = YES;
       input->gisprompt  =_("value, parameter");
       input->description=_("Value of the parameter");
       /*input->answer     =_("0.000");*/
       input->guisection = _("Required");

I could also think similarly for non-GRASS files actually
(configuration files sometimes need to be loaded separately, i.e.
i.atcorr, btw I cant find it anymore in grass70).

>
>  > 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.
>

Yes, +1 for this.

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



-- 
Yann Chemin
International Rice Research Institute
Office: http://www.irri.org/gis
Perso: http://www.freewebs.com/ychemin


More information about the grass-dev mailing list