SUBMODULE(compute_caldyn_mod) compute_planetvel_mod
   IMPLICIT NONE

CONTAINS

   MODULE SUBROUTINE compute_planetvel(planetvel)
      REAL(rstd), INTENT(OUT)  :: planetvel(:)
      CALL compute_planetvel_hex(planetvel)
   END SUBROUTINE

   SUBROUTINE compute_planetvel_hex(planetvel)
      USE wind_from_lonlat_mod, ONLY: compute_wind2D_perp_from_lonlat_compound
      USE icosa
      REAL(rstd), INTENT(OUT)  :: planetvel(iim*3*jjm)
      REAL(rstd) :: ulon(iim*3*jjm)
      REAL(rstd) :: ulat(iim*3*jjm)
      REAL(rstd) :: lon, lat
      INTEGER :: ij
      DO ij = ij_begin_ext, ij_end_ext
         ulon(ij + u_right) = radius*omega*cos(lat_e(ij + u_right))
         ulat(ij + u_right) = 0

         ulon(ij + u_lup) = radius*omega*cos(lat_e(ij + u_lup))
         ulat(ij + u_lup) = 0

         ulon(ij + u_ldown) = radius*omega*cos(lat_e(ij + u_ldown))
         ulat(ij + u_ldown) = 0
      END DO
      CALL compute_wind2D_perp_from_lonlat_compound(ulon, ulat, planetvel)
   END SUBROUTINE compute_planetvel_hex

END SUBMODULE
