Skip to content

Commit

Permalink
Merge pull request #55 from HuidaeCho/compile_for_grass79
Browse files Browse the repository at this point in the history
Make most grass7 modules compilable
  • Loading branch information
HuidaeCho committed Nov 13, 2019
2 parents e05c7bf + e46dfea commit bfb35ee
Show file tree
Hide file tree
Showing 38 changed files with 158 additions and 250 deletions.
5 changes: 4 additions & 1 deletion grass7/imagery/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
MODULE_TOPDIR = ..

# i.fusion.brovey deprecated
# Deprecated
# i.fusion.brovey
# i.pr_statistics (relies on D_* and R_* functions)
# i.pr_training (relies on the site library)

ALL_SUBDIRS := ${sort ${dir ${wildcard */.}}}
DEPRECATED_SUBDIRS := ${sort ${dir ${wildcard */DEPRECATED}}}
Expand Down
2 changes: 1 addition & 1 deletion grass7/imagery/i.pr/PRLIB/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PRINCLUDE = ../include/
EXTRA_CFLAGS = -I$(PRINCLUDE)
EXTRA_LIBS = $(GMATHLIB) $(GISLIB) $(MATHLIB)

LIB_NAME = grass_pr
LIB_NAME = grass_pr.$(GRASS_LIB_VERSION_NUMBER)

include $(MODULE_TOPDIR)/include/Make/Lib.make

Expand Down
5 changes: 3 additions & 2 deletions grass7/imagery/i.pr/PRLIB/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include <math.h>
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include "global.h"

static void add_points_to_blob();
static int in_blob();

void extract_sites_from_blob(Blob * blobs, int npoints, Blob * blobs,
void extract_sites_from_blob(Blob * blobs, int npoints, int nblobs,
struct Cell_head *cellhd, BlobSites * sites,
double **matrix)

Expand Down Expand Up @@ -99,7 +100,7 @@ void find_blob(double **matrix, int r, int c, Blob ** blobs, int *npoints,
}
}

