Implementation of the cal2-algorithm with three different versions: