mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Reformat C/C++ code ahead of 2023.03 release (#6295)
* format files * format template files too
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* hc.f -- translated by f2c (version 20020208).
|
||||
You must link the resulting object file with the libraries:
|
||||
-lf2c -lm (in that order)
|
||||
-lf2c -lm (in that order)
|
||||
*/
|
||||
|
||||
#include "f2c.h"
|
||||
@@ -27,7 +27,7 @@
|
||||
/* C */
|
||||
/* ------------------------------------------------------------C */
|
||||
/* Subroutine */ int hc_(n, len, iopt, ia, ib, crit, membr, nn, disnn, flag__,
|
||||
diss)
|
||||
diss)
|
||||
integer *n, *len, *iopt, *ia, *ib;
|
||||
doublereal *crit, *membr;
|
||||
integer *nn;
|
||||
@@ -35,262 +35,253 @@ doublereal *disnn;
|
||||
logical *flag__;
|
||||
doublereal *diss;
|
||||
{
|
||||
/* Initialized data */
|
||||
/* Initialized data */
|
||||
|
||||
static doublereal inf = 1e20;
|
||||
static doublereal inf = 1e20;
|
||||
|
||||
/* System generated locals */
|
||||
integer i__1, i__2;
|
||||
doublereal d__1, d__2;
|
||||
/* System generated locals */
|
||||
integer i__1, i__2;
|
||||
doublereal d__1, d__2;
|
||||
|
||||
/* Local variables */
|
||||
static doublereal dmin__;
|
||||
static integer i__, j, k;
|
||||
static doublereal x;
|
||||
static integer i2, j2, jj, im, jm;
|
||||
static doublereal xx;
|
||||
static integer ind, ncl;
|
||||
extern integer ioffset_();
|
||||
static integer ind1, ind2, ind3;
|
||||
/* Local variables */
|
||||
static doublereal dmin__;
|
||||
static integer i__, j, k;
|
||||
static doublereal x;
|
||||
static integer i2, j2, jj, im, jm;
|
||||
static doublereal xx;
|
||||
static integer ind, ncl;
|
||||
extern integer ioffset_();
|
||||
static integer ind1, ind2, ind3;
|
||||
|
||||
/* Parameter adjustments */
|
||||
--flag__;
|
||||
--disnn;
|
||||
--nn;
|
||||
--membr;
|
||||
--crit;
|
||||
--ib;
|
||||
--ia;
|
||||
--diss;
|
||||
/* Parameter adjustments */
|
||||
--flag__;
|
||||
--disnn;
|
||||
--nn;
|
||||
--membr;
|
||||
--crit;
|
||||
--ib;
|
||||
--ia;
|
||||
--diss;
|
||||
|
||||
/* Function Body */
|
||||
/* Function Body */
|
||||
|
||||
/* Initializations */
|
||||
/* Initializations */
|
||||
|
||||
i__1 = *n;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
membr[i__] = (float)1.;
|
||||
flag__[i__] = TRUE_;
|
||||
i__1 = *n;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
membr[i__] = (float)1.;
|
||||
flag__[i__] = TRUE_;
|
||||
}
|
||||
ncl = *n;
|
||||
if (*iopt == 1) {
|
||||
i__1 = *n * (*n - 1) / 2;
|
||||
for (ind = 1; ind <= i__1; ++ind) {
|
||||
diss[ind] /= (float)2.;
|
||||
}
|
||||
ncl = *n;
|
||||
if (*iopt == 1) {
|
||||
i__1 = *n * (*n - 1) / 2;
|
||||
for (ind = 1; ind <= i__1; ++ind) {
|
||||
diss[ind] /= (float)2.;
|
||||
}
|
||||
}
|
||||
/* (Above is done for the case of the min. var. method */
|
||||
/* where merging criteria are defined in terms of variances */
|
||||
/* rather than distances.) */
|
||||
}
|
||||
/* (Above is done for the case of the min. var. method */
|
||||
/* where merging criteria are defined in terms of variances */
|
||||
/* rather than distances.) */
|
||||
|
||||
/* Carry out an agglomeration - first create list of NNs */
|
||||
/* Carry out an agglomeration - first create list of NNs */
|
||||
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
dmin__ = inf;
|
||||
i__2 = *n;
|
||||
for (j = i__ + 1; j <= i__2; ++j) {
|
||||
ind = ioffset_(n, &i__, &j);
|
||||
if (diss[ind] >= dmin__) {
|
||||
goto L500;
|
||||
}
|
||||
dmin__ = diss[ind];
|
||||
jm = j;
|
||||
L500:
|
||||
;
|
||||
}
|
||||
nn[i__] = jm;
|
||||
disnn[i__] = dmin__;
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
dmin__ = inf;
|
||||
i__2 = *n;
|
||||
for (j = i__ + 1; j <= i__2; ++j) {
|
||||
ind = ioffset_(n, &i__, &j);
|
||||
if (diss[ind] >= dmin__) {
|
||||
goto L500;
|
||||
}
|
||||
dmin__ = diss[ind];
|
||||
jm = j;
|
||||
L500:;
|
||||
}
|
||||
nn[i__] = jm;
|
||||
disnn[i__] = dmin__;
|
||||
}
|
||||
|
||||
L400:
|
||||
/* Next, determine least diss. using list of NNs */
|
||||
/* Next, determine least diss. using list of NNs */
|
||||
dmin__ = inf;
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
if (!flag__[i__]) {
|
||||
goto L600;
|
||||
}
|
||||
if (disnn[i__] >= dmin__) {
|
||||
goto L600;
|
||||
}
|
||||
dmin__ = disnn[i__];
|
||||
im = i__;
|
||||
jm = nn[i__];
|
||||
L600:;
|
||||
}
|
||||
--ncl;
|
||||
|
||||
/* This allows an agglomeration to be carried out. */
|
||||
|
||||
i2 = min(im, jm);
|
||||
j2 = max(im, jm);
|
||||
ia[*n - ncl] = i2;
|
||||
ib[*n - ncl] = j2;
|
||||
crit[*n - ncl] = dmin__;
|
||||
ind1 = ioffset_(n, &i2, &j2);
|
||||
/* write(6,*) "agglom: ",i2,j2,dmin,diss(ind1) */
|
||||
|
||||
/* Update dissimilarities from new cluster. */
|
||||
|
||||
flag__[j2] = FALSE_;
|
||||
dmin__ = inf;
|
||||
i__1 = *n;
|
||||
for (k = 1; k <= i__1; ++k) {
|
||||
if (!flag__[k]) {
|
||||
goto L800;
|
||||
}
|
||||
if (k == i2) {
|
||||
goto L800;
|
||||
}
|
||||
x = membr[i2] + membr[j2] + membr[k];
|
||||
if (i2 < k) {
|
||||
ind1 = ioffset_(n, &i2, &k);
|
||||
} else {
|
||||
ind1 = ioffset_(n, &k, &i2);
|
||||
}
|
||||
if (j2 < k) {
|
||||
ind2 = ioffset_(n, &j2, &k);
|
||||
} else {
|
||||
ind2 = ioffset_(n, &k, &j2);
|
||||
}
|
||||
ind3 = ioffset_(n, &i2, &j2);
|
||||
xx = diss[ind3];
|
||||
|
||||
/* WARD'S MINIMUM VARIANCE METHOD - IOPT=1. */
|
||||
|
||||
if (*iopt == 1) {
|
||||
diss[ind1] = (membr[i2] + membr[k]) * diss[ind1] +
|
||||
(membr[j2] + membr[k]) * diss[ind2] - membr[k] * xx;
|
||||
diss[ind1] /= x;
|
||||
}
|
||||
|
||||
/* SINGLE LINK METHOD - IOPT=2. */
|
||||
|
||||
if (*iopt == 2) {
|
||||
/* Computing MIN */
|
||||
d__1 = diss[ind1], d__2 = diss[ind2];
|
||||
diss[ind1] = min(d__1, d__2);
|
||||
}
|
||||
|
||||
/* COMPLETE LINK METHOD - IOPT=3. */
|
||||
|
||||
if (*iopt == 3) {
|
||||
/* Computing MAX */
|
||||
d__1 = diss[ind1], d__2 = diss[ind2];
|
||||
diss[ind1] = max(d__1, d__2);
|
||||
}
|
||||
|
||||
/* AVERAGE LINK (OR GROUP AVERAGE) METHOD - IOPT=4. */
|
||||
|
||||
if (*iopt == 4) {
|
||||
diss[ind1] = (membr[i2] * diss[ind1] + membr[j2] * diss[ind2]) /
|
||||
(membr[i2] + membr[j2]);
|
||||
}
|
||||
|
||||
/* MCQUITTY'S METHOD - IOPT=5. */
|
||||
|
||||
if (*iopt == 5) {
|
||||
diss[ind1] = diss[ind1] * (float).5 + diss[ind2] * (float).5;
|
||||
}
|
||||
|
||||
/* MEDIAN (GOWER'S) METHOD - IOPT=6. */
|
||||
|
||||
if (*iopt == 6) {
|
||||
diss[ind1] =
|
||||
diss[ind1] * (float).5 + diss[ind2] * (float).5 - xx * (float).25;
|
||||
}
|
||||
|
||||
/* CENTROID METHOD - IOPT=7. */
|
||||
|
||||
if (*iopt == 7) {
|
||||
diss[ind1] = (membr[i2] * diss[ind1] + membr[j2] * diss[ind2] -
|
||||
membr[i2] * membr[j2] * xx / (membr[i2] + membr[j2])) /
|
||||
(membr[i2] + membr[j2]);
|
||||
}
|
||||
|
||||
if (i2 > k) {
|
||||
goto L800;
|
||||
}
|
||||
if (diss[ind1] >= dmin__) {
|
||||
goto L800;
|
||||
}
|
||||
dmin__ = diss[ind1];
|
||||
jj = k;
|
||||
L800:;
|
||||
}
|
||||
membr[i2] += membr[j2];
|
||||
disnn[i2] = dmin__;
|
||||
nn[i2] = jj;
|
||||
|
||||
/* Update list of NNs insofar as this is required. */
|
||||
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
if (!flag__[i__]) {
|
||||
goto L900;
|
||||
}
|
||||
if (nn[i__] == i2) {
|
||||
goto L850;
|
||||
}
|
||||
if (nn[i__] == j2) {
|
||||
goto L850;
|
||||
}
|
||||
goto L900;
|
||||
L850:
|
||||
/* (Redetermine NN of I:) */
|
||||
dmin__ = inf;
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
if (! flag__[i__]) {
|
||||
goto L600;
|
||||
}
|
||||
if (disnn[i__] >= dmin__) {
|
||||
goto L600;
|
||||
}
|
||||
dmin__ = disnn[i__];
|
||||
im = i__;
|
||||
jm = nn[i__];
|
||||
L600:
|
||||
;
|
||||
i__2 = *n;
|
||||
for (j = i__ + 1; j <= i__2; ++j) {
|
||||
ind = ioffset_(n, &i__, &j);
|
||||
if (!flag__[j]) {
|
||||
goto L870;
|
||||
}
|
||||
if (i__ == j) {
|
||||
goto L870;
|
||||
}
|
||||
if (diss[ind] >= dmin__) {
|
||||
goto L870;
|
||||
}
|
||||
dmin__ = diss[ind];
|
||||
jj = j;
|
||||
L870:;
|
||||
}
|
||||
--ncl;
|
||||
nn[i__] = jj;
|
||||
disnn[i__] = dmin__;
|
||||
L900:;
|
||||
}
|
||||
|
||||
/* This allows an agglomeration to be carried out. */
|
||||
/* Repeat previous steps until N-1 agglomerations carried out. */
|
||||
|
||||
i2 = min(im,jm);
|
||||
j2 = max(im,jm);
|
||||
ia[*n - ncl] = i2;
|
||||
ib[*n - ncl] = j2;
|
||||
crit[*n - ncl] = dmin__;
|
||||
ind1 = ioffset_(n, &i2, &j2);
|
||||
/* write(6,*) "agglom: ",i2,j2,dmin,diss(ind1) */
|
||||
if (ncl > 1) {
|
||||
goto L400;
|
||||
}
|
||||
|
||||
/* Update dissimilarities from new cluster. */
|
||||
|
||||
flag__[j2] = FALSE_;
|
||||
dmin__ = inf;
|
||||
i__1 = *n;
|
||||
for (k = 1; k <= i__1; ++k) {
|
||||
if (! flag__[k]) {
|
||||
goto L800;
|
||||
}
|
||||
if (k == i2) {
|
||||
goto L800;
|
||||
}
|
||||
x = membr[i2] + membr[j2] + membr[k];
|
||||
if (i2 < k) {
|
||||
ind1 = ioffset_(n, &i2, &k);
|
||||
} else {
|
||||
ind1 = ioffset_(n, &k, &i2);
|
||||
}
|
||||
if (j2 < k) {
|
||||
ind2 = ioffset_(n, &j2, &k);
|
||||
} else {
|
||||
ind2 = ioffset_(n, &k, &j2);
|
||||
}
|
||||
ind3 = ioffset_(n, &i2, &j2);
|
||||
xx = diss[ind3];
|
||||
|
||||
/* WARD'S MINIMUM VARIANCE METHOD - IOPT=1. */
|
||||
|
||||
if (*iopt == 1) {
|
||||
diss[ind1] = (membr[i2] + membr[k]) * diss[ind1] + (membr[j2] +
|
||||
membr[k]) * diss[ind2] - membr[k] * xx;
|
||||
diss[ind1] /= x;
|
||||
}
|
||||
|
||||
/* SINGLE LINK METHOD - IOPT=2. */
|
||||
|
||||
if (*iopt == 2) {
|
||||
/* Computing MIN */
|
||||
d__1 = diss[ind1], d__2 = diss[ind2];
|
||||
diss[ind1] = min(d__1,d__2);
|
||||
}
|
||||
|
||||
/* COMPLETE LINK METHOD - IOPT=3. */
|
||||
|
||||
if (*iopt == 3) {
|
||||
/* Computing MAX */
|
||||
d__1 = diss[ind1], d__2 = diss[ind2];
|
||||
diss[ind1] = max(d__1,d__2);
|
||||
}
|
||||
|
||||
/* AVERAGE LINK (OR GROUP AVERAGE) METHOD - IOPT=4. */
|
||||
|
||||
if (*iopt == 4) {
|
||||
diss[ind1] = (membr[i2] * diss[ind1] + membr[j2] * diss[ind2]) / (
|
||||
membr[i2] + membr[j2]);
|
||||
}
|
||||
|
||||
/* MCQUITTY'S METHOD - IOPT=5. */
|
||||
|
||||
if (*iopt == 5) {
|
||||
diss[ind1] = diss[ind1] * (float).5 + diss[ind2] * (float).5;
|
||||
}
|
||||
|
||||
/* MEDIAN (GOWER'S) METHOD - IOPT=6. */
|
||||
|
||||
if (*iopt == 6) {
|
||||
diss[ind1] = diss[ind1] * (float).5 + diss[ind2] * (float).5 - xx
|
||||
* (float).25;
|
||||
}
|
||||
|
||||
/* CENTROID METHOD - IOPT=7. */
|
||||
|
||||
if (*iopt == 7) {
|
||||
diss[ind1] = (membr[i2] * diss[ind1] + membr[j2] * diss[ind2] -
|
||||
membr[i2] * membr[j2] * xx / (membr[i2] + membr[j2])) / (
|
||||
membr[i2] + membr[j2]);
|
||||
}
|
||||
|
||||
if (i2 > k) {
|
||||
goto L800;
|
||||
}
|
||||
if (diss[ind1] >= dmin__) {
|
||||
goto L800;
|
||||
}
|
||||
dmin__ = diss[ind1];
|
||||
jj = k;
|
||||
L800:
|
||||
;
|
||||
}
|
||||
membr[i2] += membr[j2];
|
||||
disnn[i2] = dmin__;
|
||||
nn[i2] = jj;
|
||||
|
||||
/* Update list of NNs insofar as this is required. */
|
||||
|
||||
i__1 = *n - 1;
|
||||
for (i__ = 1; i__ <= i__1; ++i__) {
|
||||
if (! flag__[i__]) {
|
||||
goto L900;
|
||||
}
|
||||
if (nn[i__] == i2) {
|
||||
goto L850;
|
||||
}
|
||||
if (nn[i__] == j2) {
|
||||
goto L850;
|
||||
}
|
||||
goto L900;
|
||||
L850:
|
||||
/* (Redetermine NN of I:) */
|
||||
dmin__ = inf;
|
||||
i__2 = *n;
|
||||
for (j = i__ + 1; j <= i__2; ++j) {
|
||||
ind = ioffset_(n, &i__, &j);
|
||||
if (! flag__[j]) {
|
||||
goto L870;
|
||||
}
|
||||
if (i__ == j) {
|
||||
goto L870;
|
||||
}
|
||||
if (diss[ind] >= dmin__) {
|
||||
goto L870;
|
||||
}
|
||||
dmin__ = diss[ind];
|
||||
jj = j;
|
||||
L870:
|
||||
;
|
||||
}
|
||||
nn[i__] = jj;
|
||||
disnn[i__] = dmin__;
|
||||
L900:
|
||||
;
|
||||
}
|
||||
|
||||
/* Repeat previous steps until N-1 agglomerations carried out. */
|
||||
|
||||
if (ncl > 1) {
|
||||
goto L400;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
} /* hc_ */
|
||||
|
||||
|
||||
|
||||
integer ioffset_(n, i__, j)
|
||||
integer *n, *i__, *j;
|
||||
{
|
||||
/* System generated locals */
|
||||
integer ret_val;
|
||||
/* System generated locals */
|
||||
integer ret_val;
|
||||
|
||||
/* Map row I and column J of upper half diagonal symmetric matrix */
|
||||
/* onto vector. */
|
||||
/*ret_val = *j + (*i__ - 1) * *n - *i__ * (*i__ + 1) / 2;*/
|
||||
if (*j > *i__) {
|
||||
ret_val = (*j - 1) * (*j - 2) / 2 + *i__;
|
||||
} else {
|
||||
ret_val = (*i__ - 1) * (*i__ - 2) / 2 + *j;
|
||||
}
|
||||
return ret_val;
|
||||
/* Map row I and column J of upper half diagonal symmetric matrix */
|
||||
/* onto vector. */
|
||||
/*ret_val = *j + (*i__ - 1) * *n - *i__ * (*i__ + 1) / 2;*/
|
||||
if (*j > *i__) {
|
||||
ret_val = (*j - 1) * (*j - 2) / 2 + *i__;
|
||||
} else {
|
||||
ret_val = (*i__ - 1) * (*i__ - 2) / 2 + *j;
|
||||
}
|
||||
return ret_val;
|
||||
} /* ioffset_ */
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "f2c.h"
|
||||
|
||||
|
||||
int distdriver_(n, len, d__, iopt, ia, ib, crit)
|
||||
integer *n, *len;
|
||||
doublereal *d__;
|
||||
@@ -15,13 +14,13 @@ integer *iopt, *ia, *ib;
|
||||
doublereal *crit;
|
||||
{
|
||||
static logical *flag__;
|
||||
static doublereal *membr,*disnn;
|
||||
static doublereal *membr, *disnn;
|
||||
extern /* Subroutine */ int hc_();
|
||||
static integer *nn;
|
||||
flag__ = (logical *)malloc(*n*sizeof(logical));
|
||||
membr = (doublereal *)malloc(*n*sizeof(doublereal));
|
||||
disnn = (doublereal *)malloc(*n*sizeof(doublereal));
|
||||
nn = (integer *)malloc(*n*sizeof(integer));
|
||||
flag__ = (logical *)malloc(*n * sizeof(logical));
|
||||
membr = (doublereal *)malloc(*n * sizeof(doublereal));
|
||||
disnn = (doublereal *)malloc(*n * sizeof(doublereal));
|
||||
nn = (integer *)malloc(*n * sizeof(integer));
|
||||
|
||||
/* Parameter adjustments */
|
||||
--crit;
|
||||
@@ -30,8 +29,8 @@ doublereal *crit;
|
||||
--d__;
|
||||
|
||||
/* Function Body */
|
||||
hc_(n, len, iopt, &ia[1], &ib[1], &crit[1], membr, nn, disnn, flag__, &
|
||||
d__[1]);
|
||||
hc_(n, len, iopt, &ia[1], &ib[1], &crit[1], membr, nn, disnn, flag__,
|
||||
&d__[1]);
|
||||
|
||||
free(membr);
|
||||
free(nn);
|
||||
@@ -39,4 +38,3 @@ doublereal *crit;
|
||||
free(flag__);
|
||||
return 0;
|
||||
} /* distdriver_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user