static void add_points_to_blob(Blob *** blobs, int *npoints, Blob *** blobs,
static void add_points_to_blob(Blob *** blobs, int *npoints, int nblobs,
double **matrix, int r, int c, int i, int j,
double tm, double tM)
{
Expand Down
104 changes: 0 additions & 104 deletions grass7/imagery/i.pr/PRLIB/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,110 +12,6 @@
#include <grass/gis.h>
#include "global.h"

void Bootsamples(n, prob, random_labels)
/*
given an array of probabilities of length n, extract a bootstrap sample
of n elements according to the vector of probabilities
*/
int n;
double *prob;
int *random_labels;

{
int i, j;
int *random_labels_flag;
double *random;
double *cumprob;
double probtot = .0;

for (i = 0; i < n; i++)
probtot += prob[i];
for (i = 0; i < n; i++)
prob[i] /= probtot;

random_labels_flag = (int *)G_calloc(n, sizeof(int));
random = (double *)G_calloc(n, sizeof(double));
cumprob = (double *)G_calloc(n, sizeof(double));

for (i = 0; i < n; ++i) {
random[i] = (double)drand48();
random_labels[i] = n - 1;
random_labels_flag[i] = 0;
}


for (i = 0; i < n; i++) {
if (i > 0)
cumprob[i] = cumprob[i - 1] + prob[i];
else
cumprob[0] = prob[0];

for (j = 0; j < n; j++) {

if (random[j] < cumprob[i])
if (random_labels_flag[j] == 0) {
random_labels[j] = i;
random_labels_flag[j] = 1;
}
}
}

G_free(random);
G_free(cumprob);
G_free(random_labels_flag);
}


void Bootsamples_rseed(int n, double *prob, int *random_labels, int *idum)

/*
given an array of probabilities of length n, extract a bootstrap sample
of n elements according to the vector of probabilities
*/
{
int i, j;
int *random_labels_flag;
double *random;
double *cumprob;
double probtot = .0;

for (i = 0; i < n; i++)
probtot += prob[i];
for (i = 0; i < n; i++)
prob[i] /= probtot;

random_labels_flag = (int *)G_calloc(n, sizeof(int));
random = (double *)G_calloc(n, sizeof(double));
cumprob = (double *)G_calloc(n, sizeof(double));

for (i = 0; i < n; ++i) {
random[i] = (double)ran1(idum);
random_labels[i] = n - 1;
random_labels_flag[i] = 0;
}


for (i = 0; i < n; i++) {
if (i > 0)
cumprob[i] = cumprob[i - 1] + prob[i];
else
cumprob[0] = prob[0];

for (j = 0; j < n; j++) {

if (random[j] < cumprob[i])
if (random_labels_flag[j] == 0) {
random_labels[j] = i;
random_labels_flag[j] = 1;
}
}
}

G_free(random);
G_free(cumprob);
G_free(random_labels_flag);
}

void Bootsamples(int n, double *prob, int *random_labels)

/*
Expand Down
21 changes: 11 additions & 10 deletions grass7/imagery/i.pr/PRLIB/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
structure Feature management
*/
#include <grass/gis.h>
#include <grass/raster.h>
#include "global.h"
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -182,8 +183,8 @@ void compute_features(Features * features)
switch (features->training.data_type) {
case GRASS_data:
fprintf(stdout, "%s\n", features->training.mapnames[i][j]);
if ((mapset =
G_find_cell(features->training.mapnames[i][j],
if ((mapset = (char *)
G_find_raster(features->training.mapnames[i][j],
"")) == NULL) {
sprintf(tempbuf,
"compute_features-> Can't find raster map <%s>",
Expand Down Expand Up @@ -889,7 +890,7 @@ void read_features(char *file, Features * features, int npc)
for (i = 0; i < features->nclasses; i++) {
sscanf(line, "%d", &(features->p_classes[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}

if (!features->f_standardize[0]) {
Expand All @@ -907,13 +908,13 @@ void read_features(char *file, Features * features, int npc)
for (i = 0; i < features->f_standardize[1]; i++) {
sscanf(line, "%lf", &(features->mean[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
line = GetLine(fp);
for (i = 0; i < features->f_standardize[1]; i++) {
sscanf(line, "%lf", &(features->sd[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
}

Expand Down Expand Up @@ -949,7 +950,7 @@ void read_features(char *file, Features * features, int npc)
for (j = 0; j < features->examples_dim; j++) {
sscanf(line, "%lf", &(features->value[i][j]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
sscanf(line, "%d", &(features->class[i]));
}
Expand Down Expand Up @@ -1012,7 +1013,7 @@ void read_features(char *file, Features * features, int npc)
sscanf(line, "%lf", &(features->value[i][index++]));
}
line = (char *)strchr(line, '\t');
*line++;
line++;
}
sscanf(line, "%d", &(features->class[i]));
}
Expand Down Expand Up @@ -1166,7 +1167,7 @@ void read_header_features(FILE * fp, Features * features)
for (i = 0; i < features->nclasses; i++) {
sscanf(line, "%d", &(features->p_classes[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}

if (!features->f_standardize[0]) {
Expand All @@ -1184,13 +1185,13 @@ void read_header_features(FILE * fp, Features * features)
for (i = 0; i < features->f_standardize[1]; i++) {
sscanf(line, "%lf", &(features->mean[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
line = GetLine(fp);
for (i = 0; i < features->f_standardize[1]; i++) {
sscanf(line, "%lf", &(features->sd[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
}

Expand Down
4 changes: 2 additions & 2 deletions grass7/imagery/i.pr/PRLIB/min_quadratic.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <grass/gis.h>
#include "func.h"

void mqc(double **M, double *m, int n, double **H, double *h, int **mH,
double **K, double *k, int **mK, double eps, double *x,
void mqc(double **M, double *m, int n, double **H, double *h, int mH,
double **K, double *k, int mK, double eps, double *x,
double *minvalue)
{
int i, j, l;
Expand Down
1 change: 1 addition & 0 deletions grass7/imagery/i.pr/PRLIB/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <grass/gis.h>
#include <grass/raster.h>
#include <stdlib.h>

int open_new_CELL(name)
Expand Down
4 changes: 2 additions & 2 deletions grass7/imagery/i.pr/PRLIB/pca.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ void read_pca(FILE * fp, Pca * pca)
for (i = 0; i < pca->n; i++) {
sscanf(line, "%lf", &(pca->eigval[i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
line = GetLine(fp);
for (j = 0; j < pca->n; j++) {
line = GetLine(fp);
for (i = 0; i < pca->n; i++) {
sscanf(line, "%lf", &(pca->eigmat[j][i]));
line = (char *)strchr(line, '\t');
*line++;
line++;
}
}
}

0 comments on commit bfb35ee

Please sign in to comment.