The function removes/introduces idx_grid depending on whether gval is a vector
(single-layer case) or a matrix (usually a multi-layer case). If idx_grid is missing
and gval is a matrix, it is assumed to contain all grid-points (including NAs)
The function also assigns dimension names in the order 'y', 'x' (unless otherwise
specified) for gdim, gres, and gyx.
res_tol is used to check if the resolution gres is consistent with the spacing
of the grid lines. Only the spacing of the first two lines is computed - if the
relative error along either dimensions is greater res_tol, the function throws
an error.