|
@@ -17,30 +17,49 @@
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <grass/gis.h>
|
|
|
+#include <grass/raster.h>
|
|
|
#include <grass/glocale.h>
|
|
|
|
|
|
-#include "local_proto.h"
|
|
|
+static void rdwr_gridatb(const char *iname, const char *file)
|
|
|
+{
|
|
|
+ int fd = Rast_open_old(iname, "");
|
|
|
+ FILE *fp = fopen(file, "w");
|
|
|
+ DCELL *dcell = Rast_allocate_d_buf();
|
|
|
+ struct Cell_head cellhd;
|
|
|
+ int row, col;
|
|
|
+
|
|
|
+ Rast_get_window(&cellhd);
|
|
|
+
|
|
|
+ fprintf(fp, "%s\n", Rast_get_cell_title(iname, ""));
|
|
|
+ fprintf(fp, "%d %d %lf\n", cellhd.cols, cellhd.rows, cellhd.ns_res);
|
|
|
+
|
|
|
+ for (row = 0; row < cellhd.rows; row++) {
|
|
|
+ G_percent(row, cellhd.rows, 2);
|
|
|
|
|
|
-struct Cell_head cellhd;
|
|
|
-FCELL *cell;
|
|
|
-const char *file;
|
|
|
-const char *iname;
|
|
|
-char overwr;
|
|
|
+ Rast_get_d_row(fd, dcell, row);
|
|
|
+
|
|
|
+ for (col = 0; col < cellhd.cols; col++) {
|
|
|
+ if (Rast_is_d_null_value(&dcell[col]))
|
|
|
+ fprintf(fp, " 9999.00 ");
|
|
|
+ else
|
|
|
+ fprintf(fp, "%9.2f", (double) dcell[col]);
|
|
|
+ if (!((col + 1) % 8) || col == cellhd.cols - 1)
|
|
|
+ fprintf(fp, "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Rast_close(fd);
|
|
|
+}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
+ struct GModule *module;
|
|
|
struct
|
|
|
{
|
|
|
struct Option *input;
|
|
|
struct Option *output;
|
|
|
} params;
|
|
|
|
|
|
- struct
|
|
|
- {
|
|
|
- struct Flag *overwr;
|
|
|
- } flags;
|
|
|
- struct GModule *module;
|
|
|
-
|
|
|
G_gisinit(argv[0]);
|
|
|
|
|
|
/* Set description */
|
|
@@ -49,32 +68,15 @@ int main(int argc, char **argv)
|
|
|
module->description =
|
|
|
_("Exports GRASS raster map to GRIDATB.FOR map file (TOPMODEL)");
|
|
|
|
|
|
- params.input = G_define_option();
|
|
|
- params.input->key = "input";
|
|
|
- params.input->description = _("Input map");
|
|
|
- params.input->type = TYPE_STRING;
|
|
|
- params.input->required = YES;
|
|
|
- params.input->gisprompt = "old,cell,raster";
|
|
|
+ params.input = G_define_standard_option(G_OPT_R_INPUT);
|
|
|
|
|
|
- params.output = G_define_option();
|
|
|
- params.output->key = "output";
|
|
|
- params.output->description = _("GRIDATB i/o map file");
|
|
|
- params.output->type = TYPE_STRING;
|
|
|
- params.output->required = YES;
|
|
|
-
|
|
|
- flags.overwr = G_define_flag();
|
|
|
- flags.overwr->key = 'o';
|
|
|
- flags.overwr->description = _("Overwrite output map file");
|
|
|
+ params.output = G_define_standard_option(G_OPT_F_OUTPUT);
|
|
|
|
|
|
if (G_parser(argc, argv))
|
|
|
exit(1);
|
|
|
|
|
|
- iname = params.input->answer;
|
|
|
- file = params.output->answer;
|
|
|
- overwr = flags.overwr->answer;
|
|
|
-
|
|
|
- check_ready();
|
|
|
- rdwr_gridatb();
|
|
|
+ rdwr_gridatb(params.input->answer, params.output->answer);
|
|
|
|
|
|
- exit(0);
|
|
|
+ return EXIT_SUCCESS;
|
|
|
}
|
|
|
+
|