{
boolean in_write_mode;
int level,index;
int[] xp = new int[nDim];
int[] xr = new int[nDim];
GlobalObject gBody;
GlobalObject gCell;
Cell cell;
Body body;
while ( data.bodies_there < data.nbody) {
gBody = bodyTab[data.bodies_there++];
body = (Body) gBody.open( "r" );
intcoord(xp, body.pos);
try{
gBody.release();
}catch (AlephException e) {}
gCell = root;
level = iMax >> 1;
while (true) {
cell = (Cell) gCell.open( "r" );
in_write_mode = false;
index = subindex(xp, level);
level >>= 1;
if (cell.next[index] == null) {
try{
gCell.release();
}catch (AlephException e) {}
cell = (Cell) gCell.open( "w" );
in_write_mode = true;
if (cell.next[index] == null) {
cell.next[index] = gBody;
try{
gCell.release();
}catch (AlephException e) {}
break;
}
}
if (!cell.isCell(index)) {
if (!in_write_mode) {
try{
gCell.release();
}catch (AlephException e) {}
cell = (Cell) gCell.open( "w" );
}
if (!cell.isCell(index)) {
cell.next[index] = newCell(cell.next[index], level, data);
cell.markCell(index);
}
}
GlobalObject g = cell.next[index];
try{
gCell.release();
}catch (AlephException e) {}
gCell = g;
}