~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to raster/r.terraflow/grass2str.h

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#define _gras2str_H
22
22
 
23
23
#include <grass/iostream/ami.h>
 
24
#include <grass/glocale.h>
24
25
#include "option.h"
25
26
#include "types.h"
26
27
#include "common.h"
48
49
  { 
49
50
    char * foo;
50
51
    str->name(&foo); 
51
 
    *stats << "reading raster map " << cellname 
52
 
                   << "to stream " << foo << endl;
53
 
    if (opt->verbose) 
54
 
      fprintf(stderr, "reading data from %s to stream %s: ", cellname, foo);
 
52
    *stats << "Reading raster map <" << cellname 
 
53
                   << "> to stream <" << foo << ">." << endl;
 
54
    G_verbose_message(_("Reading data from <%s> to stream <%s>"), cellname, foo);
55
55
  }
56
 
  
 
56
 
57
57
  char *mapset;
58
58
  mapset = G_find_cell (cellname, "");
59
59
  if (mapset == NULL)
60
 
    G_fatal_error (_("Raster map <%s> not found"), cellname);
 
60
    G_fatal_error(_("Raster map <%s> not found"), cellname);
61
61
  
62
62
  /* open map */
63
63
  int infd;
64
64
  if ( (infd = G_open_cell_old (cellname, mapset)) < 0)
65
 
    G_fatal_error (_("Unable to open raster map <%s>"), cellname);
 
65
    G_fatal_error(_("Unable to open raster map <%s>"), cellname);
66
66
  
67
67
  /* determine map type (CELL/FCELL/DCELL) */
68
68
  RASTER_MAP_TYPE data_type;
82
82
        
83
83
        /* read input map */
84
84
    if (G_get_raster_row (infd, inrast, i, data_type) < 0)
85
 
      G_fatal_error (_("Unable to read raster map <%s>, row %d"),cellname, i);
 
85
      G_fatal_error(_("Unable to read raster map <%s>, row %d"),cellname, i);
86
86
  
87
87
        for (int j=0; j<ncols; j++) {
88
88
 
119
119
          } else {
120
120
                /* check range */
121
121
                if ((d > (DCELL)T_max_value) || (d < (DCELL)T_min_value)) {
122
 
                  fprintf(stderr, "reading raster map %s at (i=%d,j=%d) value=%.1f\n",
123
 
                                  cellname, i, j, d);
124
 
                  G_fatal_error("value out of range.");
 
122
                  G_fatal_error("Value out of range, reading raster map <%s> "
 
123
                                "at (i=%d, j=%d) value=%.1f",
 
124
                                cellname, i, j, d);
125
125
                }
126
126
          }  
127
127
          /* write x to stream */
140
140
  G_free(inrast);
141
141
  /* close map files */
142
142
  G_close_cell (infd);
143
 
  
 
143
 
 
144
  G_debug(3, "nrows=%d   ncols=%d    stream_len()=%d", nrows, ncols,
 
145
                str->stream_len());  
144
146
  assert(nrows * ncols == str->stream_len());
145
147
  rt_stop(rt);
146
148
  stats->recordTime("reading raster map", rt);
168
170
  {
169
171
    char * foo;
170
172
    str->name(&foo); 
171
 
    *stats << "writing stream " << foo << " to raster map  " << cellname << "\n";
172
 
    fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
 
173
    *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">.\n";
 
174
    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
173
175
  }
174
176
 
175
177
  /* open output raster map */
176
178
  int outfd;
177
 
  if ( (outfd = G_open_raster_new (cellname, mtype)) < 0) {
 
179
  if ( (outfd = G_open_raster_new (cellname, mtype)) < 0)
178
180
    G_fatal_error (_("Unable to create raster map <%s>"), cellname);
179
 
  }
 
181
 
180
182
  
181
183
  /* Allocate output buffer */
182
184
  unsigned char *outrast;
191
193
          ae = str->read_item(&elt);
192
194
          if (ae != AMI_ERROR_NO_ERROR) {
193
195
                str->sprint();
194
 
                fprintf(stderr, "reading stream failed at (%d,%d)\n", i,j);
195
 
                G_fatal_error("stream2cell failed");
 
196
                G_fatal_error(_("stream2cell: Reading stream failed at (%d,%d)"),
 
197
                                i, j);
196
198
          }
197
199
 
198
200
          /* WRITE VALUE */
212
214
 
213
215
  } /* for j*/
214
216
  if (G_put_raster_row (outfd, outrast, mtype) < 0)
215
 
    G_fatal_error ("Cannot write to <%s>",cellname);
 
217
    G_fatal_error(_("Cannot write to <%s>"), cellname);
216
218
 
