[GRASS-SVN] r43552 -
grass/branches/develbranch_6/raster/r.surf.contour
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 21 03:15:48 EDT 2010
Author: mmetz
Date: 2010-09-21 07:15:48 +0000 (Tue, 21 Sep 2010)
New Revision: 43552
Added:
grass/branches/develbranch_6/raster/r.surf.contour/dseg_close.c
grass/branches/develbranch_6/raster/r.surf.contour/dseg_get.c
grass/branches/develbranch_6/raster/r.surf.contour/dseg_open.c
grass/branches/develbranch_6/raster/r.surf.contour/dseg_put.c
grass/branches/develbranch_6/raster/r.surf.contour/dseg_read.c
grass/branches/develbranch_6/raster/r.surf.contour/dseg_write.c
grass/branches/develbranch_6/raster/r.surf.contour/seg.h
Removed:
grass/branches/develbranch_6/raster/r.surf.contour/cseg.h
grass/branches/develbranch_6/raster/r.surf.contour/cseg_close.c
grass/branches/develbranch_6/raster/r.surf.contour/cseg_get.c
grass/branches/develbranch_6/raster/r.surf.contour/cseg_open.c
grass/branches/develbranch_6/raster/r.surf.contour/cseg_put.c
grass/branches/develbranch_6/raster/r.surf.contour/cseg_read.c
grass/branches/develbranch_6/raster/r.surf.contour/cseg_write.c
Modified:
grass/branches/develbranch_6/raster/r.surf.contour/addpts.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_close.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_get.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_open.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_put.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_read.c
grass/branches/develbranch_6/raster/r.surf.contour/bseg_write.c
grass/branches/develbranch_6/raster/r.surf.contour/contour.h
grass/branches/develbranch_6/raster/r.surf.contour/find_con.c
grass/branches/develbranch_6/raster/r.surf.contour/main.c
Log:
add fp and NULL (nodata) support
Modified: grass/branches/develbranch_6/raster/r.surf.contour/addpts.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/addpts.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/addpts.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -3,7 +3,7 @@
NODE *addpts_slow(NODE * zero, int r, int c, int rr, int cc, int *node_ct)
{
NODE *add_in_slow();
- CELL value;
+ char value;
if (rr < nrows - 1) {
bseg_get(&bseen, &value, rr + 1, cc);
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_close.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_close.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_close.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,6 +1,6 @@
#include <unistd.h>
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
int bseg_close(BSEG * bseg)
{
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_get.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_get.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_get.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,18 +1,18 @@
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
-int bseg_get(BSEG * bseg, CELL * value, int row, int col)
+int bseg_get(BSEG * bseg, char * value, int row, int col)
{
unsigned char x;
char errmsg[200];
- if (segment_get(&(bseg->seg), (int *)&x, row, col >> 3) < 0) {
+ if (segment_get(&(bseg->seg), &x, row, col >> 3) < 0) {
sprintf(errmsg,
"bseg_get(): could not read segment file at r:%d c:%d",
(int)row, (int)col);
G_warning(errmsg);
return -1;
}
- *value = (CELL) ((x & (1 << (col & 7))) ? 1 : 0);
+ *value = (char) ((x & (1 << (col & 7))) ? 1 : 0);
return 0;
}
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_open.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_open.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_open.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -3,7 +3,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
int bseg_open(BSEG * bseg, int srows, int scols, int nsegs_in_memory)
{
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_put.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_put.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_put.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,12 +1,12 @@
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
-int bseg_put(BSEG * bseg, CELL * value, int row, int col)
+int bseg_put(BSEG * bseg, char * value, int row, int col)
{
unsigned char old_value;
char errmsg[200];
- if (segment_get(&(bseg->seg), (int *)&old_value, row, col >> 3) < 0) {
+ if (segment_get(&(bseg->seg), &old_value, row, col >> 3) < 0) {
sprintf(errmsg,
"bseg_put(): could not read segment file at r:%d c:%d",
(int)row, (int)col);
@@ -17,7 +17,7 @@
old_value |= (1 << (col & 7));
else
old_value &= ~(1 << (col & 7));
- if (segment_put(&(bseg->seg), (int *)&old_value, row, col >> 3) < 0) {
+ if (segment_put(&(bseg->seg), &old_value, row, col >> 3) < 0) {
sprintf(errmsg,
"bseg_put(): could not write segment file at r:%d c:%d",
(int)row, (int)col);
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_read.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_read.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_read.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,6 +1,6 @@
#include <unistd.h>
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
static char *me = "bseg_read_cell";
@@ -11,6 +11,7 @@
int map_fd;
char msg[100];
CELL *buffer;
+ char value;
bseg->name = NULL;
bseg->mapset = NULL;
@@ -35,7 +36,8 @@
return -2;
}
for (col = ncols; col >= 0; col--) {
- bseg_put(bseg, &(buffer[col]), row, col);
+ value = (char) buffer[col];
+ bseg_put(bseg, &(value), row, col);
}
}
Modified: grass/branches/develbranch_6/raster/r.surf.contour/bseg_write.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/bseg_write.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/bseg_write.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,5 +1,5 @@
#include <grass/gis.h>
-#include "cseg.h"
+#include "seg.h"
static char *me = "bseg_write_cell";
@@ -9,7 +9,7 @@
int row, nrows;
int col, ncols;
CELL *buffer;
- CELL value;
+ char value;
map_fd = G_open_cell_new(map_name);
if (map_fd < 0) {
Modified: grass/branches/develbranch_6/raster/r.surf.contour/contour.h
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/contour.h 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/contour.h 2010-09-21 07:15:48 UTC (rev 43552)
@@ -2,7 +2,7 @@
#include <math.h>
#include <grass/gis.h>
#include "flag.h"
-#include "cseg.h"
+#include "seg.h"
#define NODE struct _n_o_d_e_
#define INIT_AR 64
@@ -31,11 +31,11 @@
GLOBAL int maxr;
GLOBAL int array_size;
GLOBAL double i_val_l_f;
-GLOBAL CSEG con;
+GLOBAL DSEG con;
GLOBAL FLAG *seen, *mask;
GLOBAL BSEG bseen, bmask;
GLOBAL NODE *zero;
-GLOBAL CELL on, off;
+GLOBAL char on, off;
/* add_in.c */
NODE *add_in_slow(int, int, int, int, NODE *, int *);
@@ -46,5 +46,5 @@
NODE *addpts(NODE *, int, int, int, int, int *);
/* find_con.c */
-int find_con_slow(int, int, double *, double *, CELL *, CELL *);
-int find_con(int, int, double *, double *, CELL *, CELL *);
+int find_con_slow(int, int, double *, double *, DCELL *, DCELL *);
+int find_con(int, int, double *, double *, DCELL *, DCELL *);
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg.h
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg.h 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg.h 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,64 +0,0 @@
-#include <grass/segment.h>
-
-#define CSEG struct _c_s_e_g_
-CSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-#define DSEG struct _d_s_e_g_
-DSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-#define BSEG struct _b_s_e_g_
-BSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-/* bseg_close.c */
-int bseg_close(BSEG *);
-
-/* bseg_get.c */
-int bseg_get(BSEG *, CELL *, int, int);
-
-/* bseg_open.c */
-int bseg_open(BSEG *, int, int, int);
-
-/* bseg_put.c */
-int bseg_put(BSEG *, CELL *, int, int);
-
-/* bseg_read.c */
-int bseg_read_cell(BSEG *, char *, char *);
-
-/* bseg_write.c */
-int bseg_write_cellfile(BSEG *, char *);
-
-/* cseg_close.c */
-int cseg_close(CSEG *);
-
-/* cseg_get.c */
-int cseg_get(CSEG *, int, int, CELL *);
-
-/* cseg_open.c */
-int cseg_open(CSEG *, int, int, int);
-
-/* cseg_put.c */
-int cseg_put(CSEG *, int, int, CELL);
-
-/* cseg_read.c */
-int cseg_read_cell(CSEG *, char *, char *);
-
-/* cseg_write.c */
-int cseg_write_cellfile(CSEG *, char *);
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_close.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_close.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_close.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,19 +0,0 @@
-#include <grass/gis.h>
-#include <unistd.h>
-#include "cseg.h"
-
-int cseg_close(CSEG * cseg)
-{
- segment_release(&(cseg->seg));
- close(cseg->fd);
- unlink(cseg->filename);
- if (cseg->name) {
- G_free(cseg->name);
- cseg->name = NULL;
- }
- if (cseg->mapset) {
- G_free(cseg->mapset);
- cseg->mapset = NULL;
- }
- return 0;
-}
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_get.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_get.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_get.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,11 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_get(CSEG * cseg, int row, int col, CELL * value)
-{
- if (segment_get(&(cseg->seg), value, row, col) < 0) {
- G_warning("cseg_get(): could not read segment file");
- return -1;
- }
- return 0;
-}
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_open.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_open.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_open.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,60 +0,0 @@
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_open(CSEG * cseg, int srows, int scols, int nsegs_in_memory)
-{
- char *filename;
- int errflag;
- int fd;
-
- cseg->filename = NULL;
- cseg->fd = -1;
- cseg->name = NULL;
- cseg->mapset = NULL;
-
- filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("cseg_open(): unable to create segment file");
- return -2;
- }
- if (0 >
- (errflag =
- segment_format(fd, G_window_rows(), G_window_cols(), srows, scols,
- sizeof(CELL)))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("cseg_open(): could not write segment file");
- return -1;
- }
- else {
- G_warning("cseg_open(): illegal configuration parameter(s)");
- return -3;
- }
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("cseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = segment_init(&(cseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("cseg_open(): could not read segment file");
- return -5;
- }
- else {
- G_warning("cseg_open(): out of memory");
- return -6;
- }
- }
- cseg->filename = filename;
- cseg->fd = fd;
- return 0;
-}
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_put.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_put.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_put.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,11 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_put(CSEG * cseg, int row, int col, CELL value)
-{
- if (segment_put(&(cseg->seg), &value, row, col) < 0) {
- G_warning("cseg_put(): could not write segment file");
- return -1;
- }
- return 0;
-}
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_read.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_read.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_read.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,51 +0,0 @@
-#include <grass/gis.h>
-#include <unistd.h>
-#include "cseg.h"
-
-static char *me = "cseg_read_cell";
-
-int cseg_read_cell(CSEG * cseg, char *map_name, char *mapset)
-{
- int row, nrows;
- int map_fd;
- char msg[100];
- CELL *buffer;
-
- cseg->name = NULL;
- cseg->mapset = NULL;
-
- if ((map_fd = G_open_cell_old(map_name, mapset)) < 0) {
- sprintf(msg, "%s(): unable to open file [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return -3;
- }
- nrows = G_window_rows();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- if (G_get_map_row(map_fd, buffer, row) < 0) {
- G_free(buffer);
- G_close_cell(map_fd);
- sprintf(msg, "%s(): unable to read file [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return -2;
- }
- if (segment_put_row(&(cseg->seg), buffer, row) < 0) {
- G_free(buffer);
- G_close_cell(map_fd);
- sprintf(msg, "%s(): unable to segment put row for [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return (-1);
- }
- }
-
- G_close_cell(map_fd);
- G_free(buffer);
-
- cseg->name = G_store(map_name);
- cseg->mapset = G_store(mapset);
-
- return 0;
-}
Deleted: grass/branches/develbranch_6/raster/r.surf.contour/cseg_write.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/cseg_write.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/cseg_write.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,36 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-static char *me = "cseg_write_cell";
-
-int cseg_write_cellfile(CSEG * cseg, char *map_name)
-{
- int map_fd;
- int row, nrows;
- char msg[100];
- CELL *buffer;
-
- map_fd = G_open_cell_new(map_name);
- if (map_fd < 0) {
- sprintf(msg, "%s(): unable to open new map layer [%s]", me, map_name);
- G_warning(msg);
- return -1;
- }
- nrows = G_window_rows();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- segment_get_row(&(cseg->seg), buffer, row);
- if (G_put_raster_row(map_fd, buffer, CELL_TYPE) < 0) {
- G_free(buffer);
- G_unopen_cell(map_fd);
- sprintf(msg,
- "%s(): unable to write new map layer [%s], row %d",
- me, map_name, row);
- G_warning(msg);
- return -2;
- }
- }
- G_free(buffer);
- G_close_cell(map_fd);
- return 0;
-}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_close.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_close.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_close.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_close.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,19 @@
+#include <grass/gis.h>
+#include <unistd.h>
+#include "seg.h"
+
+int dseg_close(DSEG * dseg)
+{
+ segment_release(&(dseg->seg));
+ close(dseg->fd);
+ unlink(dseg->filename);
+ if (dseg->name) {
+ G_free(dseg->name);
+ dseg->name = NULL;
+ }
+ if (dseg->mapset) {
+ G_free(dseg->mapset);
+ dseg->mapset = NULL;
+ }
+ return 0;
+}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_get.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_get.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_get.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_get.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,11 @@
+#include <grass/gis.h>
+#include "seg.h"
+
+int dseg_get(DSEG * dseg, int row, int col, DCELL * value)
+{
+ if (segment_get(&(dseg->seg), value, row, col) < 0) {
+ G_warning("dseg_get(): could not read segment file");
+ return -1;
+ }
+ return 0;
+}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_open.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_open.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_open.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_open.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,60 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <grass/gis.h>
+#include "seg.h"
+
+int dseg_open(DSEG * dseg, int srows, int scols, int nsegs_in_memory)
+{
+ char *filename;
+ int errflag;
+ int fd;
+
+ dseg->filename = NULL;
+ dseg->fd = -1;
+ dseg->name = NULL;
+ dseg->mapset = NULL;
+
+ filename = G_tempfile();
+ if (-1 == (fd = creat(filename, 0666))) {
+ G_warning("dseg_open(): unable to create segment file");
+ return -2;
+ }
+ if (0 >
+ (errflag =
+ segment_format(fd, G_window_rows(), G_window_cols(), srows, scols,
+ sizeof(DCELL)))) {
+ close(fd);
+ unlink(filename);
+ if (errflag == -1) {
+ G_warning("dseg_open(): could not write segment file");
+ return -1;
+ }
+ else {
+ G_warning("dseg_open(): illegal configuration parameter(s)");
+ return -3;
+ }
+ }
+ close(fd);
+ if (-1 == (fd = open(filename, 2))) {
+ unlink(filename);
+ G_warning("dseg_open(): unable to re-open segment file");
+ return -4;
+ }
+ if (0 > (errflag = segment_init(&(dseg->seg), fd, nsegs_in_memory))) {
+ close(fd);
+ unlink(filename);
+ if (errflag == -1) {
+ G_warning("cseg_open(): could not read segment file");
+ return -5;
+ }
+ else {
+ G_warning("cseg_open(): out of memory");
+ return -6;
+ }
+ }
+ dseg->filename = filename;
+ dseg->fd = fd;
+ return 0;
+}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_put.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_put.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_put.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_put.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,11 @@
+#include <grass/gis.h>
+#include "seg.h"
+
+int dseg_put(DSEG * dseg, int row, int col, DCELL value)
+{
+ if (segment_put(&(dseg->seg), &value, row, col) < 0) {
+ G_warning("dseg_put(): could not write segment file");
+ return -1;
+ }
+ return 0;
+}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_read.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_read.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_read.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_read.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,51 @@
+#include <grass/gis.h>
+#include <unistd.h>
+#include "seg.h"
+
+static char *me = "dseg_read_cell";
+
+int dseg_read_cell(DSEG * dseg, char *map_name, char *mapset)
+{
+ int row, nrows;
+ int map_fd;
+ char msg[100];
+ DCELL *buffer;
+
+ dseg->name = NULL;
+ dseg->mapset = NULL;
+
+ if ((map_fd = G_open_cell_old(map_name, mapset)) < 0) {
+ sprintf(msg, "%s(): unable to open file [%s] in [%s]",
+ me, map_name, mapset);
+ G_warning(msg);
+ return -3;
+ }
+ nrows = G_window_rows();
+ buffer = G_allocate_d_raster_buf();
+ for (row = 0; row < nrows; row++) {
+ if (G_get_d_raster_row(map_fd, buffer, row) < 0) {
+ G_free(buffer);
+ G_close_cell(map_fd);
+ sprintf(msg, "%s(): unable to read file [%s] in [%s]",
+ me, map_name, mapset);
+ G_warning(msg);
+ return -2;
+ }
+ if (segment_put_row(&(dseg->seg), buffer, row) < 0) {
+ G_free(buffer);
+ G_close_cell(map_fd);
+ sprintf(msg, "%s(): unable to segment put row for [%s] in [%s]",
+ me, map_name, mapset);
+ G_warning(msg);
+ return (-1);
+ }
+ }
+
+ G_close_cell(map_fd);
+ G_free(buffer);
+
+ dseg->name = G_store(map_name);
+ dseg->mapset = G_store(mapset);
+
+ return 0;
+}
Copied: grass/branches/develbranch_6/raster/r.surf.contour/dseg_write.c (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg_write.c)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/dseg_write.c (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/dseg_write.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,36 @@
+#include <grass/gis.h>
+#include "seg.h"
+
+static char *me = "dseg_write_cell";
+
+int dseg_write_cellfile(DSEG * dseg, char *map_name)
+{
+ int map_fd;
+ int row, nrows;
+ char msg[100];
+ DCELL *buffer;
+
+ map_fd = G_open_raster_new(map_name, DCELL_TYPE);
+ if (map_fd < 0) {
+ sprintf(msg, "%s(): unable to open new map layer [%s]", me, map_name);
+ G_warning(msg);
+ return -1;
+ }
+ nrows = G_window_rows();
+ buffer = G_allocate_d_raster_buf();
+ for (row = 0; row < nrows; row++) {
+ segment_get_row(&(dseg->seg), buffer, row);
+ if (G_put_raster_row(map_fd, buffer, DCELL_TYPE) < 0) {
+ G_free(buffer);
+ G_unopen_cell(map_fd);
+ sprintf(msg,
+ "%s(): unable to write new map layer [%s], row %d",
+ me, map_name, row);
+ G_warning(msg);
+ return -2;
+ }
+ }
+ G_free(buffer);
+ G_close_cell(map_fd);
+ return 0;
+}
Modified: grass/branches/develbranch_6/raster/r.surf.contour/find_con.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/find_con.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/find_con.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -1,16 +1,17 @@
#include <math.h>
#include "contour.h"
-int find_con_slow(int r, int c, double *d1, double *d2, CELL * con1,
- CELL * con2)
+int find_con_slow(int r, int c, double *d1, double *d2, DCELL * con1,
+ DCELL * con2)
{
int ct, low_ct, node_ct;
int rr, cc, dor, doc;
double dd, shortest;
- CELL value;
+ DCELL value;
+ char mask_value;
- *con1 = 0;
- *con2 = 0;
+ G_set_d_null_value(con1, 1);
+ G_set_d_null_value(con2, 1);
*d1 = *d2 = 1.0;
shortest = nrows * ncols;
for (rr = minr; rr <= maxr; rr++) {
@@ -43,13 +44,13 @@
cc = zero[ct].c;
dor = ABS(rr - r);
doc = ABS(cc - c);
- bseg_get(&bmask, &value, rr, cc);
- if (!value && rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
+ bseg_get(&bmask, &mask_value, rr, cc);
+ if (!mask_value && rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
&& zero[ct].d < shortest) {
- cseg_get(&con, rr, cc, &value);
- if (value == 0)
+ dseg_get(&con, rr, cc, &value);
+ if (G_is_d_null_value(&value))
zero = addpts_slow(zero, r, c, rr, cc, &node_ct);
- else if (*con1 == 0) {
+ else if (G_is_d_null_value(con1)) {
*con1 = value;
*d1 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
shortest = *d1 * 2.0 * i_val_l_f;
@@ -61,7 +62,7 @@
shortest = dd * 2.0 * i_val_l_f;
}
}
- else if (*con2 == 0) {
+ else if (G_is_d_null_value(con2)) {
*con2 = value;
*d2 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
shortest = *d2;
@@ -74,15 +75,15 @@
}
}
-int find_con(int r, int c, double *d1, double *d2, CELL * con1, CELL * con2)
+int find_con(int r, int c, double *d1, double *d2, DCELL * con1, DCELL * con2)
{
int ct, low_ct, node_ct;
int rr, cc, dor, doc;
double dd, shortest;
- CELL value;
+ DCELL value;
- *con1 = 0;
- *con2 = 0;
+ G_set_d_null_value(con1, 1);
+ G_set_d_null_value(con2, 1);
*d1 = *d2 = 1.0;
shortest = nrows * ncols;
for (rr = minr; rr <= maxr; rr++) {
@@ -114,10 +115,10 @@
doc = ABS(cc - c);
if (rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
&& zero[ct].d < shortest && !flag_get(mask, rr, cc)) {
- cseg_get(&con, rr, cc, &value);
- if (value == 0)
+ dseg_get(&con, rr, cc, &value);
+ if (G_is_d_null_value(&value))
zero = addpts(zero, r, c, rr, cc, &node_ct);
- else if (*con1 == 0) {
+ else if (G_is_d_null_value(con1)) {
*con1 = value;
*d1 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
shortest = *d1 * 2.0 * i_val_l_f;
@@ -129,7 +130,7 @@
shortest = dd * 2.0 * i_val_l_f;
}
}
- else if (*con2 == 0) {
+ else if (G_is_d_null_value(con2)) {
*con2 = value;
*d2 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
shortest = *d2;
Modified: grass/branches/develbranch_6/raster/r.surf.contour/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/main.c 2010-09-21 06:54:54 UTC (rev 43551)
+++ grass/branches/develbranch_6/raster/r.surf.contour/main.c 2010-09-21 07:15:48 UTC (rev 43552)
@@ -32,13 +32,14 @@
int main(int argc, char *argv[])
{
int r, c;
- CELL con1, con2;
+ DCELL con1, con2;
double d1, d2;
- CELL *alt_row;
+ DCELL *alt_row;
char *con_name, *alt_name, *con_mapset;
int file_fd;
- int fast_mode;
- CELL value;
+ int fast_mode, n_segments, s_size;
+ DCELL value;
+ char mask_value;
struct History history;
struct GModule *module;
struct Flag *flag1, *flag_slow;
@@ -97,33 +98,42 @@
nrows = G_window_rows();
ncols = G_window_cols();
i_val_l_f = nrows + ncols;
- cseg_open(&con, 512, 512, 16);
- cseg_read_cell(&con, con_name, con_mapset);
- alt_row = (CELL *) G_malloc(ncols * sizeof(CELL));
+ s_size = 128;
+ n_segments = nrows / s_size + (nrows % s_size > 0) * s_size +
+ ncols / s_size + (ncols % s_size > 0) * s_size;
+ /* limit memory consumption to about 100 MB */
+ if (n_segments > 800)
+ n_segments = 800;
+ G_debug(0, "n_segments: %d", n_segments);
+ dseg_open(&con, s_size, s_size, n_segments);
+ dseg_read_cell(&con, con_name, con_mapset);
+ alt_row = (DCELL *) G_malloc(ncols * sizeof(DCELL));
if (fast_mode) {
seen = flag_create(nrows, ncols);
mask = flag_create(nrows, ncols);
}
else {
- bseg_open(&bseen, 64, 64, 16);
- bseg_open(&bmask, 64, 64, 16);
+ bseg_open(&bseen, s_size, s_size, n_segments);
+ bseg_open(&bmask, s_size, s_size, n_segments);
}
if (NULL != G_find_file("cell", "MASK", G_mapset())) {
if ((file_fd = G_open_cell_old("MASK", G_mapset())) < 0)
G_fatal_error("Unable to open MASK");
if (fast_mode) {
for (r = 0; r < nrows; r++) {
- G_get_map_row_nomask(file_fd, alt_row, r);
+ G_get_d_raster_row_nomask(file_fd, alt_row, r);
for (c = 0; c < ncols; c++)
- if (!alt_row[c])
+ if (G_is_d_null_value(&(alt_row[c])) || alt_row[c] == 0)
FLAG_SET(mask, r, c);
+ else
+ FLAG_UNSET(mask, r, c);
}
}
else {
for (r = 0; r < nrows; r++) {
- G_get_map_row_nomask(file_fd, alt_row, r);
+ G_get_d_raster_row_nomask(file_fd, alt_row, r);
for (c = 0; c < ncols; c++)
- if (!alt_row[c])
+ if (G_is_d_null_value(&(alt_row[c])) || alt_row[c] == 0)
bseg_put(&bmask, &off, r, c);
}
}
@@ -134,23 +144,24 @@
maxc = ncols - 1;
maxr = nrows - 1;
array_size = INIT_AR;
- file_fd = G_open_cell_new(alt_name);
+ file_fd = G_open_raster_new(alt_name, DCELL_TYPE);
if (!file_fd)
G_fatal_error("Unable to open output map");
for (r = 0; r < nrows; r++) {
G_percent(r, nrows, 1);
+ G_set_d_null_value(alt_row, ncols);
for (c = 0; c < ncols; c++) {
if (fast_mode) {
if (FLAG_GET(mask, r, c))
continue;
}
else {
- bseg_get(&bmask, &value, r, c);
- if (value)
+ bseg_get(&bmask, &mask_value, r, c);
+ if (mask_value)
continue;
}
- cseg_get(&con, r, c, &value);
- if (value != 0) {
+ dseg_get(&con, r, c, &value);
+ if (!G_is_d_null_value(&value)) {
alt_row[c] = value;
continue;
}
@@ -159,15 +170,15 @@
else
find_con_slow(r, c, &d1, &d2, &con1, &con2);
if (con2 > 0)
- alt_row[c] = (CELL) (d2 * con1 / (d1 + d2) +
- d1 * con2 / (d1 + d2) + 0.5);
+ alt_row[c] = d2 * con1 / (d1 + d2) +
+ d1 * con2 / (d1 + d2);
else
alt_row[c] = con1;
}
- G_put_raster_row(file_fd, alt_row, CELL_TYPE);
+ G_put_raster_row(file_fd, alt_row, DCELL_TYPE);
}
G_percent(r, nrows, 1);
- cseg_close(&con);
+ dseg_close(&con);
if (fast_mode) {
flag_destroy(seen);
flag_destroy(mask);
Copied: grass/branches/develbranch_6/raster/r.surf.contour/seg.h (from rev 43540, grass/branches/develbranch_6/raster/r.surf.contour/cseg.h)
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.contour/seg.h (rev 0)
+++ grass/branches/develbranch_6/raster/r.surf.contour/seg.h 2010-09-21 07:15:48 UTC (rev 43552)
@@ -0,0 +1,55 @@
+#include <grass/segment.h>
+
+#define DSEG struct _d_s_e_g_
+DSEG {
+ SEGMENT seg; /* segment structure */
+ int fd; /* fd for reading/writing segment file */
+ char *filename; /* name of segment file */
+ char *name; /* raster map read into segment file */
+ char *mapset;
+};
+
+#define BSEG struct _b_s_e_g_
+BSEG {
+ SEGMENT seg; /* segment structure */
+ int fd; /* fd for reading/writing segment file */
+ char *filename; /* name of segment file */
+ char *name; /* raster map read into segment file */
+ char *mapset;
+};
+
+/* bseg_close.c */
+int bseg_close(BSEG *);
+
+/* bseg_get.c */
+int bseg_get(BSEG *, char *, int, int);
+
+/* bseg_open.c */
+int bseg_open(BSEG *, int, int, int);
+
+/* bseg_put.c */
+int bseg_put(BSEG *, char *, int, int);
+
+/* bseg_read.c */
+int bseg_read_cell(BSEG *, char *, char *);
+
+/* bseg_write.c */
+int bseg_write_cellfile(BSEG *, char *);
+
+/* dseg_close.c */
+int dseg_close(DSEG *);
+
+/* dseg_get.c */
+int dseg_get(DSEG *, int, int, DCELL *);
+
+/* dseg_open.c */
+int dseg_open(DSEG *, int, int, int);
+
+/* dseg_put.c */
+int dseg_put(DSEG *, int, int, DCELL);
+
+/* dseg_read.c */
+int dseg_read_cell(DSEG *, char *, char *);
+
+/* dseg_write.c */
+int dseg_write_cellfile(DSEG *, char *);
More information about the grass-commit
mailing list