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

« back to all changes in this revision

Viewing changes to raster/r.surf.contour/dseg_write.c

  • 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:
 
1
#include <grass/gis.h>
 
2
#include "seg.h"
 
3
 
 
4
static char *me = "dseg_write_cell";
 
5
 
 
6
int dseg_write_cellfile(DSEG * dseg, char *map_name)
 
7
{
 
8
    int map_fd;
 
9
    int row, nrows;
 
10
    char msg[100];
 
11
    DCELL *buffer;
 
12
 
 
13
    map_fd = G_open_raster_new(map_name, DCELL_TYPE);
 
14
    if (map_fd < 0) {
 
15
        sprintf(msg, "%s(): unable to open new map layer [%s]", me, map_name);
 
16
        G_warning(msg);
 
17
        return -1;
 
18
    }
 
19
    nrows = G_window_rows();
 
20
    buffer = G_allocate_d_raster_buf();
 
21
    for (row = 0; row < nrows; row++) {
 
22
        segment_get_row(&(dseg->seg), buffer, row);
 
23
        if (G_put_raster_row(map_fd, buffer, DCELL_TYPE) < 0) {
 
24
            G_free(buffer);
 
25
            G_unopen_cell(map_fd);
 
26
            sprintf(msg,
 
27
                    "%s(): unable to write new map layer [%s], row %d",
 
28
                    me, map_name, row);
 
29
            G_warning(msg);
 
30
            return -2;
 
31
        }
 
32
    }
 
33
    G_free(buffer);
 
34
    G_close_cell(map_fd);
 
35
    return 0;
 
36
}