|
Sure...
MAIN:
posb=0;posa=0,pts=0, totalpts=0;
while(pts<nptsa+nptsb)
{
blksize = 0;
// Extract stationing into temporary block
exrtact_sta(b, a, stablk, &posb, &posa, &blksize);
pts+= blksize;
// Calc area of cut and fill for the chunk
for(i=0;i<10;++i) //initialize
{
current.cut[i]=0;
current.fill[i]=0;
}
cut=0;fill=0;
area_coords(stablk, blksize, current); //calcs the areas of cut/fill
for(i=0;i<10;++i)
{
cut += current.cut[i];
fill += current.fill[i]=0;
}
// Move current station area data to previous (for computation of next volume)
previous.sta = current.sta;
for(i=0;i<10;++i)
{
previous.cut[i]=0;
previous.fill[i]=0;
}
for(i=0;i<10;++i)
{
previous.cut[i] = current.cut[i];
previous.fill[i] = current.fill[i];
}
}//end for loop
FUNCTION:
void area_coords(DATA stablk[100], int blksize, AREA current)
{
double area, one, two;
int i, j, k, m, n, cfflag;
one=0; two=0, j=0, k=0, m=0,n=0;
// Find first inflection point and calc area to second inflection point
for(i=0;i<blksize;++i)
{
if(stablk[i].flag1==0 && stablk[i].flag2==0)
{
j=i;
if(stablk[i+1].z1>stablk[i+1].z2)
cfflag=1;
else if(stablk[i+1].z1<stablk[i+1].z2)
cfflag=0;
one += stablk[j].off * stablk[j+1].z1;
two += stablk[j+1].off * stablk[j].z1;
++j;
while(stablk[j].flag1!=0 && stablk[j].flag2!=0)
{
one += stablk[j].off * stablk[j+1].z1;
two += stablk[j+1].off * stablk[j].z1;
++j;
}
k=j;
while(j>i)
{
one += stablk[j].off * stablk[j-1].z2;
two += stablk[j-1].off * stablk[j].z2;
--j;
}
area=(one-two)/2;
if(area<0)
area=area*-1;
// Determine if area goes to cut or fill
current.sta = stablk[i].sta;
if(cfflag == 1)
{
current.cut[m] = area;
++m;
}
if(cfflag == 0)
{
current.fill[n] = area;
++n;
}
i=k;
}
// Update i to start calcing area from next infelction point
}
}
|