|
@@ -21,6 +21,7 @@
|
|
#define _gras2str_H
|
|
#define _gras2str_H
|
|
|
|
|
|
#include <grass/iostream/ami.h>
|
|
#include <grass/iostream/ami.h>
|
|
|
|
+#include <grass/glocale.h>
|
|
#include "option.h"
|
|
#include "option.h"
|
|
#include "types.h"
|
|
#include "types.h"
|
|
#include "common.h"
|
|
#include "common.h"
|
|
@@ -48,21 +49,20 @@ cell2stream(char* cellname, elevation_type T_max_value, long* nodata_count) {
|
|
{
|
|
{
|
|
char * foo;
|
|
char * foo;
|
|
str->name(&foo);
|
|
str->name(&foo);
|
|
- *stats << "reading raster map " << cellname
|
|
|
|
- << "to stream " << foo << endl;
|
|
|
|
- if (opt->verbose)
|
|
|
|
- fprintf(stderr, "reading data from %s to stream %s: ", cellname, foo);
|
|
|
|
|
|
+ *stats << "Reading raster map <" << cellname
|
|
|
|
+ << "> to stream <" << foo << ">." << endl;
|
|
|
|
+ G_verbose_message(_("Reading data from <%s> to stream <%s>"), cellname, foo);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
const char *mapset;
|
|
const char *mapset;
|
|
mapset = G_find_raster (cellname, "");
|
|
mapset = G_find_raster (cellname, "");
|
|
if (mapset == NULL)
|
|
if (mapset == NULL)
|
|
- G_fatal_error (_("Raster map <%s> not found"), cellname);
|
|
|
|
|
|
+ G_fatal_error(_("Raster map <%s> not found"), cellname);
|
|
|
|
|
|
/* open map */
|
|
/* open map */
|
|
int infd;
|
|
int infd;
|
|
if ( (infd = Rast_open_old (cellname, mapset)) < 0)
|
|
if ( (infd = Rast_open_old (cellname, mapset)) < 0)
|
|
- G_fatal_error (_("Unable to open raster map <%s>"), cellname);
|
|
|
|
|
|
+ G_fatal_error(_("Unable to open raster map <%s>"), cellname);
|
|
|
|
|
|
/* determine map type (CELL/FCELL/DCELL) */
|
|
/* determine map type (CELL/FCELL/DCELL) */
|
|
RASTER_MAP_TYPE data_type;
|
|
RASTER_MAP_TYPE data_type;
|
|
@@ -79,10 +79,10 @@ cell2stream(char* cellname, elevation_type T_max_value, long* nodata_count) {
|
|
int isnull = 0;
|
|
int isnull = 0;
|
|
|
|
|
|
for (int i = 0; i< nrows; i++) {
|
|
for (int i = 0; i< nrows; i++) {
|
|
-
|
|
|
|
|
|
+
|
|
/* read input map */
|
|
/* read input map */
|
|
- Rast_get_row (infd, inrast, i, data_type);
|
|
|
|
-
|
|
|
|
|
|
+ Rast_get_row (infd, inrast, i, data_type);
|
|
|
|
+
|
|
for (int j=0; j<ncols; j++) {
|
|
for (int j=0; j<ncols; j++) {
|
|
|
|
|
|
switch (data_type) {
|
|
switch (data_type) {
|
|
@@ -118,9 +118,9 @@ cell2stream(char* cellname, elevation_type T_max_value, long* nodata_count) {
|
|
} else {
|
|
} else {
|
|
/* check range */
|
|
/* check range */
|
|
if ((d > (DCELL)T_max_value) || (d < (DCELL)T_min_value)) {
|
|
if ((d > (DCELL)T_max_value) || (d < (DCELL)T_min_value)) {
|
|
- fprintf(stderr, "reading raster map %s at (i=%d,j=%d) value=%.1f\n",
|
|
|
|
- cellname, i, j, d);
|
|
|
|
- G_fatal_error("value out of range.");
|
|
|
|
|
|
+ G_fatal_error("Value out of range, reading raster map <%s> "
|
|
|
|
+ "at (i=%d, j=%d) value=%.1f",
|
|
|
|
+ cellname, i, j, d);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/* write x to stream */
|
|
/* write x to stream */
|
|
@@ -139,7 +139,9 @@ cell2stream(char* cellname, elevation_type T_max_value, long* nodata_count) {
|
|
G_free(inrast);
|
|
G_free(inrast);
|
|
/* close map files */
|
|
/* close map files */
|
|
Rast_close (infd);
|
|
Rast_close (infd);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ G_debug(3, "nrows=%d ncols=%d stream_len()=%d", nrows, ncols,
|
|
|
|
+ str->stream_len());
|
|
assert(nrows * ncols == str->stream_len());
|
|
assert(nrows * ncols == str->stream_len());
|
|
rt_stop(rt);
|
|
rt_stop(rt);
|
|
stats->recordTime("reading raster map", rt);
|
|
stats->recordTime("reading raster map", rt);
|
|
@@ -167,15 +169,13 @@ stream2_CELL(AMI_STREAM<T>* str, dimension_type nrows, dimension_type ncols,
|
|
{
|
|
{
|
|
char * foo;
|
|
char * foo;
|
|
str->name(&foo);
|
|
str->name(&foo);
|
|
- *stats << "writing stream " << foo << " to raster map " << cellname << "\n";
|
|
|
|
- fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
|
|
|
|
|
|
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">.\n";
|
|
|
|
+ G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
|
|
}
|
|
}
|
|
|
|
|
|
/* open output raster map */
|
|
/* open output raster map */
|
|
int outfd;
|
|
int outfd;
|
|
if ( (outfd = Rast_open_new (cellname, mtype)) < 0) {
|
|
if ( (outfd = Rast_open_new (cellname, mtype)) < 0) {
|
|
- G_fatal_error (_("Unable to create raster map <%s>"), cellname);
|
|
|
|
- }
|
|
|
|
|
|
|
|
/* Allocate output buffer */
|
|
/* Allocate output buffer */
|
|
unsigned char *outrast;
|
|
unsigned char *outrast;
|
|
@@ -190,8 +190,8 @@ stream2_CELL(AMI_STREAM<T>* str, dimension_type nrows, dimension_type ncols,
|
|
ae = str->read_item(&elt);
|
|
ae = str->read_item(&elt);
|
|
if (ae != AMI_ERROR_NO_ERROR) {
|
|
if (ae != AMI_ERROR_NO_ERROR) {
|
|
str->sprint();
|
|
str->sprint();
|
|
- fprintf(stderr, "reading stream failed at (%d,%d)\n", i,j);
|
|
|
|
- G_fatal_error("stream2cell failed");
|
|
|
|
|
|
+ G_fatal_error(_("stream2cell: Reading stream failed at (%d,%d)"),
|
|
|
|
+ i, j);
|
|
}
|
|
}
|
|
|
|
|
|
/* WRITE VALUE */
|
|
/* WRITE VALUE */
|
|
@@ -251,14 +251,14 @@ stream2_CELL(AMI_STREAM<T> *str, dimension_type nrows, dimension_type ncols,
|
|
{
|
|
{
|
|
char * foo;
|
|
char * foo;
|
|
str->name(&foo);
|
|
str->name(&foo);
|
|
- *stats << "writing stream " << foo << "cellfile " << cellname << endl;
|
|
|
|
- fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
|
|
|
|
|
|
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
|
|
|
|
+ G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
|
|
}
|
|
}
|
|
|
|
|
|
/* open output raster map */
|
|
/* open output raster map */
|
|
int outfd;
|
|
int outfd;
|
|
if ( (outfd = Rast_open_new (cellname, CELL_TYPE)) < 0) {
|
|
if ( (outfd = Rast_open_new (cellname, CELL_TYPE)) < 0) {
|
|
- G_fatal_error ("Could not open <%s>", cellname);
|
|
|
|
|
|
+ G_fatal_error(_("Could not open <%s>"), cellname);
|
|
}
|
|
}
|
|
|
|
|
|
/* Allocate output buffer */
|
|
/* Allocate output buffer */
|
|
@@ -324,14 +324,14 @@ stream2_FCELL(AMI_STREAM<T> *str, dimension_type nrows, dimension_type ncols,
|
|
{
|
|
{
|
|
char * foo;
|
|
char * foo;
|
|
str->name(&foo);
|
|
str->name(&foo);
|
|
- *stats << "writing stream " << foo << "cellfile " << cellname << endl;
|
|
|
|
- fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
|
|
|
|
|
|
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
|
|
|
|
+ G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
|
|
}
|
|
}
|
|
|
|
|
|
/* open output raster map */
|
|
/* open output raster map */
|
|
int outfd;
|
|
int outfd;
|
|
if ( (outfd = Rast_open_new (cellname, FCELL_TYPE)) < 0) {
|
|
if ( (outfd = Rast_open_new (cellname, FCELL_TYPE)) < 0) {
|
|
- G_fatal_error ("Could not open <%s>", cellname);
|
|
|
|
|
|
+ G_fatal_error(_("Could not open <%s>"), cellname);
|
|
}
|
|
}
|
|
|
|
|
|
/* Allocate output buffer */
|
|
/* Allocate output buffer */
|
|
@@ -404,7 +404,7 @@ stream2_FCELL(AMI_STREAM<T>* str, dimension_type nrows, dimension_type ncols,
|
|
assert(str);
|
|
assert(str);
|
|
#ifndef OUTPUT_TCI
|
|
#ifndef OUTPUT_TCI
|
|
/* this function should be used only if tci is wanted as output */
|
|
/* this function should be used only if tci is wanted as output */
|
|
- fprintf(stderr, "use this function only if tci is wanted as output\n");
|
|
|
|
|
|
+ G_warning("Use this function only if tci is wanted as output");
|
|
exit(1);
|
|
exit(1);
|
|
#else
|
|
#else
|
|
rt_start(rt);
|
|
rt_start(rt);
|
|
@@ -413,20 +413,20 @@ stream2_FCELL(AMI_STREAM<T>* str, dimension_type nrows, dimension_type ncols,
|
|
{
|
|
{
|
|
char * foo;
|
|
char * foo;
|
|
str->name(&foo);
|
|
str->name(&foo);
|
|
- *stats << "writing stream " << foo << "to raster maps "
|
|
|
|
- << cellname1 << ", " << cellname2 << endl;
|
|
|
|
- fprintf(stderr, "writing stream %s to raster maps %s, %s: ",
|
|
|
|
- foo, cellname1, cellname2);
|
|
|
|
|
|
+ *stats << "Writing stream <" << foo << "> to raster maps <"
|
|
|
|
+ << cellname1 << "> and <" << cellname2 << ">." << endl;
|
|
|
|
+ G_verbose_message(_("Writing stream <%s> to raster maps <%s> and <%s>"),
|
|
|
|
+ foo, cellname1, cellname2);
|
|
}
|
|
}
|
|
|
|
|
|
/* open raster maps */
|
|
/* open raster maps */
|
|
int fd1;
|
|
int fd1;
|
|
if ( (fd1 = Rast_open_new (cellname1, FCELL_TYPE)) < 0) {
|
|
if ( (fd1 = Rast_open_new (cellname1, FCELL_TYPE)) < 0) {
|
|
- G_fatal_error ("Could not open <%s>", cellname1);
|
|
|
|
|
|
+ G_fatal_error(_("Could not open <%s>"), cellname1);
|
|
}
|
|
}
|
|
int fd2;
|
|
int fd2;
|
|
if ( (fd2 = Rast_open_new (cellname2, FCELL_TYPE)) < 0) {
|
|
if ( (fd2 = Rast_open_new (cellname2, FCELL_TYPE)) < 0) {
|
|
- G_fatal_error ("Could not open <%s>", cellname2);
|
|
|
|
|
|
+ G_fatal_error(_("Could not open <%s>"), cellname2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|