Skip to content

Commit

Permalink
Some code cleanup:
Browse files Browse the repository at this point in the history
- remove unused variables
- add some explicit type conversions
  • Loading branch information
micaeljtoliveira committed Sep 18, 2024
1 parent e1374f5 commit 4ed7ff7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/gen_topo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subroutine gen_topo(topo_file, out_file, grid_file, istripolar, offset)
logical, intent(in) :: istripolar
real(real32), intent(in) :: offset

integer(int32) :: i, j, k
integer(int32) :: i, j
integer(int32) :: nx, ny ! Size of model grid
integer(int32) :: nxp, nyp ! Size of model supergrid
integer(int32) :: nxt, nyt ! Size of model T grid
Expand All @@ -40,8 +40,8 @@ subroutine gen_topo(topo_file, out_file, grid_file, istripolar, offset)
integer(int32) :: dids(2) ! NetCDF ids
integer(int32) :: dids_topo(2) ! NetCDF ids

real(real64), allocatable :: wrk(:,:), wrk_super(:,:)
real(real64), allocatable :: x_c(:,:), y_c(:,:), x_t(:,:), y_t(:,:), area(:,:)
real(real64), allocatable :: wrk_super(:,:)
real(real64), allocatable :: x_c(:,:), y_c(:,:), x_t(:,:), y_t(:,:)
real(real64), allocatable :: xtopo(:), ytopo(:), weight(:), x_rot(:)
real(real32), allocatable :: topo_in(:,:), topo_out(:,:), topo_all_out(:,:), frac(:,:)
real(real32), allocatable :: topo_med_out(:,:), topo_all_med_out(:,:)
Expand All @@ -50,7 +50,7 @@ subroutine gen_topo(topo_file, out_file, grid_file, istripolar, offset)

integer(int32) :: ishift

integer(int32) :: x_cyc, j_lat
integer(int32) :: j_lat

integer(int32) :: xlen, ylen

Expand All @@ -65,8 +65,7 @@ subroutine gen_topo(topo_file, out_file, grid_file, istripolar, offset)
real(real64) :: xstart, ystart
real(real64) :: xend, yend

real(real64) :: xt_start, xt_delta
real(real64) :: yt_start, yt_delta
real(real64) :: xt_delta, yt_delta

!
! On mosaic "supergrid" we need to get every second point
Expand Down Expand Up @@ -338,7 +337,7 @@ subroutine get_topo_data(ncid, hid, istart, jstart, iend, jend, ishift, xlen, xp
real(real32), allocatable, intent(out) :: topo(:, :)

integer(int32) :: icount, jcount
integer(int32) :: listart, liend, licount, licount1, licount2
integer(int32) :: listart, liend, licount1, licount2
integer(int32) :: n
integer(int16), allocatable :: itopo(:,:)

Expand Down Expand Up @@ -390,7 +389,8 @@ subroutine get_range(vals, lower, upper, index_lo, index_hi)
real(real64), intent(in) :: lower, upper
integer(int32), intent(out) :: index_lo, index_hi

integer(int32) :: itmp, imx, imn, its, itsmax = 20
integer(int32) :: imx, imn, its
integer(int32), parameter :: itsmax = 20

imn = 1
imx = size(vals)
Expand Down Expand Up @@ -462,7 +462,7 @@ subroutine make_topo_gen(topo_in, x_in, y_in, topo_out, x_out, y_out, topo_all_o

logical, allocatable :: mask(:,:)

integer :: im, it, jm, jt, inext, jnext, itopo, jtopo
integer :: im, it, jm, jt

! tree stuff
real(kdkind), allocatable :: possie(:,:)
Expand All @@ -471,7 +471,7 @@ subroutine make_topo_gen(topo_in, x_in, y_in, topo_out, x_out, y_out, topo_all_o
real(kdkind) :: t_source(3), xt, yt, rad2
type(kdtree2), pointer :: tree
type(kdtree2_result), allocatable :: results(:)
real(int32), allocatable :: idx(:), jdx(:)
integer(int32), allocatable :: idx(:), jdx(:)
real(real64), parameter :: DEG2RAD = asin(1.0_real64)/90.0_real64 ! PI/180
integer(int32) :: num_found, n, ngd, num_max
real(real32), allocatable :: t_s(:), t_s_all(:)
Expand Down
18 changes: 5 additions & 13 deletions src/topography.f90
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ subroutine topography_write(this, filename)
class(topography_t), intent(in) :: this
character(len=*), intent(in) :: filename

integer(int32) :: ncid, depth_id, frac_id, geolon_id, geolat_id, dids(2) ! NetCDF ids
integer(int32) :: ncid, depth_id, frac_id, dids(2) ! NetCDF ids

write(output_unit,'(3a)') "Writing topography to file '", trim(filename), "'"

Expand Down Expand Up @@ -228,7 +228,7 @@ subroutine topography_number_seas(this, sea_number, number_of_seas, silent)
integer(int32), intent(out), optional :: number_of_seas
logical, intent(in), optional :: silent

integer(int32) :: i, j, counter, its, its1, its2, sea_num
integer(int32) :: i, j, counter, its, sea_num
integer(int32) :: im, ip, jm, jp, land

integer(int16) :: new_sea
Expand Down Expand Up @@ -440,19 +440,13 @@ subroutine topography_min_max_depth(this, vgrid_file, vgrid_type, level)
integer, intent(in) :: level

integer(int32) :: i,j
integer(int32) :: im,ip,jm,jp

integer(int32) :: ncid_lev, lev_id ! NetCDF ids
integer(int32) :: dids_lev(1) ! NetCDF ids
integer(int32) :: zlen ! length of zeta array

type(vgrid_t) :: vgrid

this%min_level = level

vgrid = vgrid_t(vgrid_file, vgrid_type)
this%min_depth = vgrid%zeta(this%min_level)
this%max_depth = vgrid%zeta(vgrid%nlevels)
this%min_depth = real(vgrid%zeta(this%min_level), real32)
this%max_depth = real(vgrid%zeta(vgrid%nlevels), real32)

write(output_unit,'(a,f7.2,a)') 'Setting minimum depth to ', this%min_depth, ' m'
write(output_unit,'(a,f7.2,a)') 'Setting maximum depth to ', this%max_depth, ' m'
Expand Down Expand Up @@ -507,9 +501,7 @@ subroutine topography_nonadvective(this, vgrid_file, vgrid_type, potholes, coast
type(vgrid_t) :: vgrid
integer(int32), allocatable :: num_levels(:,:)
real(real32), allocatable :: zw(:)
integer(int32) :: passes, i, j, k, ni, nj, its, coastal_counter, potholes_counter
integer(int32) :: ncid, vid
integer(int32) :: dids(2)
integer(int32) :: passes, i, j, k, its, coastal_counter, potholes_counter
logical :: se, sw, ne, nw ! .TRUE. if C-cell centre is shallower than T cell centre.
logical :: changes_made = .false.
integer(int32) :: kse, ksw, kne, knw, kmu_max
Expand Down

0 comments on commit 4ed7ff7

Please sign in to comment.