GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
iclass_bands.c
Go to the documentation of this file.
1 /*!
2  \file lib/imagery/iclass_bands.c
3 
4  \brief Imagery library - functions for wx.iclass
5 
6  Computation based on training areas for supervised classification.
7  Based on i.class module (GRASS 6).
8 
9  Reading bands cell category values.
10 
11  Copyright (C) 1999-2007, 2011 by the GRASS Development Team
12 
13  This program is free software under the GNU General Public License
14  (>=v2). Read the file COPYING that comes with GRASS for details.
15 
16  \author David Satnik, Central Washington University (original author)
17  \author Markus Neteler <neteler itc.it> (i.class module)
18  \author Bernhard Reiter <bernhard intevation.de> (i.class module)
19  \author Brad Douglas <rez touchofmadness.com>(i.class module)
20  \author Glynn Clements <glynn gclements.plus.com> (i.class module)
21  \author Hamish Bowman <hamish_b yahoo.com> (i.class module)
22  \author Jan-Oliver Wagner <jan intevation.de> (i.class module)
23  \author Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
24  \author Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)
25  */
26 
27 #include <grass/imagery.h>
28 #include <grass/raster.h>
29 
30 #include "iclass_local_proto.h"
31 
32 /*!
33  \brief Open and allocate space for the group band files.
34 
35  \param refer pointer to band files structure
36  \param[out] band_buffer buffer to read one row of each band
37  \param[out] band_fd band files descriptors
38  */
39 void open_band_files(struct Ref *refer, CELL *** band_buffer, int **band_fd)
40 {
41  int n, nbands;
42 
43  char *name, *mapset;
44 
45  G_debug(3, "open_band_files()");
46 
47  /* allocate row buffers and open raster maps */
48  nbands = refer->nfiles;
49  *band_buffer = (CELL **) G_malloc(nbands * sizeof(CELL *));
50  *band_fd = (int *)G_malloc(nbands * sizeof(int));
51 
52  for (n = 0; n < nbands; n++) {
53  (*band_buffer)[n] = Rast_allocate_c_buf();
54  name = refer->file[n].name;
55  mapset = refer->file[n].mapset;
56  (*band_fd)[n] = Rast_open_old(name, mapset);
57  }
58 }
59 
60 /*!
61  \brief Close and free space for the group band files.
62 
63  \param refer pointer to band files structure
64  \param band_buffer buffer to read one row of each band
65  \param band_fd band files descriptors
66  */
67 void close_band_files(struct Ref *refer, CELL ** band_buffer, int *band_fd)
68 {
69  int n, nbands;
70 
71  G_debug(3, "close_band_files()");
72 
73  nbands = refer->nfiles;
74  for (n = 0; n < nbands; n++) {
75  G_free(band_buffer[n]);
76  Rast_close(band_fd[n]);
77  }
78 
79  G_free(band_buffer);
80  G_free(band_fd);
81 }
82 
83 /*!
84  \brief Read one row of each band.
85 
86  \param band_buffer buffer to read one row of each band
87  \param band_fd band files descriptors
88  \param nbands number of band files
89  \param row data row
90  */
91 void read_band_row(CELL ** band_buffer, int *band_fd, int nbands, int row)
92 {
93  int i;
94 
95  G_debug(5, "read_band_row(): row = %d", row);
96 
97  for (i = 0; i < nbands; i++)
98  Rast_get_c_row_nomask(band_fd[i], band_buffer[i], row);
99 }
#define G_malloc(n)
Definition: defs/gis.h:112
char name[INAME_LEN]
Definition: imagery.h:22
Definition: imagery.h:26
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
void Rast_get_c_row_nomask(int, CELL *, int)
Read raster row without masking (CELL type)
char mapset[INAME_LEN]
Definition: imagery.h:23
int Rast_open_old(const char *, const char *)
Open an existing integer raster map (cell)
Definition: raster/open.c:112
int nfiles
Definition: imagery.h:28
struct Ref_Files * file
Definition: imagery.h:29
int CELL
Definition: gis.h:613
const char * name
Definition: named_colr.c:7
void open_band_files(struct Ref *refer, CELL ***band_buffer, int **band_fd)
Open and allocate space for the group band files.
Definition: iclass_bands.c:39
int G_debug(int, const char *,...) __attribute__((format(printf
CELL * Rast_allocate_c_buf(void)
Allocate memory for a CELL type raster map.
Definition: alloc_cell.c:82
void read_band_row(CELL **band_buffer, int *band_fd, int nbands, int row)
Read one row of each band.
Definition: iclass_bands.c:91
void close_band_files(struct Ref *refer, CELL **band_buffer, int *band_fd)
Close and free space for the group band files.
Definition: iclass_bands.c:67
void Rast_close(int)
Close a raster map.
Definition: raster/close.c:99