code to compute unit boundaries and allocation function