[GRASS-SVN] r40774 - grass/trunk/raster/r.out.gridatb
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 1 18:08:42 EST 2010
Author: glynn
Date: 2010-02-01 18:08:42 -0500 (Mon, 01 Feb 2010)
New Revision: 40774
Removed:
grass/trunk/raster/r.out.gridatb/adjcellhd.c
grass/trunk/raster/r.out.gridatb/check_ready.c
grass/trunk/raster/r.out.gridatb/file_io.c
grass/trunk/raster/r.out.gridatb/local_proto.h
Modified:
grass/trunk/raster/r.out.gridatb/main.c
Log:
Make r.out.gridatb honour current region
Fix bugs, simplify
Deleted: grass/trunk/raster/r.out.gridatb/adjcellhd.c
===================================================================
--- grass/trunk/raster/r.out.gridatb/adjcellhd.c 2010-02-01 23:07:47 UTC (rev 40773)
+++ grass/trunk/raster/r.out.gridatb/adjcellhd.c 2010-02-01 23:08:42 UTC (rev 40774)
@@ -1,17 +0,0 @@
-#include "local_proto.h"
-
-
-int adjcellhd(struct Cell_head *cellhd)
-{
- int retval = 0;
-
- G_set_window(cellhd);
-
- if (cellhd->rows != Rast_window_rows())
- retval = 2;
-
- if (cellhd->cols != Rast_window_cols())
- retval = 3;
-
- return (retval);
-}
Deleted: grass/trunk/raster/r.out.gridatb/check_ready.c
===================================================================
--- grass/trunk/raster/r.out.gridatb/check_ready.c 2010-02-01 23:07:47 UTC (rev 40773)
+++ grass/trunk/raster/r.out.gridatb/check_ready.c 2010-02-01 23:08:42 UTC (rev 40774)
@@ -1,20 +0,0 @@
-#include <unistd.h>
-#include "local_proto.h"
-#include <grass/glocale.h>
-
-
-void check_ready(void)
-{
- FILE *fp;
-
- fp = fopen(file, "r");
- if (!fp)
- return;
-
- fclose(fp);
-
- if (overwr)
- unlink(file);
- else
- G_fatal_error("%s - file already exists", file);
-}
Deleted: grass/trunk/raster/r.out.gridatb/file_io.c
===================================================================
--- grass/trunk/raster/r.out.gridatb/file_io.c 2010-02-01 23:07:47 UTC (rev 40773)
+++ grass/trunk/raster/r.out.gridatb/file_io.c 2010-02-01 23:08:42 UTC (rev 40774)
@@ -1,96 +0,0 @@
-#include <stdlib.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-
-void rdwr_gridatb(void)
-{
- FILE *fp;
- int fd, row, col;
- int adjcellhdval;
- CELL *cell;
- DCELL *dcell;
- FCELL *fcell;
- RASTER_MAP_TYPE data_type;
-
- fd = Rast_open_old(iname, "");
-
- data_type = Rast_get_map_type(fd);
- switch (data_type) {
- case CELL_TYPE:
- cell = Rast_allocate_c_buf();
- break;
- case FCELL_TYPE:
- fcell = Rast_allocate_f_buf();
- break;
- case DCELL_TYPE:
- dcell = Rast_allocate_d_buf();
- break;
- }
-
- Rast_get_cellhd(iname, "", &cellhd);
-
- adjcellhdval = adjcellhd(&cellhd);
- switch (adjcellhdval) {
- case 1:
- G_fatal_error(_("Setting window header"));
- break;
- case 2:
- G_fatal_error(_("Rows changed"));
- break;
- case 3:
- G_fatal_error(_("Cols changed"));
- break;
- }
-
- fp = fopen(file, "w");
-
- 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);
- switch (data_type) {
- case CELL_TYPE:
- Rast_get_c_row(fd, cell, row);
-
- for (col = 0; col < cellhd.cols; col++) {
- if (Rast_is_c_null_value(&cell[col]))
- fprintf(fp, " 9999.00 ");
- else
- fprintf(fp, "%9.2f ", (float)cell[col]);
- if (!((col + 1) % 8) || col == cellhd.cols - 1)
- fprintf(fp, "\n");
- }
- break;
- case FCELL_TYPE:
- Rast_get_f_row(fd, fcell, row);
-
- for (col = 0; col < cellhd.cols; col++) {
- if (Rast_is_f_null_value(&fcell[col]))
- fprintf(fp, " 9999.00 ");
- else
- fprintf(fp, "%9.2f ", (float)fcell[col]);
- if (!((col + 1) % 8) || col == cellhd.cols - 1)
- fprintf(fp, "\n");
- }
- break;
- case DCELL_TYPE:
- 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.2lf ", (double)dcell[col]);
- if (!((col + 1) % 8) || col == cellhd.cols - 1)
- fprintf(fp, "\n");
- }
- break;
- }
- }
- Rast_close(fd);
-
- return;
-}
Deleted: grass/trunk/raster/r.out.gridatb/local_proto.h
===================================================================
--- grass/trunk/raster/r.out.gridatb/local_proto.h 2010-02-01 23:07:47 UTC (rev 40773)
+++ grass/trunk/raster/r.out.gridatb/local_proto.h 2010-02-01 23:08:42 UTC (rev 40774)
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-
-void check_ready(void);
-int adjcellhd(struct Cell_head *cellhd);
-void rdwr_gridatb(void);
-
-
-extern struct Cell_head cellhd;
-extern FCELL *cell;
-extern const char *file;
-extern const char *iname;
-extern char overwr;
Modified: grass/trunk/raster/r.out.gridatb/main.c
===================================================================
--- grass/trunk/raster/r.out.gridatb/main.c 2010-02-01 23:07:47 UTC (rev 40773)
+++ grass/trunk/raster/r.out.gridatb/main.c 2010-02-01 23:08:42 UTC (rev 40774)
@@ -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;
-struct Cell_head cellhd;
-FCELL *cell;
-const char *file;
-const char *iname;
-char overwr;
+ 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);
+
+ 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 @@
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;
+ params.output = G_define_standard_option(G_OPT_F_OUTPUT);
- flags.overwr = G_define_flag();
- flags.overwr->key = 'o';
- flags.overwr->description = _("Overwrite output map file");
-
if (G_parser(argc, argv))
exit(1);
- iname = params.input->answer;
- file = params.output->answer;
- overwr = flags.overwr->answer;
+ rdwr_gridatb(params.input->answer, params.output->answer);
- check_ready();
- rdwr_gridatb();
+ return EXIT_SUCCESS;
+}
- exit(0);
-}
More information about the grass-commit
mailing list