tested modified flatten_ongrid.m on cluster