GRASS Programmer's Manual  6.4.4(2014)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
histogram.c File Reference
#include <grass/gis.h>
#include <grass/glocale.h>
#include <stdlib.h>
Include dependency graph for histogram.c:

Go to the source code of this file.

Macros

#define LIST   struct Histogram_list
 

Functions

int G_init_histogram (struct Histogram *histogram)
 initializes the histogram structure More...
 
int G_read_histogram (const char *name, const char *mapset, struct Histogram *histogram)
 read the histogram information More...
 
int G_write_histogram (const char *name, const struct Histogram *histogram)
 Writes the histogram information. More...
 
int G_write_histogram_cs (const char *name, struct Cell_stats *statf)
 Writes the histogram based on cell statistics to file. More...
 
int G_make_histogram_cs (struct Cell_stats *statf, struct Histogram *histogram)
 Creates histogram based on cell statistics. More...
 
int G_get_histogram_num (const struct Histogram *histogram)
 Sorts the histogram in ascending order by counts then category. More...
 
CELL G_get_histogram_cat (int n, const struct Histogram *histogram)
 Returns cat for the nth element in the histogram. More...
 
long G_get_histogram_count (int n, const struct Histogram *histogram)
 Returns count for the nth element in the histogram. More...
 
int G_free_histogram (struct Histogram *histogram)
 Frees memory allocated for the histogram. More...
 
int G_sort_histogram (struct Histogram *histogram)
 Sorts the histogram. More...
 
int G_sort_histogram_by_count (struct Histogram *histogram)
 Sorts the histogram by counts. More...
 
int G_remove_histogram (const char *name)
 Removes the histogram. More...
 
int G_add_histogram (CELL cat, long count, struct Histogram *histogram)
 adds count to the histogram value for cat More...
 
int G_set_histogram (CELL cat, long count, struct Histogram *histogram)
 sets the histogram value for cat to count More...
 
int G_extend_histogram (CELL cat, long count, struct Histogram *histogram)
 Extends histogram struct to accomodate a new value. More...
 
int G_zero_histogram (struct Histogram *histogram)
 Zero out histogram struct. More...
 

Macro Definition Documentation

#define LIST   struct Histogram_list

Definition at line 6 of file histogram.c.

Referenced by G_extend_histogram().

Function Documentation

int G_add_histogram ( CELL  cat,
long  count,
struct Histogram *  histogram 
)

adds count to the histogram value for cat

adds count to the histogram value for cat

Parameters
catcategory
count
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 389 of file histogram.c.

References count, and G_extend_histogram().

Referenced by G_make_histogram_cs().

int G_extend_histogram ( CELL  cat,
long  count,
struct Histogram *  histogram 
)

Extends histogram struct to accomodate a new value.

Parameters
catcategory
count
histogramstruct for histogram
Returns

Definition at line 439 of file histogram.c.

References count, and LIST.

Referenced by G_add_histogram(), G_read_histogram(), and G_set_histogram().

int G_free_histogram ( struct Histogram *  histogram)

Frees memory allocated for the histogram.

frees the memory allocated for the histogram

Parameters
histogramstruct for histogram
Returns

Definition at line 234 of file histogram.c.

References G_free(), and NULL.

Referenced by G_read_histogram().

CELL G_get_histogram_cat ( int  n,
const struct Histogram *  histogram 
)

Returns cat for the nth element in the histogram.

Returns cat for the nth element in the histogram

Parameters
histogramstruct for histogram
Returns
CELL

Definition at line 201 of file histogram.c.

Referenced by G_histogram_eq().

long G_get_histogram_count ( int  n,
const struct Histogram *  histogram 
)

Returns count for the nth element in the histogram.

Returns count for the nth element in the histogram

Parameters
nnth element
histogramstruct for histogram
Returns
count

Definition at line 218 of file histogram.c.

Referenced by G_histogram_eq().

int G_get_histogram_num ( const struct Histogram *  histogram)

Sorts the histogram in ascending order by counts then category.

Sorts the histogram in ascending order by counts then category. No combining is done.

Parameters
histogramstruct for histogram
Returns
1 if successful, -1 on fail

Definition at line 188 of file histogram.c.

Referenced by G_histogram_eq().

int G_init_histogram ( struct Histogram *  histogram)

initializes the histogram structure

initializes the histogram structure for calls to G_set_histogram() and G_add_histogram()

Parameters
histogram
Returns
int

Definition at line 22 of file histogram.c.

References NULL.

Referenced by G_make_histogram_cs(), and G_read_histogram().

int G_make_histogram_cs ( struct Cell_stats *  statf,
struct Histogram *  histogram 
)

Creates histogram based on cell statistics.

Parameters
statfcell statistics
histogramraster histogram
Returns
0

Definition at line 163 of file histogram.c.

References count, G_add_histogram(), G_init_histogram(), G_next_cell_stat(), G_rewind_cell_stats(), and G_sort_histogram().

int G_read_histogram ( const char *  name,
const char *  mapset,
struct Histogram *  histogram 
)

read the histogram information

Reads the histogram information associated with map layer "map" in mapset "mapset" into the structure "histogram".

note: a warning message is printed if the file is missing or incorrect

Parameters
namename of map
mapsetmapset that map belongs to
histogramstruct for histogram
Returns
1 if successful, 0 if no histogram file, -1 on fail

Definition at line 46 of file histogram.c.

References count, G_extend_histogram(), G_find_file2_misc(), G_fopen_old_misc(), G_free_histogram(), G_init_histogram(), G_sort_histogram(), G_warning(), and NULL.

int G_remove_histogram ( const char *  name)

Removes the histogram.

Removes the histogram information associated with map layer "name"

Parameters
namename of map
Returns
0

Definition at line 371 of file histogram.c.

References G_remove_misc().

int G_set_histogram ( CELL  cat,
long  count,
struct Histogram *  histogram 
)

sets the histogram value for cat to count

sets the histogram value for cat to count

Parameters
catcategory
count
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 415 of file histogram.c.

References count, and G_extend_histogram().

int G_sort_histogram ( struct Histogram *  histogram)

Sorts the histogram.

Sorts the histogram in ascending order by category, combining (by adding) elements that have the same category.

Parameters
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 253 of file histogram.c.

References b.

Referenced by G_make_histogram_cs(), and G_read_histogram().

int G_sort_histogram_by_count ( struct Histogram *  histogram)

Sorts the histogram by counts.

Sorts the histogram in ascending order by counts then category. No combining is done.

Parameters
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 313 of file histogram.c.

int G_write_histogram ( const char *  name,
const struct Histogram *  histogram 
)

Writes the histogram information.

Writes the histogram information associated with map layer "name"

Parameters
namename of map
histogramstruct for histogram
Returns
1 if successful, -1 on fail

Definition at line 105 of file histogram.c.

References count, and NULL.

int G_write_histogram_cs ( const char *  name,
struct Cell_stats *  statf 
)

Writes the histogram based on cell statistics to file.

Parameters
namename of map
statfcell statistics
Returns
1 on success -1 on failure

Definition at line 135 of file histogram.c.

References count, G_next_cell_stat(), G_rewind_cell_stats(), and NULL.

int G_zero_histogram ( struct Histogram *  histogram)

Zero out histogram struct.

Parameters
histogramstruct for histogram
Returns

Definition at line 458 of file histogram.c.