function nearest_valid_depth_value, val, dim if (N_elements(dim) eq 0) then return, val ; assume that topgrid is the first one return, DOUBLE(ROUND((val * dim) > 1 ))/dim end