range_mat to shape_mat on line 163 in R Prog