diff --git a/Inst_eddies/set_max_speed.f90 b/Inst_eddies/set_max_speed.f90 index 750ee87aa824a276bff1d2ee735f82835370db1e..16d0776f87945bab75b2e413dbc5c4363ac5eb22 100644 --- a/Inst_eddies/set_max_speed.f90 +++ b/Inst_eddies/set_max_speed.f90 @@ -91,23 +91,34 @@ contains else e%speed_cont%polyline = good_contour(corner, step, ssh, & e%speed_cont%ssh, e%coord_extr, outside_points) - e%max_speed = mean_speed(u, v, e%speed_cont%polyline, e%coord_extr, & - corner, step) - if (IEEE_IS_NAN(speed_outerm)) then - ! This may happen when the outermost contour is near land. - ! Stick to the contour coming from max_speed_contour_ssh. - e%speed_cont%area = spher_polyline_area(e%speed_cont%polyline) + if (e%speed_cont%n_points == 0) then + ! This may happen if there is the exact same value of ssh + ! next to the extremum and this value is + ! e%speed_cont%ssh. + e%speed_cont%ssh = missing_ssh + e%speed_cont%area = - 1e6 + e%max_speed = speed_outerm else - ! Note the following test should raise an invalid exception - ! if e%max_speed is NaN. - if (abs(speed_outerm) > abs(e%max_speed)) then - ! Abandon the contour coming from max_speed_contour_ssh: - e%speed_cont = null_ssh_contour() - e%max_speed = speed_outerm - else + e%max_speed = mean_speed(u, v, e%speed_cont%polyline, & + e%coord_extr, corner, step) + + if (IEEE_IS_NAN(speed_outerm)) then + ! This may happen when the outermost contour is near land. ! Stick to the contour coming from max_speed_contour_ssh. e%speed_cont%area = spher_polyline_area(e%speed_cont%polyline) + else + ! Note the following test should raise an invalid exception + ! if e%max_speed is NaN. + if (abs(speed_outerm) > abs(e%max_speed)) then + ! Abandon the contour coming from max_speed_contour_ssh: + e%speed_cont = null_ssh_contour() + e%max_speed = speed_outerm + else + ! Stick to the contour coming from max_speed_contour_ssh. + e%speed_cont%area & + = spher_polyline_area(e%speed_cont%polyline) + end if end if end if end if