[GRASS-dev] GRASS 7 raster coding best practices
Yann Chemin
yann.chemin at gmail.com
Sat May 3 00:26:21 EDT 2008
Hi list,
I would like to open a discussion, hopefully quite short about
clean/short raster programming.
There are few things appearing that are nice coding practices, of
course I believe r.example exists, but it is not exhaustive, well it
is not intended to be anyway.
/* Define the different options */
input1 = G_define_standard_option(G_OPT_R_INPUT) ;
input1->key = _("albedo");
input1->description =_("Name of the Albedo map [0.0-1.0]");
input1->answer =_("albedo");
input1->guisection = _("Required");
In here you can find G_define_standard_option(G_OPT_R_INPUT) assuming
already those:
input1->type = TYPE_STRING;
input1->required = YES;
input1->gisprompt =_("old,cell,raster") ;
If your input is not required to run the module, you just create the
following line:
input1->required = NO;
Same goes for G_OPT_R_OUTPUT, but I could not find it for parameters
in float format (G_OPT_F_INPUT?) for example...
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.
In a similar way, metadata/history storage:
G_short_history(result1, "raster", &history);
G_command_history(&history);
G_write_history(result1,&history);
This is the standard incantation, but I have to find timestamp(), and
more details metadata maybe like sensor type for a start, or
source/origin of data... Can we make metadata having elements
(history->processing, history->timestamp, history->source(or
history->origin), etc?) then it could be filled up specifically.
Or color palettes application, discovered this recently, it is nice:
/* Color table for biomass */
G_init_colors(&colors);
G_add_color_rule(0,0,0,0,1,255,255,255,&colors);
I don't deny it, it must be there, I just would like to get things
together and identify what best (i.e. clean/complete/nice) coding I
can implement as a standard on the modules I work on...
Are there other gems hidden that we could simply list or make a more
exhaustive r.example2?
Thanks for your comments and suggestions,
Yann
--
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