Skip to content
Snippets Groups Projects
Commit 8fe2368c authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Move pack_indices out of the project to NR_util.

Choose longitude and latitude window at run-time in test_local_extrema.
parent 319fdb13
No related branches found
No related tags found
No related merge requests found
...@@ -10,34 +10,42 @@ program test_local_extrema ...@@ -10,34 +10,42 @@ program test_local_extrema
implicit none implicit none
integer, parameter:: ilon_llc = 21, ilat_llc = 215 ! lower left corner integer:: ilon_llc = 21, ilat_llc = 215 ! lower left corner
integer, parameter:: ilon_urc = 49, ilat_urc = 231 ! upper right corner integer:: ilon_urc = 49, ilat_urc = 231 ! upper right corner
integer, parameter:: nlon = ilon_urc - ilon_llc + 1 integer nlon, nlat
integer, parameter:: nlat = ilat_urc - ilat_llc + 1
integer ncid, varid, dimid_lat, dimid_lon integer ncid, varid, dimid_lat, dimid_lon
integer varid_lat, varid_lon, varid_extr_map integer varid_lat, varid_lon, varid_extr_map
integer i, length, status, unit integer i, length, status, unit
character(len = :), allocatable:: filename character(len = :), allocatable:: filename
real longitude(nlon), latitude(nlat) ! in degrees real, allocatable:: longitude(:) ! (nlon) in degrees
real ssh(nlon, nlat) ! sea-surface height, in m real, allocatable:: latitude(:) ! (nlat) in degrees
real, allocatable:: ssh(:, :) ! (nlon, nlat) sea-surface height, in m
integer, allocatable:: extr_map(:, :) ! (nlon, nlat) map of extrema
integer, allocatable:: ind_extr(:, :) ! (2, n_extr) integer, allocatable:: ind_extr(:, :) ! (2, n_extr)
! indices in the two dimensions of extrema ! indices in the two dimensions of extrema
integer extr_map(nlon, nlat) ! map of extrema
real, allocatable:: innermost_level(:) ! (n_extr) real, allocatable:: innermost_level(:) ! (n_extr)
! level of innermost contour, for each extremum ! level of innermost contour, for each extremum
logical, allocatable:: cyclone(:) ! (n_extr) logical, allocatable:: cyclone(:) ! (n_extr)
namelist /main_nml/ ilon_llc, ilat_llc, ilon_urc, ilat_urc
!--------------------------------------------------------------------- !---------------------------------------------------------------------
call get_command_argument(1, length = length, status = status) call get_command_argument(number = 1, length = length, status = status)
call assert(status == 0, "Required argument: ADT file") call assert(status == 0, "Required argument: ADT file")
allocate(character(len = length):: filename) allocate(character(len = length):: filename)
call get_command_argument(1, filename) call get_command_argument(1, filename)
print *, "Enter namelist main_nml."
read(unit = *, nml = main_nml)
nlon = ilon_urc - ilon_llc + 1
nlat = ilat_urc - ilat_llc + 1
allocate(longitude(nlon), latitude(nlat))
allocate(ssh(nlon, nlat), extr_map(nlon, nlat))
call nf95_open(filename, nf90_nowrite, ncid) call nf95_open(filename, nf90_nowrite, ncid)
...@@ -70,7 +78,7 @@ program test_local_extrema ...@@ -70,7 +78,7 @@ program test_local_extrema
end do end do
close(unit) close(unit)
print *, 'Created file "test_local_extrema.csv".' print *, 'Created file "test_local_extrema.csv".'
call nf95_create("test_local_extrema.nc", NF90_CLOBBER, ncid) call nf95_create("test_local_extrema.nc", NF90_CLOBBER, ncid)
call nf95_def_dim(ncid, "lat", nlat, dimid_lat) call nf95_def_dim(ncid, "lat", nlat, dimid_lat)
...@@ -79,11 +87,11 @@ program test_local_extrema ...@@ -79,11 +87,11 @@ program test_local_extrema
call nf95_def_var(ncid, "lat", NF90_FLOAT, dimid_lat, varid_lat) call nf95_def_var(ncid, "lat", NF90_FLOAT, dimid_lat, varid_lat)
call nf95_put_att(ncid, varid_lat, "standard_name", "latitude") call nf95_put_att(ncid, varid_lat, "standard_name", "latitude")
call nf95_put_att(ncid, varid_lat, "units", "degrees_north") call nf95_put_att(ncid, varid_lat, "units", "degrees_north")
call nf95_def_var(ncid, "lon", NF90_FLOAT, dimid_lon, varid_lon) call nf95_def_var(ncid, "lon", NF90_FLOAT, dimid_lon, varid_lon)
call nf95_put_att(ncid, varid_lon, "standard_name", "longitude") call nf95_put_att(ncid, varid_lon, "standard_name", "longitude")
call nf95_put_att(ncid, varid_lon, "units", "degrees_east") call nf95_put_att(ncid, varid_lon, "units", "degrees_east")
call nf95_def_var(ncid, "extr_map", NF90_INT, [dimid_lon, dimid_lat], & call nf95_def_var(ncid, "extr_map", NF90_INT, [dimid_lon, dimid_lat], &
varid_extr_map) varid_extr_map)
......
...@@ -12,11 +12,11 @@ if len(sys.argv) != 2: sys.exit("Required argument: ADT file") ...@@ -12,11 +12,11 @@ if len(sys.argv) != 2: sys.exit("Required argument: ADT file")
f= netCDF4.Dataset(sys.argv[1]) f= netCDF4.Dataset(sys.argv[1])
# Lower left corner (llc): # Lower left corner (llc):
ilon_llc = np.searchsorted(f.variables["lon"], 5) ilon_llc = np.searchsorted(f.variables["lon"], 6.125)
ilat_llc = np.searchsorted(f.variables["lat"], -36.5) ilat_llc = np.searchsorted(f.variables["lat"], -38.125)
# Upper right corner (urc): # Upper right corner (urc):
ilon_urc = np.searchsorted(f.variables["lon"], 12) ilon_urc = np.searchsorted(f.variables["lon"], 12.625)
ilat_urc = np.searchsorted(f.variables["lat"], -32.5) ilat_urc = np.searchsorted(f.variables["lat"], -34.125)
print("ilon_llc = ", ilon_llc) print("ilon_llc = ", ilon_llc)
print("ilat_llc = ", ilat_llc) print("ilat_llc = ", ilat_llc)
......
...@@ -9,7 +9,9 @@ src_tests_dir=~/Documents/Informatique_fonctionnement/Programs/Detection_eddies/ ...@@ -9,7 +9,9 @@ src_tests_dir=~/Documents/Informatique_fonctionnement/Programs/Detection_eddies/
$compil_prod_dir/test_good_contour $compil_prod_dir/test_good_contour
$compil_prod_dir/test_local_extrema h_2006_01_01.nc $compil_prod_dir/test_local_extrema h_2006_01_01.nc <<EOF
&main_nml /
EOF
$src_tests_dir/test_local_extrema.py h_2006_01_01.nc $src_tests_dir/test_local_extrema.py h_2006_01_01.nc
$compil_prod_dir/test_inside $compil_prod_dir/test_inside
......
...@@ -9,12 +9,12 @@ contains ...@@ -9,12 +9,12 @@ contains
use contour_531, only: convert_to_reg_coord, convert_to_ind use contour_531, only: convert_to_reg_coord, convert_to_ind
use derived_types, only: eddy use derived_types, only: eddy
use get_outermost_contour_m, only: get_outermost_contour
use good_contour_m, only: good_contour use good_contour_m, only: good_contour
use max_speed_contour_ssh_m, only: max_speed_contour_ssh use max_speed_contour_ssh_m, only: max_speed_contour_ssh
use mean_speed_m, only: mean_speed use mean_speed_m, only: mean_speed
use get_outermost_contour_m, only: get_outermost_contour use nr_util, only: pack_indices
use outermost_possible_level_m, only: outermost_possible_level use outermost_possible_level_m, only: outermost_possible_level
use pack_indices_m, only: pack_indices
use spherical_polygon_area_m, only: spherical_polygon_area use spherical_polygon_area_m, only: spherical_polygon_area
real, intent(in):: ssh(:, :), u(:, :), v(:, :) real, intent(in):: ssh(:, :), u(:, :), v(:, :)
......
module pack_indices_m
implicit none
contains
pure function pack_indices(my_array, excluded)
! Returns the indices of the elements not excluded in my_array.
integer, allocatable:: pack_indices(:, :) ! (2, n_packed)
integer, intent(in):: my_array(:, :) ! (m, :)
integer, intent(in):: excluded(:) ! excluded values of my_array
! Local:
integer n_packed, i, j, m
integer t(2, size(my_array)) ! Maximum number of packed elements is m * n.
!---------------------------------------------------------------
m = size(my_array, 1)
n_packed = 0
do j = 1, size(my_array, 2)
do i = 1, m
if (all(my_array(i, j) /= excluded)) then
n_packed = n_packed + 1
t(:, n_packed) = [i, j]
end if
end do
end do
pack_indices = t(:, :n_packed)
end function pack_indices
end module pack_indices_m
dispatch_snapshot.o : write_eddy.o send_snapshot.o derived_types.o dispatch_snapshot.o : write_eddy.o send_snapshot.o derived_types.o
get_eddy.o : spherical_polygon_area.o pack_indices.o outermost_possible_level.o get_outermost_contour.o mean_speed.o max_speed_contour_ssh.o good_contour.o derived_types.o get_eddy.o : spherical_polygon_area.o outermost_possible_level.o mean_speed.o max_speed_contour_ssh.o good_contour.o get_outermost_contour.o derived_types.o
get_snapshot.o : receive_snapshot.o local_extrema.o get_eddy.o derived_types.o get_snapshot.o : receive_snapshot.o local_extrema.o get_eddy.o derived_types.o
max_speed_contour_ssh.o : inside.o max_speed_contour_ssh.o : inside.o
get_outermost_contour.o : spherical_polygon_area.o derived_types.o good_contour.o get_outermost_contour.o : spherical_polygon_area.o derived_types.o good_contour.o
......
...@@ -9,7 +9,6 @@ max_speed_contour_ssh.f ...@@ -9,7 +9,6 @@ max_speed_contour_ssh.f
mean_speed.f mean_speed.f
get_outermost_contour.f get_outermost_contour.f
outermost_possible_level.f outermost_possible_level.f
pack_indices.f
receive_snapshot.f receive_snapshot.f
send_snapshot.f send_snapshot.f
spherical_polygon_area.f spherical_polygon_area.f
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment