for (i=0; i<4; i++) {

**// FOR THE FOUR VERTICES OF QUAD.**
**// disk coordinates**
p_d[n].x = b2[i] * cos(a2[i]) + x0;

p_d[n].y = b2[i] * sin(a2[i]) + y0;

**// calcuate texture coordinates**
AziCalc (lat_p, long_p, b2[i], a2[i], p_d[n].x, R);

p_d[n].u = 0.5 - longitude/PI2;

p_d[n].v = latitude/PI;

**// I HAD THE TEXTURE WRAPPING CODE HERE!**
n++;

}

**// THE CODE SHOULD HAVE BEEN HERE!**
// Wrap bad texture coordinates

getmax2(n-4, n-1, &max, &index); //get max value for last quad

getmin2(n-4, n-1, &min, &index); //get min value for last quad

while (max - min > 0.5){ // if texture coordinates too far apart

p_d[index].u += 1; //wrap coordinates

getmax2(n-4, n-1, &min, &index); //get max value for last quad

getmin2(n-4, n-1, &min, &index); //get min value for last quad

}

}