7 #define LIST struct Histogram_list
9 static FILE *fopen_histogram_new(
const char *);
10 static int cmp(
const void *,
const void *);
11 static int cmp_count(
const void *,
const void *);
53 G_warning(
_(
"Histogram for [%s in %s] missing (run r.support)"),
name,
62 while (fgets(buf,
sizeof buf, fd)) {
63 if (sscanf(buf,
"%ld:%ld", &cat, &
count) != 2)
70 if (histogram->
num == 0)
93 fp = fopen_histogram_new(
name);
96 for (n = 0; n < histogram->
num; n++) {
118 fp = fopen_histogram_new(
name);
123 fprintf(fp,
"%ld:%ld\n", (
long)cat,
count);
161 return histogram->
num;
173 if (n < 0 || n >= histogram->
num)
189 if (n < 0 || n >= histogram->
num)
204 if (histogram->
num > 0)
225 if ((n = histogram->
num) <= 1)
231 for (a = 1; a < n; a++)
241 for (a = 0,
b = 1;
b < n;
b++) {
251 histogram->
num = a + 1;
256 static int cmp(
const void *aa,
const void *bb)
258 const LIST *a = aa, *
b = bb;
284 if ((n = histogram->
num) <= 1)
290 qsort(
list, n,
sizeof(
LIST), &cmp_count);
295 static int cmp_count(
const void *aa,
const void *bb)
297 const LIST *a = aa, *
b = bb;
299 if (a->count <
b->count)
302 if (a->count >
b->count)
314 static FILE *fopen_histogram_new(
const char *
name)
352 for (i = 0; i < histogram->
num; i++) {
353 if (histogram->
list[i].
cat == cat) {
377 for (i = 0; i < histogram->
num; i++) {
378 if (histogram->
list[i].
cat == cat) {
401 histogram->
list[histogram->
num - 1].
cat = cat;
415 for (i = 0; i < histogram->
num; i++)
void G_free(void *)
Free allocated memory.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a misc file from the mapset search list or in a specified mapset. (look but don't touch)
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
int Rast_rewind_cell_stats(struct Cell_stats *)
Reset/rewind cell stats.
int Rast_next_cell_stat(CELL *, long *, struct Cell_stats *)
Retrieve sorted cell stats.
int Rast_get_histogram_num(const struct Histogram *histogram)
Sorts the histogram in ascending order by counts then category.
void Rast_write_histogram(const char *name, const struct Histogram *histogram)
Writes the histogram information.
int Rast_read_histogram(const char *name, const char *mapset, struct Histogram *histogram)
read the histogram information
void Rast_free_histogram(struct Histogram *histogram)
Frees memory allocated for the histogram.
int Rast_add_histogram(CELL cat, long count, struct Histogram *histogram)
adds count to the histogram value for cat
int Rast_sort_histogram(struct Histogram *histogram)
Sorts the histogram.
void Rast_extend_histogram(CELL cat, long count, struct Histogram *histogram)
Extends histogram struct to accommodate a new value.
void Rast_write_histogram_cs(const char *name, struct Cell_stats *statf)
Writes the histogram based on cell statistics to file.
long Rast_get_histogram_count(int n, const struct Histogram *histogram)
Returns count for the nth element in the histogram.
int Rast_sort_histogram_by_count(struct Histogram *histogram)
Sorts the histogram by counts.
void Rast_make_histogram_cs(struct Cell_stats *statf, struct Histogram *histogram)
Creates histogram based on cell statistics.
int Rast_set_histogram(CELL cat, long count, struct Histogram *histogram)
sets the histogram value for cat to count
CELL Rast_get_histogram_cat(int n, const struct Histogram *histogram)
Returns cat for the nth element in the histogram.
void Rast_zero_histogram(struct Histogram *histogram)
Zero out histogram struct.
void Rast_init_histogram(struct Histogram *histogram)
initializes the histogram structure
void Rast_remove_histogram(const char *name)
Removes the histogram.
struct Histogram::Histogram_list * list