Removed old unused code (jozov_persistent). Activated jozov2 cleaned implementation of jozov in C++.

This commit is contained in:
Guilhem Lavaux 2013-04-01 09:02:59 -04:00
parent 6a15e59521
commit 60e692a0cb
3 changed files with 96 additions and 617 deletions

81
c_tools/zobov2/findrtop.c Normal file
View file

@ -0,0 +1,81 @@
#include <math.h>
#include <stdlib.h>
/*------------------------------------------------------------------------------
Find nb elements of Real array a having the largest value.
Returns index iord of these elements, ordered so iord[0] corresponds
to element a[iord[0]] having the largest value.
If nb > na, then the last nb-na elements of iord are undefined.
Elements of a that are equal are left in their original order.
Courtesy Andrew Hamilton.
*/
void findrtop(double *a, int na, int *iord, int nb)
{
#undef ORDER
#define ORDER(ia, ja) a[ia] > a[ja] || (a[ia] == a[ja] && ia < ja)
int i, ia, ib, it, n;
n = (na <= nb)? na : nb;
if (n <= 0) return;
/* heap first n elements, so smallest element is at top of heap */
for (ib = (n >> 1); ib < n; ib++) {
iord[ib] = ib;
}
for (ia = (n >> 1) - 1; ia >= 0; ia--) {
i = ia;
for (ib = (i << 1) + 1; ib < n; ib = (i << 1) + 1) {
if (ib+1 < n) {
if (ORDER(iord[ib], iord[ib+1])) ib++;
}
if (ORDER(ia, iord[ib])) {
iord[i] = iord[ib];
i = ib;
} else {
break;
}
}
iord[i] = ia;
}
/* now compare rest of elements of array to heap */
for (ia = n; ia < na; ia++) {
/* if new element is greater than smallest, sift it into heap */
i = 0;
if (ORDER(ia, iord[i])) {
for (ib = (i << 1) + 1; ib < n; ib = (i << 1) + 1) {
if (ib+1 < n) {
if (ORDER(iord[ib], iord[ib+1])) ib++;
}
if (ORDER(ia, iord[ib])) {
iord[i] = iord[ib];
i = ib;
} else {
break;
}
}
iord[i] = ia;
}
}
/* unheap iord so largest element is at top */
for (ia = n - 1; ia > 0; ia--) {
it = iord[ia];
i = 0;
iord[ia] = iord[i];
for (ib = (i << 1) + 1; ib < ia; ib = (i << 1) + 1) {
if (ib+1 < ia) {
if (ORDER(iord[ib], iord[ib+1])) ib++;
}
if (ORDER(it, iord[ib])) {
iord[i] = iord[ib];
i = ib;
} else {
break;
}
}
iord[i] = it;
}
}

View file

@ -391,28 +391,28 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
inyet2 = new char[numZones];
zonelist = new int[numZones];
zonelist2 = new int[numZones];
done_zones = new bool[nzones];
done_zones = new bool[numZones];
fill(inyet, inyet + numZones, 0);
fill(inyet2, inyet2 + numZones, 0);
fill(done_zones, done_zones + numZones, false);
sorter = new double[nzones+1];
double *sorter = new double[numZones+1];
/* Assign sorter by probability (could use volume instead) */
for (int h = 0; h < nzones; h++)
for (int h = 0; h < numZones; h++)
sorter[h] = (double)z[h].core;
/* Text output file */
printf("about to sort (pre-watershed sort) ...\n");FF;
iord = new int[nzones];
iord = new int[numZones];
findrtop(sorter, numZones, iord, numZones);
delete[] sorter;
nhl = 0;
for (int ii = 0; ii < numZones; h++)
for (int ii = 0; ii < numZones; ii++)
{
int nhlcount = 0;
int h = iord[ii];
@ -580,11 +580,18 @@ void doWatershed(const std::string& zonfile2, PARTICLE *p, pid_t np, ZONE *z, in
done_zones[h] = true;
z[h].nhl = nhl;
zon2.write((char *)&nhl, sizeof(int));
zon2.write((char *)zonelist, nhl*sizeof(int));
}
delete[] zonelist;
delete[] zonelist2;
delete[] links;
delete[] iord;
cout << "Writing void/zone relations..." << endl;
for (int h = 0; h < numZones; h++)
{
zon2.write((char *)&z[h].nhl, sizeof(int));
zon2.write((char *)z[h].zonelist, z[h].nhl*sizeof(int));
}
cout << format("Maxdenscontrast = %f.") % maxdenscontrast << endl;
}