座標をグリッドセル添字へ変換し、範囲外は端セルへ丸める。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_type), | intent(in) | :: | mesh | |||
| real(kind=dp), | intent(in) | :: | x | |||
| integer(kind=i32), | intent(in) | :: | axis |
pure integer(i32) function coord_to_cell(mesh, x, axis) result(idx) type(mesh_type), intent(in) :: mesh real(dp), intent(in) :: x integer(i32), intent(in) :: axis real(dp) :: u if (x <= mesh%grid_bb_min(axis)) then idx = 1_i32 return end if if (x >= mesh%grid_bb_max(axis)) then idx = mesh%grid_ncell(axis) return end if u = (x - mesh%grid_bb_min(axis))*mesh%grid_inv_cell(axis) idx = int(u, kind=i32) + 1_i32 if (idx < 1_i32) idx = 1_i32 if (idx > mesh%grid_ncell(axis)) idx = mesh%grid_ncell(axis) end function coord_to_cell