217
219
  G_percent(i, nrows, 2);
218
220
  }/* for i */
253
255
  {
254
256
    char * foo;
255
257
    str->name(&foo); 
256
 
    *stats << "writing stream " << foo << "cellfile  " << cellname << endl;
257
 
    fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
 
258
    *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
 
259
    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
258
260
  }
259
261
  
260
262
  /* open output raster map */
261
263
  int outfd;
262
264
  if ( (outfd = G_open_raster_new (cellname, CELL_TYPE)) < 0) {
263
 
    G_fatal_error ("Could not open <%s>", cellname);
 
265
    G_fatal_error(_("Could not open <%s>"), cellname);
264
266
  }
265
267
  
266
268
  /* Allocate output buffer */
291
293
      
292
294
    } /* for j*/
293
295
    if (G_put_raster_row (outfd, outrast, CELL_TYPE) < 0)
294
 
      G_fatal_error ("Cannot write to <%s>",cellname);
 
296
      G_fatal_error(_("Cannot write to <%s>"), cellname);
295
297
 
296
298
    G_percent(i, nrows, 2);
297
299
  }/* for i */
327
329
  {
328
330
    char * foo;
329
331
    str->name(&foo); 
330
 
    *stats << "writing stream " << foo << "cellfile  " << cellname << endl;
331
 
    fprintf(stderr, "writing stream %s to raster map %s: ", foo, cellname);
 
332
    *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
 
333
    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
332
334
  }
333
335
  
334
336
  /* open output raster map */
335
337
  int outfd;
336
338
  if ( (outfd = G_open_raster_new (cellname, FCELL_TYPE)) < 0) {
337
 
    G_fatal_error ("Could not open <%s>", cellname);
 
339
    G_fatal_error(_("Could not open <%s>"), cellname);
338
340
  }
339
341
  
340
342
  /* Allocate output buffer */
365
367
      
366
368
    } /* for j*/
367
369
    if (G_put_raster_row (outfd, outrast, FCELL_TYPE) < 0)
368
 
      G_fatal_error ("Cannot write to <%s>",cellname);
 
370
      G_fatal_error(_("Cannot write to <%s>"), cellname);
369
371
 
370
372
    G_percent(i, nrows, 2);
371
373
  }/* for i */
408
410
  assert(str);
409
411
#ifndef   OUTPUT_TCI 
410
412
  /* this function should be used only if tci is wanted as output */
411
 
  fprintf(stderr, "use this function only if tci is wanted as output\n");
 
413
  G_warning("Use this function only if tci is wanted as output");
412
414
  exit(1);
413
415
#else 
414
416
  rt_start(rt); 
417
419
  {
418
420
    char * foo;
419
421
    str->name(&foo); 
420
 
    *stats << "writing stream " << foo << "to raster maps  "
421
 
           << cellname1 << ", " << cellname2 << endl;
422
 
    fprintf(stderr, "writing stream %s to raster maps %s, %s: ", 
423
 
            foo, cellname1, cellname2);
 
422
    *stats << "Writing stream <" << foo << "> to raster maps <"
 
423
           << cellname1 << "> and <" << cellname2 << ">." << endl;
 
424
    G_verbose_message(_("Writing stream <%s> to raster maps <%s> and <%s>"), 
 
425
                foo, cellname1, cellname2);
424
426
  }
425
427
 
426
428
  /* open  raster maps */
427
429
  int fd1;
428
430
  if ( (fd1 = G_open_raster_new (cellname1, FCELL_TYPE)) < 0) {
429
 
    G_fatal_error ("Could not open <%s>", cellname1);
 
431
    G_fatal_error (_("Could not open <%s>"), cellname1);
430
432
  }
431
433
  int fd2;
432
434
  if ( (fd2 = G_open_raster_new (cellname2, FCELL_TYPE)) < 0) {
433
 
    G_fatal_error ("Could not open <%s>", cellname2);
 
435
    G_fatal_error (_("Could not open <%s>"), cellname2);
434
436
  }
435
437
  
436
438
 
474
476
    } /* for j*/
475
477
 
476
478
    if (G_put_raster_row (fd1, rast1, FCELL_TYPE) < 0)
477
 
      G_fatal_error ("Cannot write to <%s>", cellname1);
 
479
      G_fatal_error(_("Cannot write to <%s>"), cellname1);
478
480
    if (G_put_raster_row (fd2, rast2, FCELL_TYPE) < 0)
479
 
      G_fatal_error ("Cannot write to <%s>", cellname2);
 
481
      G_fatal_error(_("Cannot write to <%s>"), cellname2);
480
482
    
481
483
    G_percent(i, nrows, 2);
482
484