2 #include <grass/imagery.h>
14 #define SIG struct One_Sig
22 S->sig = (
SIG *) G_realloc(S->sig, S->nsigs *
sizeof(
SIG));
24 S->sig[i].mean = (
double *)G_calloc(S->nbands,
sizeof(
double));
25 S->sig[i].var = (
double **)G_calloc(S->nbands,
sizeof(
double *));
27 for (n = 0; n < S->nbands; n++)
28 S->sig[i].var[n] = (
double *)G_calloc(S->nbands,
sizeof(
double));
31 S->sig[i].have_color = 0;
32 sprintf(S->sig[i].desc,
"Class %d", i + 1);;
41 for (i = 0; i < S->nsigs; i++) {
42 for (n = 0; n < S->nbands; n++)
43 free(S->sig[i].var[n]);
58 while ((i = fgetc(fd)) != EOF)
70 if (fscanf(fd,
"%d", &s->npoints) != 1)
73 for (i = 0; i < S->nbands; i++) {
74 if (fscanf(fd,
"%lf", &s->mean[i]) != 1)
78 for (i = 0; i < S->nbands; i++) {
79 for (n = 0; n <= i; n++) {
80 if (fscanf(fd,
"%lf", &s->var[i][n]) != 1)
82 s->var[
n][i] = s->var[i][
n];
85 if (fscanf(fd,
"%f%f%f", &s->r, &s->g, &s->b) == 3 &&
86 s->r >= 0.0 && s->r <= 1.0 &&
87 s->g >= 0.0 && s->g <= 1.0 && s->b >= 0.0 && s->b <= 1.0)
99 while ((n = fgetc(fd)) != EOF)
123 fprintf(fd,
"#%s\n", S->title);
124 for (k = 0; k < S->nsigs; k++) {
128 fprintf(fd,
"#%s\n", s->desc);
129 fprintf(fd,
"%d\n", s->npoints);
130 for (i = 0; i < S->nbands; i++)
131 fprintf(fd,
"%g ", s->mean[i]);
133 for (i = 0; i < S->nbands; i++) {
134 for (n = 0; n <= i; n++)
135 fprintf(fd,
"%g ", s->var[i][n]);
139 fprintf(fd,
"%g %g %g\n", s->r, s->g, s->b);
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int I_new_signature(struct Signature *S)
int I_read_signatures(FILE *fd, struct Signature *S)
int I_init_signatures(struct Signature *S, int nbands)
int G_strip(char *buf)
Removes all leading and trailing white space from string.
int I_write_signatures(FILE *fd, struct Signature *S)
int I_free_signatures(struct Signature *S)
int I_get_to_eol(char *line, int len, FILE *fd)
int I_read_one_signature(FILE *fd, struct Signature *S)