Spherical Overdensity is a very simple scheme for automatic detection of dark matter halos in N body simulations. It was first described in Lacey & Cole (1992) and is now widely used in the community. The algorithm performs the following operation. 1- Particles are sorted in decreasing order according to their local density. The density of each particle can be computed using any sensible method (grid-based like CIC or SPH-based). 2- The densest particle in the list is considered as a first guess for the center of mass of the halo candidate. A sphere of increasing radius is built around this fixed centre, until the average density reaches Delta in units of the mean background density. Delta is usually taken equal to 600. 3- A new center of mass is computed using all particles in the sphere and the process is iterated again, until the position of the center of mass has converged. 4- All particles belonging to the final halo are removed from the density list, and the whole process is started again.
Here is a F90 code that applies the Spherical Overdensity detection method to particle files in the RAMSES format. It is self-documented. To compile, type "f90 sod.f90 -o sod".
Here is a F90 code that applies the Spherical Overdensity detection method to particle files in the GADGET format.