adapt ben's code to the matrix structure
ben's algo
first try at using oni files, not working atm : segfault to inspect