/**************************************************************************** * * MODULE: r.terraflow * * COPYRIGHT (C) 2007 Laura Toma * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *****************************************************************************/ #include #include #include #include "tflowopts.h" userOptions *opt = NULL; void init_module(struct GModule **module) { *module = G_define_module(); #ifdef ELEV_SHORT (*module)->description = _("Flow computation for massive grids (Integer version)."); #endif #ifdef ELEV_FLOAT (*module)->description = _("Flow computation for massive grids (Float version)."); #endif } #define MAX_ACCU 1e+15 void parse_args(int argc, char *argv[]) { /* input elevation grid */ struct Option *input_elev; input_elev = G_define_standard_option(G_OPT_R_ELEV); /* output filled elevation grid */ struct Option *output_elev; output_elev = G_define_standard_option(G_OPT_R_OUTPUT); output_elev->key = "filled"; output_elev->description = _("Output filled (flooded) elevation raster map"); /* output direction grid */ struct Option *output_dir; output_dir = G_define_standard_option(G_OPT_R_OUTPUT); output_dir->key = "direction"; output_dir->description = _("Output flow direction raster map"); /* output sinkwatershed grid */ struct Option *output_watershed; output_watershed = G_define_standard_option(G_OPT_R_OUTPUT); output_watershed->key = "swatershed"; output_watershed->description = _("Output sink-watershed raster map"); /* output flow accumulation grid */ struct Option *output_accu; output_accu = G_define_standard_option(G_OPT_R_OUTPUT); output_accu->key = "accumulation"; output_accu->description = _("Output flow accumulation raster map"); #ifdef OUTPUT_TCI struct Option *output_tci; output_tci = G_define_standard_option(G_OPT_R_OUTPUT); output_tci->key = "tci"; output_tci->description = _("Output topographic convergence index (tci) raster map"); #endif /* MFD/SFD flag */ struct Flag *sfd_flag; sfd_flag = G_define_flag(); sfd_flag->key = 's'; sfd_flag->description = _("SFD (D8) flow (default is MFD)"); /* sfd_flag->answer = 'n'; */ /* D8CUT value */ struct Option *d8cut; d8cut = G_define_option(); d8cut->key = "d8cut"; d8cut->type = TYPE_DOUBLE; d8cut->required = NO; d8cut->answer = "infinity"; /* default value */ d8cut->description = _("If flow accumulation is larger than this value it is routed using " "SFD (D8) direction \n \t\t (meaningfull only for MFD flow)"); /* main memory */ struct Option *mem; mem = G_define_option(); mem->key = "memory"; mem->type = TYPE_INTEGER; mem->required = NO; mem->answer = "300"; /* 300MB default value */ mem->description = _("Maximum runtime memory size (in MB)"); /* temporary STREAM path */ struct Option *streamdir; streamdir = G_define_option(); streamdir->key = "STREAM_DIR"; streamdir->type = TYPE_STRING; streamdir->required = NO; streamdir->answer = "/var/tmp"; streamdir->description = _("Directory to hold temporary files (they can be large)"); /* verbose flag */ /* please, remove before GRASS 7 released */ struct Flag *quiet; quiet = G_define_flag(); quiet->key = 'q'; quiet->description = _("Quiet"); /* quiet->answer = 'n'; */ /* stats file */ struct Option *stats_opt; stats_opt = G_define_option(); stats_opt->key = "stats"; stats_opt->type = TYPE_STRING; stats_opt->required = NO; stats_opt->description = _("Name of file containing runtime statistics"); stats_opt->answer = "stats.out"; if (G_parser(argc, argv)) { exit(EXIT_FAILURE); } /* ************************* */ opt->elev_grid = input_elev->answer; opt->filled_grid = output_elev->answer; opt->dir_grid = output_dir->answer; opt->watershed_grid = output_watershed->answer; opt->flowaccu_grid = output_accu->answer; #ifdef OUTPUT_TCI opt->tci_grid = output_tci->answer; #endif opt->d8 = sfd_flag->answer; if (strcmp(d8cut->answer, "infinity") == 0) { opt->d8cut = MAX_ACCU; } else { opt->d8cut = atoi(d8cut->answer); } opt->mem = atoi(mem->answer); opt->streamdir = streamdir->answer; opt->verbose = FALSE; /* please, remove before GRASS 7 released */ if (quiet->answer) { G_warning(_("The '-q' flag is superseded and will be removed " "in future. Please use '--quiet' instead.")); G_putenv("GRASS_VERBOSE", "0"); opt->verbose = FALSE; } else { if (G_verbose() == G_verbose_max()) opt->verbose = TRUE; } opt->stats = stats_opt->answer; /* somebody should delete the options */ } #undef MAX_ACCU