From f2a1ec627ce69171ddf001cac52eac78e3359154 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Wed, 28 Feb 2024 22:01:30 +0100 Subject: [PATCH] Move code to new function `copy_shift` Preparing for more complex association criterium. --- Overlap/CMakeLists.txt | 5 +++-- Overlap/copy_shift.f90 | 30 ++++++++++++++++++++++++++++++ Overlap/overlap.f90 | 15 +++++---------- 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 Overlap/copy_shift.f90 diff --git a/Overlap/CMakeLists.txt b/Overlap/CMakeLists.txt index 9ca60079..2303bb2a 100644 --- a/Overlap/CMakeLists.txt +++ b/Overlap/CMakeLists.txt @@ -7,7 +7,8 @@ if(MPI_Fortran_HAVE_F08_MODULE) add_executable(eddy_graph eddy_graph.f90 get_snapshot.f90 overlap.f90 dispatch_snapshot.f90 recv_snapshot.f90 candidate_overlap.f90 spher_polygon_area.f90 send_snapshot.f90 unit_edge_m.f90 config_graph.F90 - read_grid.F90 read_snapshot.f90 read_eddy.f90 inters_lines.f90) + read_grid.F90 read_snapshot.f90 read_eddy.f90 inters_lines.f90 + copy_shift.f90) target_link_libraries(eddy_graph PRIVATE EZMPI::ezmpi Jumble::jumble Shapelib_03::shapelib_03 Contour_531::contour_531 gpc_f Geometry::geometry MPI::MPI_Fortran Numer_Rec_95::numer_rec_95) @@ -21,7 +22,7 @@ endif() add_subdirectory(Tests) target_sources(test_overlap PRIVATE overlap.f90 spher_polygon_area.f90 candidate_overlap.f90 unit_edge_m.f90 config_graph.F90 read_grid.F90 - read_snapshot.f90 read_eddy.f90 inters_lines.f90) + read_snapshot.f90 read_eddy.f90 inters_lines.f90 copy_shift.f90) target_sources(test_spher_polygon_area PRIVATE spher_polygon_area.f90) target_sources(test_read_snapshot PRIVATE read_snapshot.f90 read_eddy.f90 read_grid.F90 config_graph.F90) diff --git a/Overlap/copy_shift.f90 b/Overlap/copy_shift.f90 new file mode 100644 index 00000000..0b0fb2da --- /dev/null +++ b/Overlap/copy_shift.f90 @@ -0,0 +1,30 @@ +module copy_shift_m + + implicit none + +contains + + function copy_shift(p, delta_long) + + ! Libraries: + use contour_531, only: polyline + use jumble, only: twopi + + type(polyline), intent(in):: p + real, intent(in):: delta_long ! difference in longitude, in rad + type(polyline) copy_shift + + !------------------------------------------------------------------ + + copy_shift%n_points = p%n_points + copy_shift%closed = p%closed + allocate(copy_shift%points(2, p%n_points)) + copy_shift%points(2, :) = p%points(2, :) + + ! Shift the longitudes of `p`: + copy_shift%points(1, :) = p%points(1, :) & + + floor(delta_long / twopi + 0.5) * twopi + + end function copy_shift + +end module copy_shift_m diff --git a/Overlap/overlap.f90 b/Overlap/overlap.f90 index 43fe5c77..06b70cf1 100644 --- a/Overlap/overlap.f90 +++ b/Overlap/overlap.f90 @@ -13,9 +13,9 @@ contains ! Libraries: use contour_531, only: polyline - use jumble, only: twopi use inters_lines_m, only: inters_lines + use copy_shift_m, only: copy_shift use candidate_overlap_m, only: candidate_overlap use config_graph_m, only: dist_lim, min_inters_speed use derived_types, only: snapshot @@ -86,19 +86,14 @@ contains ! Assertion: {e1%delta_out >= delta .or. e2%delta_in ! >= delta} + delta_long = e1%extr%coord(1) - e2%extr%coord(1) + if (e2%speed_cont%n_points /= 0) then - polyline_2 = e2%speed_cont%polyline + polyline_2 = copy_shift(e2%speed_cont%polyline, delta_long) else - polyline_2 = e2%out_cont%polyline + polyline_2 = copy_shift(e2%out_cont%polyline, delta_long) end if - delta_long = e1%extr%coord(1) - e2%extr%coord(1) - - ! Shift the longitudes of polyline_2 to values close to the - ! longitude of extremum i1: - polyline_2%points(1, :) = polyline_2%points(1, :) & - + floor(delta_long / twopi + 0.5) * twopi - assoc_eddies = inters_lines(polyline_1, polyline_2, & min_inters_speed) -- GitLab