MODULE geo2ocean !!====================================================================== !! *** MODULE geo2ocean *** !! Ocean mesh : ??? !!===================================================================== !!---------------------------------------------------------------------- !! repcmo : !! angle : !! geo2oce : !! repere : old routine suppress it ??? !!---------------------------------------------------------------------- !! * Modules used USE dom_oce ! mesh and scale factors USE phycst ! physical constants USE in_out_manager ! I/O manager USE lbclnk ! ocean lateral boundary conditions (or mpp link) IMPLICIT NONE !! * Accessibility PRIVATE PUBLIC rot_rep, repcmo, repere, geo2oce ! only rot_rep should be used ! repcmo and repere are keep only for compatibility. ! they are only a useless overlay of rot_rep !! * Module variables REAL(wp), DIMENSION(jpi,jpj) :: & gsint, gcost, & ! cos/sin between model grid lines and NP direction at T point gsinu, gcosu, & ! cos/sin between model grid lines and NP direction at U point gsinv, gcosv, & ! cos/sin between model grid lines and NP direction at V point gsinf, gcosf ! cos/sin between model grid lines and NP direction at F point LOGICAL :: lmust_init = .TRUE. !: used to initialize the cos/sin variables (se above) !! * Substitutions # include "vectopt_loop_substitute.h90" !!--------------------------------------------------------------------------------- !! OPA 9.0 , LOCEAN-IPSL (2005) !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/geo2ocean.F90,v 1.7 2007/06/29 14:23:06 opalod Exp $ !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt !!--------------------------------------------------------------------------------- CONTAINS SUBROUTINE repcmo ( pxu1, pyu1, pxv1, pyv1, & px2 , py2 ) !!---------------------------------------------------------------------- !! *** ROUTINE repcmo *** !! !! ** Purpose : Change vector componantes from a geographic grid to a !! stretched coordinates grid. !! !! ** Method : Initialization of arrays at the first call. !! !! ** Action : - px2 : first componante (defined at u point) !! - py2 : second componante (defined at v point) !! !! History : !! 7.0 ! 07-96 (O. Marti) Original code !! 8.5 ! 02-08 (G. Madec) F90: Free form !!---------------------------------------------------------------------- !! * Arguments REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) :: & pxu1, pyu1, & ! geographic vector componantes at u-point pxv1, pyv1 ! geographic vector componantes at v-point REAL(wp), INTENT( out ), DIMENSION(jpi,jpj) :: & px2, & ! i-componante (defined at u-point) py2 ! j-componante (defined at v-point) !!---------------------------------------------------------------------- ! Change from geographic to stretched coordinate ! ---------------------------------------------- CALL rot_rep( pxu1, pyu1, 'U', 'en->i',px2 ) CALL rot_rep( pxv1, pyv1, 'V', 'en->j',py2 ) END SUBROUTINE repcmo SUBROUTINE rot_rep ( pxin, pyin, cd_type, cdtodo, prot ) !!---------------------------------------------------------------------- !! *** ROUTINE rot_rep *** !! !! ** Purpose : Rotate the Repere: Change vector componantes between !! geographic grid <--> stretched coordinates grid. !! !! History : !! 9.2 ! 07-04 (S. Masson) !! (O. Marti ) Original code (repere and repcmo) !!---------------------------------------------------------------------- !! * Arguments REAL(wp), DIMENSION(jpi,jpj), INTENT( IN ) :: pxin, pyin ! vector componantes CHARACTER(len=1), INTENT( IN ) :: cd_type ! define the nature of pt2d array grid-points CHARACTER(len=5), INTENT( IN ) :: cdtodo ! specify the work to do: !! ! 'en->i' east-north componantes to model i componante !! ! 'en->j' east-north componantes to model j componante !! ! 'ij->e' model i-j componantes to east componante !! ! 'ij->n' model i-j componantes to east componante REAL(wp), DIMENSION(jpi,jpj), INTENT(out) :: prot !!---------------------------------------------------------------------- ! Initialization of gsin* and gcos* at first call ! ----------------------------------------------- IF( lmust_init ) THEN IF(lwp) WRITE(numout,*) IF(lwp) WRITE(numout,*) ' rot_rep : geographic <--> stretched' IF(lwp) WRITE(numout,*) ' ~~~~~ coordinate transformation' CALL angle ! initialization of the transformation lmust_init = .FALSE. ENDIF SELECT CASE (cdtodo) CASE ('en->i') ! 'en->i' est-north componantes to model i componante SELECT CASE (cd_type) CASE ('T') ; prot(:,:) = pxin(:,:) * gcost(:,:) + pyin(:,:) * gsint(:,:) CASE ('U') ; prot(:,:) = pxin(:,:) * gcosu(:,:) + pyin(:,:) * gsinu(:,:) CASE ('V') ; prot(:,:) = pxin(:,:) * gcosv(:,:) + pyin(:,:) * gsinv(:,:) CASE ('F') ; prot(:,:) = pxin(:,:) * gcosf(:,:) + pyin(:,:) * gsinf(:,:) CASE DEFAULT ; CALL ctl_stop( 'Only T, U, V and F grid points are coded' ) END SELECT CASE ('en->j') ! 'en->j' est-north componantes to model j componante SELECT CASE (cd_type) CASE ('T') ; prot(:,:) = pyin(:,:) * gcost(:,:) - pxin(:,:) * gsint(:,:) CASE ('U') ; prot(:,:) = pyin(:,:) * gcosu(:,:) - pxin(:,:) * gsinu(:,:) CASE ('V') ; prot(:,:) = pyin(:,:) * gcosv(:,:) - pxin(:,:) * gsinv(:,:) CASE ('F') ; prot(:,:) = pyin(:,:) * gcosf(:,:) - pxin(:,:) * gsinf(:,:) CASE DEFAULT ; CALL ctl_stop( 'Only T, U, V and F grid points are coded' ) END SELECT CASE ('ij->e') ! 'ij->e' model i-j componantes to est componante SELECT CASE (cd_type) CASE ('T') ; prot(:,:) = pxin(:,:) * gcost(:,:) - pyin(:,:) * gsint(:,:) CASE ('U') ; prot(:,:) = pxin(:,:) * gcosu(:,:) - pyin(:,:) * gsinu(:,:) CASE ('V') ; prot(:,:) = pxin(:,:) * gcosv(:,:) - pyin(:,:) * gsinv(:,:) CASE ('F') ; prot(:,:) = pxin(:,:) * gcosf(:,:) - pyin(:,:) * gsinf(:,:) CASE DEFAULT ; CALL ctl_stop( 'Only T, U, V and F grid points are coded' ) END SELECT CASE ('ij->n') ! 'ij->n' model i-j componantes to est componante SELECT CASE (cd_type) CASE ('T') ; prot(:,:) = pyin(:,:) * gcost(:,:) + pxin(:,:) * gsint(:,:) CASE ('U') ; prot(:,:) = pyin(:,:) * gcosu(:,:) + pxin(:,:) * gsinu(:,:) CASE ('V') ; prot(:,:) = pyin(:,:) * gcosv(:,:) + pxin(:,:) * gsinv(:,:) CASE ('F') ; prot(:,:) = pyin(:,:) * gcosf(:,:) + pxin(:,:) * gsinf(:,:) CASE DEFAULT ; CALL ctl_stop( 'Only T, U, V and F grid points are coded' ) END SELECT CASE DEFAULT ; CALL ctl_stop( 'rot_rep: Syntax Error in the definition of cdtodo' ) END SELECT END SUBROUTINE rot_rep SUBROUTINE angle !!---------------------------------------------------------------------- !! *** ROUTINE angle *** !! !! ** Purpose : Compute angles between model grid lines and the North direction !! !! ** Method : !! !! ** Action : Compute (gsint, gcost, gsinu, gcosu, gsinv, gcosv, gsinf, gcosf) arrays: !! sinus and cosinus of the angle between the north-south axe and the !! j-direction at t, u, v and f-points !! !! History : !! 7.0 ! 96-07 (O. Marti ) Original code !! 8.0 ! 98-06 (G. Madec ) !! 8.5 ! 98-06 (G. Madec ) Free form, F90 + opt. !! 9.2 ! 07-04 (S. Masson) Add T, F points and bugfix in cos lateral boundary !!---------------------------------------------------------------------- !! * local declarations INTEGER :: ji, jj ! dummy loop indices REAL(wp) :: & zlam, zphi, & ! temporary scalars zlan, zphh, & ! " " zxnpt, zynpt, znnpt, & ! x,y components and norm of the vector: T point to North Pole zxnpu, zynpu, znnpu, & ! x,y components and norm of the vector: U point to North Pole zxnpv, zynpv, znnpv, & ! x,y components and norm of the vector: V point to North Pole zxnpf, zynpf, znnpf, & ! x,y components and norm of the vector: F point to North Pole zxvvt, zyvvt, znvvt, & ! x,y components and norm of the vector: between V points below and above a T point zxffu, zyffu, znffu, & ! x,y components and norm of the vector: between F points below and above a U point zxffv, zyffv, znffv, & ! x,y components and norm of the vector: between F points left and right a V point zxuuf, zyuuf, znuuf ! x,y components and norm of the vector: between U points below and above a F point !!---------------------------------------------------------------------- ! ============================= ! ! Compute the cosinus and sinus ! ! ============================= ! ! (computation done on the north stereographic polar plane) DO jj = 2, jpjm1 !CDIR NOVERRCHK DO ji = fs_2, jpi ! vector opt. ! north pole direction & modulous (at t-point) zlam = glamt(ji,jj) zphi = gphit(ji,jj) zxnpt = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) zynpt = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) znnpt = zxnpt*zxnpt + zynpt*zynpt ! north pole direction & modulous (at u-point) zlam = glamu(ji,jj) zphi = gphiu(ji,jj) zxnpu = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) zynpu = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) znnpu = zxnpu*zxnpu + zynpu*zynpu ! north pole direction & modulous (at v-point) zlam = glamv(ji,jj) zphi = gphiv(ji,jj) zxnpv = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) zynpv = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) znnpv = zxnpv*zxnpv + zynpv*zynpv ! north pole direction & modulous (at f-point) zlam = glamf(ji,jj) zphi = gphif(ji,jj) zxnpf = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) zynpf = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) znnpf = zxnpf*zxnpf + zynpf*zynpf ! j-direction: v-point segment direction (around t-point) zlam = glamv(ji,jj ) zphi = gphiv(ji,jj ) zlan = glamv(ji,jj-1) zphh = gphiv(ji,jj-1) zxvvt = 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) zyvvt = 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) znvvt = SQRT( znnpt * ( zxvvt*zxvvt + zyvvt*zyvvt ) ) znvvt = MAX( znvvt, 1.e-14 ) ! j-direction: f-point segment direction (around u-point) zlam = glamf(ji,jj ) zphi = gphif(ji,jj ) zlan = glamf(ji,jj-1) zphh = gphif(ji,jj-1) zxffu = 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) zyffu = 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) znffu = SQRT( znnpu * ( zxffu*zxffu + zyffu*zyffu ) ) znffu = MAX( znffu, 1.e-14 ) ! i-direction: f-point segment direction (around v-point) zlam = glamf(ji ,jj) zphi = gphif(ji ,jj) zlan = glamf(ji-1,jj) zphh = gphif(ji-1,jj) zxffv = 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) zyffv = 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) znffv = SQRT( znnpv * ( zxffv*zxffv + zyffv*zyffv ) ) znffv = MAX( znffv, 1.e-14 ) ! j-direction: u-point segment direction (around f-point) zlam = glamu(ji,jj+1) zphi = gphiu(ji,jj+1) zlan = glamu(ji,jj ) zphh = gphiu(ji,jj ) zxuuf = 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) zyuuf = 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. ) & & - 2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. ) znuuf = SQRT( znnpf * ( zxuuf*zxuuf + zyuuf*zyuuf ) ) znuuf = MAX( znuuf, 1.e-14 ) ! cosinus and sinus using scalar and vectorial products gsint(ji,jj) = ( zxnpt*zyvvt - zynpt*zxvvt ) / znvvt gcost(ji,jj) = ( zxnpt*zxvvt + zynpt*zyvvt ) / znvvt gsinu(ji,jj) = ( zxnpu*zyffu - zynpu*zxffu ) / znffu gcosu(ji,jj) = ( zxnpu*zxffu + zynpu*zyffu ) / znffu gsinf(ji,jj) = ( zxnpf*zyuuf - zynpf*zxuuf ) / znuuf gcosf(ji,jj) = ( zxnpf*zxuuf + zynpf*zyuuf ) / znuuf ! (caution, rotation of 90 degres) gsinv(ji,jj) = ( zxnpv*zxffv + zynpv*zyffv ) / znffv gcosv(ji,jj) =-( zxnpv*zyffv - zynpv*zxffv ) / znffv END DO END DO ! =============== ! ! Geographic mesh ! ! =============== ! DO jj = 2, jpjm1 DO ji = fs_2, jpi ! vector opt. IF( MOD( ABS( glamv(ji,jj) - glamv(ji,jj-1) ), 360. ) < 1.e-8 ) THEN gsint(ji,jj) = 0. gcost(ji,jj) = 1. ENDIF IF( MOD( ABS( glamf(ji,jj) - glamf(ji,jj-1) ), 360. ) < 1.e-8 ) THEN gsinu(ji,jj) = 0. gcosu(ji,jj) = 1. ENDIF IF( ABS( gphif(ji,jj) - gphif(ji-1,jj) ) < 1.e-8 ) THEN gsinv(ji,jj) = 0. gcosv(ji,jj) = 1. ENDIF IF( MOD( ABS( glamu(ji,jj) - glamu(ji,jj+1) ), 360. ) < 1.e-8 ) THEN gsinf(ji,jj) = 0. gcosf(ji,jj) = 1. ENDIF END DO END DO ! =========================== ! ! Lateral boundary conditions ! ! =========================== ! ! lateral boundary cond.: T-, U-, V-, F-pts, sgn CALL lbc_lnk ( gcost, 'T', 1. ) ; CALL lbc_lnk( gsint, 'T', -1. ) CALL lbc_lnk ( gcosu, 'U', 1. ) ; CALL lbc_lnk( gsinu, 'U', -1. ) CALL lbc_lnk ( gcosv, 'V', 1. ) ; CALL lbc_lnk( gsinv, 'V', -1. ) CALL lbc_lnk ( gcosf, 'F', 1. ) ; CALL lbc_lnk( gsinf, 'F', -1. ) END SUBROUTINE angle SUBROUTINE geo2oce ( pxx , pyy , pzz, cgrid, & plon, plat, pte, ptn , ptv ) !!---------------------------------------------------------------------- !! *** ROUTINE geo2oce *** !! !! ** Purpose : !! !! ** Method : Change wind stress from geocentric to east/north !! !! History : !! ! (O. Marti) Original code !! ! 91-03 (G. Madec) !! ! 92-07 (M. Imbard) !! ! 99-11 (M. Imbard) NetCDF format with IOIPSL !! ! 00-08 (D. Ludicone) Reduced section at Bab el Mandeb !! 8.5 ! 02-06 (G. Madec) F90: Free form !!---------------------------------------------------------------------- !! * Local declarations REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) :: & pxx, pyy, pzz CHARACTER (len=1), INTENT( in) :: & cgrid REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) :: & plon, plat REAL(wp), INTENT(out), DIMENSION(jpi,jpj) :: & pte, ptn, ptv REAL(wp), PARAMETER :: rpi = 3.141592653E0 REAL(wp), PARAMETER :: rad = rpi / 180.e0 !! * Local variables INTEGER :: ig ! !! * Local save REAL(wp), SAVE, DIMENSION(jpi,jpj,4) :: & zsinlon, zcoslon, & zsinlat, zcoslat LOGICAL, SAVE, DIMENSION (4) :: & linit = .FALSE. !!---------------------------------------------------------------------- SELECT CASE( cgrid) CASE ( 't' ) ;; ig = 1 CASE ( 'u' ) ;; ig = 2 CASE ( 'v' ) ;; ig = 3 CASE ( 'f' ) ;; ig = 4 CASE default WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid CALL ctl_stop( ctmp1 ) END SELECT IF( .NOT. linit(ig) ) THEN zsinlon (:,:,ig) = SIN (rad * plon) zcoslon (:,:,ig) = COS (rad * plon) zsinlat (:,:,ig) = SIN (rad * plat) zcoslat (:,:,ig) = COS (rad * plat) linit (ig) = .TRUE. ENDIF pte = - zsinlon (:,:,ig) * pxx + zcoslon (:,:,ig) * pyy ptn = - zcoslon (:,:,ig) * zsinlat (:,:,ig) * pxx & - zsinlon (:,:,ig) * zsinlat (:,:,ig) * pyy & + zcoslat (:,:,ig) * pzz ptv = zcoslon (:,:,ig) * zcoslat (:,:,ig) * pxx & + zsinlon (:,:,ig) * zcoslat (:,:,ig) * pyy & + zsinlat (:,:,ig) * pzz END SUBROUTINE geo2oce SUBROUTINE repere ( px1, py1, px2, py2, kchoix, cd_type ) !!---------------------------------------------------------------------- !! *** ROUTINE repere *** !! !! ** Purpose : Change vector componantes between a geopgraphic grid !! and a stretched coordinates grid. !! !! ** Method : !! !! ** Action : !! !! History : !! ! 89-03 (O. Marti) original code !! ! 92-02 (M. Imbard) !! ! 93-03 (M. Guyon) symetrical conditions !! ! 98-05 (B. Blanke) !! 8.5 ! 02-08 (G. Madec) F90: Free form !!---------------------------------------------------------------------- !! * Arguments REAL(wp), INTENT( IN ), DIMENSION(jpi,jpj) :: & px1, py1 ! two horizontal components to be rotated REAL(wp), INTENT( OUT ), DIMENSION(jpi,jpj) :: & px2, py2 ! the two horizontal components in the model repere INTEGER, INTENT( IN ) :: & kchoix ! type of transformation ! = 1 change from geographic to model grid. ! =-1 change from model to geographic grid CHARACTER(len=1), INTENT( IN ), OPTIONAL :: cd_type ! define the nature of pt2d array grid-points ! CHARACTER(len=1) :: cl_type ! define the nature of pt2d array grid-points (T point by default) !!---------------------------------------------------------------------- cl_type = 'T' IF( PRESENT(cd_type) ) cl_type = cd_type ! SELECT CASE (kchoix) CASE ( 1) ! change from geographic to model grid. CALL rot_rep( px1, py1, cl_type, 'en->i', px2 ) CALL rot_rep( px1, py1, cl_type, 'en->j', py2 ) CASE (-1) ! change from model to geographic grid CALL rot_rep( px1, py1, cl_type, 'ij->e', px2 ) CALL rot_rep( px1, py1, cl_type, 'ij->n', py2 ) CASE DEFAULT ; CALL ctl_stop( 'repere: Syntax Error in the definition of kchoix (1 OR -1' ) END SELECT END SUBROUTINE repere !!====================================================================== END MODULE geo2ocean