New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
geo2ocean.F90 in branches/UKMO/r5936_hadgem3_cplfld/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/r5936_hadgem3_cplfld/NEMOGCM/NEMO/OPA_SRC/SBC/geo2ocean.F90 @ 7150

Last change on this file since 7150 was 7139, checked in by jcastill, 8 years ago

Changes as in branch UKMO/dev_r5107_hadgem3_cplfld@5592

File size: 26.8 KB
Line 
1MODULE geo2ocean
2   !!======================================================================
3   !!                     ***  MODULE  geo2ocean  ***
4   !! Ocean mesh    :  ???
5   !!======================================================================
6   !! History :  OPA  !  07-1996  (O. Marti)  Original code
7   !!   NEMO     1.0  !  02-2008  (G. Madec)  F90: Free form
8   !!            3.0  ! 
9   !!----------------------------------------------------------------------
10
11   !!----------------------------------------------------------------------
12   !!   repcmo      :
13   !!   angle       :
14   !!   geo2oce     :
15   !!   repere      :   old routine suppress it ???
16   !!----------------------------------------------------------------------
17   USE dom_oce         ! mesh and scale factors
18   USE phycst          ! physical constants
19   USE in_out_manager  ! I/O manager
20   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
21   USE lib_mpp         ! MPP library
22
23   IMPLICIT NONE
24   PRIVATE
25
26   PUBLIC   rot_rep, repcmo, repere, geo2oce, oce2geo   ! only rot_rep should be used
27                                             ! repcmo and repere are keep only for compatibility.
28                                             ! they are only a useless overlay of rot_rep
29
30   PUBLIC   obs_rot
31
32   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &
33      gsint, gcost,   &  ! cos/sin between model grid lines and NP direction at T point
34      gsinu, gcosu,   &  ! cos/sin between model grid lines and NP direction at U point
35      gsinv, gcosv,   &  ! cos/sin between model grid lines and NP direction at V point
36      gsinf, gcosf       ! cos/sin between model grid lines and NP direction at F point
37
38   LOGICAL ,              SAVE, DIMENSION(4)     ::   linit = .FALSE.
39   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gsinlon, gcoslon, gsinlat, gcoslat
40
41   LOGICAL ::   lmust_init = .TRUE.        !: used to initialize the cos/sin variables (se above)
42
43   !! * Substitutions
44#  include "vectopt_loop_substitute.h90"
45   !!----------------------------------------------------------------------
46   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
47   !! $Id$
48   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
49   !!----------------------------------------------------------------------
50CONTAINS
51
52   SUBROUTINE repcmo ( pxu1, pyu1, pxv1, pyv1,   &
53                       px2 , py2, kchoix )
54      !!----------------------------------------------------------------------
55      !!                  ***  ROUTINE repcmo  ***
56      !!
57      !! ** Purpose :   Change vector componantes from a geographic grid to a
58      !!      stretched coordinates grid.
59      !!
60      !! ** Method  :   Initialization of arrays at the first call.
61      !!
62      !! ** Action  : - px2 : first  componante (defined at u point)
63      !!              - py2 : second componante (defined at v point)
64      !!----------------------------------------------------------------------
65      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   pxu1, pyu1   ! geographic vector componantes at u-point
66      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   pxv1, pyv1   ! geographic vector componantes at v-point
67      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   px2          ! i-componante (defined at u-point)
68      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   py2          ! j-componante (defined at v-point)
69      INTEGER, INTENT( IN )                       ::   kchoix       ! type of transformation
70                                                                    ! = 1 change from geographic to model grid.
71                                                                    ! =-1 change from model to geographic grid
72      !!----------------------------------------------------------------------
73     
74      SELECT CASE (kchoix) 
75      CASE ( 1) 
76        ! Change from geographic to stretched coordinate
77        ! ----------------------------------------------
78     
79        CALL rot_rep( pxu1, pyu1, 'U', 'en->i',px2 ) 
80        CALL rot_rep( pxv1, pyv1, 'V', 'en->j',py2 ) 
81      CASE (-1) 
82        ! Change from stretched to geographic coordinate
83        ! ----------------------------------------------
84     
85        CALL rot_rep( pxu1, pyu1, 'U', 'ij->e',px2 ) 
86        CALL rot_rep( pxv1, pyv1, 'V', 'ij->n',py2 ) 
87      END SELECT
88     
89   END SUBROUTINE repcmo
90
91
92   SUBROUTINE rot_rep ( pxin, pyin, cd_type, cdtodo, prot )
93      !!----------------------------------------------------------------------
94      !!                  ***  ROUTINE rot_rep  ***
95      !!
96      !! ** Purpose :   Rotate the Repere: Change vector componantes between
97      !!                geographic grid <--> stretched coordinates grid.
98      !!
99      !! History :
100      !!   9.2  !  07-04  (S. Masson) 
101      !!                  (O. Marti ) Original code (repere and repcmo)
102      !!----------------------------------------------------------------------
103      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN ) ::   pxin, pyin   ! vector componantes
104      CHARACTER(len=1),             INTENT( IN ) ::   cd_type      ! define the nature of pt2d array grid-points
105      CHARACTER(len=5),             INTENT( IN ) ::   cdtodo       ! specify the work to do:
106      !!                                                           ! 'en->i' east-north componantes to model i componante
107      !!                                                           ! 'en->j' east-north componantes to model j componante
108      !!                                                           ! 'ij->e' model i-j componantes to east componante
109      !!                                                           ! 'ij->n' model i-j componantes to east componante
110      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::   prot     
111      !!----------------------------------------------------------------------
112
113      ! Initialization of gsin* and gcos* at first call
114      ! -----------------------------------------------
115
116      IF( lmust_init ) THEN
117         IF(lwp) WRITE(numout,*)
118         IF(lwp) WRITE(numout,*) ' rot_rep : geographic <--> stretched'
119         IF(lwp) WRITE(numout,*) ' ~~~~~    coordinate transformation'
120         !
121         CALL angle       ! initialization of the transformation
122         lmust_init = .FALSE.
123      ENDIF
124     
125      SELECT CASE (cdtodo)
126      CASE ('en->i')      ! 'en->i' est-north componantes to model i componante
127         SELECT CASE (cd_type)
128         CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) + pyin(:,:) * gsint(:,:)
129         CASE ('U')   ;   prot(:,:) = pxin(:,:) * gcosu(:,:) + pyin(:,:) * gsinu(:,:)
130         CASE ('V')   ;   prot(:,:) = pxin(:,:) * gcosv(:,:) + pyin(:,:) * gsinv(:,:)
131         CASE ('F')   ;   prot(:,:) = pxin(:,:) * gcosf(:,:) + pyin(:,:) * gsinf(:,:)
132         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
133         END SELECT
134      CASE ('en->j')      ! 'en->j' est-north componantes to model j componante
135         SELECT CASE (cd_type)
136         CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) - pxin(:,:) * gsint(:,:)
137         CASE ('U')   ;   prot(:,:) = pyin(:,:) * gcosu(:,:) - pxin(:,:) * gsinu(:,:)
138         CASE ('V')   ;   prot(:,:) = pyin(:,:) * gcosv(:,:) - pxin(:,:) * gsinv(:,:)   
139         CASE ('F')   ;   prot(:,:) = pyin(:,:) * gcosf(:,:) - pxin(:,:) * gsinf(:,:)   
140         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
141         END SELECT
142      CASE ('ij->e')      ! 'ij->e' model i-j componantes to est componante
143         SELECT CASE (cd_type)
144         CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) - pyin(:,:) * gsint(:,:)
145         CASE ('U')   ;   prot(:,:) = pxin(:,:) * gcosu(:,:) - pyin(:,:) * gsinu(:,:)
146         CASE ('V')   ;   prot(:,:) = pxin(:,:) * gcosv(:,:) - pyin(:,:) * gsinv(:,:)
147         CASE ('F')   ;   prot(:,:) = pxin(:,:) * gcosf(:,:) - pyin(:,:) * gsinf(:,:)
148         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
149         END SELECT
150      CASE ('ij->n')      ! 'ij->n' model i-j componantes to est componante
151         SELECT CASE (cd_type)
152         CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) + pxin(:,:) * gsint(:,:)
153         CASE ('U')   ;   prot(:,:) = pyin(:,:) * gcosu(:,:) + pxin(:,:) * gsinu(:,:)
154         CASE ('V')   ;   prot(:,:) = pyin(:,:) * gcosv(:,:) + pxin(:,:) * gsinv(:,:)
155         CASE ('F')   ;   prot(:,:) = pyin(:,:) * gcosf(:,:) + pxin(:,:) * gsinf(:,:)
156         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
157         END SELECT
158      CASE DEFAULT   ;   CALL ctl_stop( 'rot_rep: Syntax Error in the definition of cdtodo' )
159      END SELECT
160     
161   END SUBROUTINE rot_rep
162
163
164   SUBROUTINE angle
165      !!----------------------------------------------------------------------
166      !!                  ***  ROUTINE angle  ***
167      !!
168      !! ** Purpose :   Compute angles between model grid lines and the North direction
169      !!
170      !! ** Method  :
171      !!
172      !! ** Action  :   Compute (gsint, gcost, gsinu, gcosu, gsinv, gcosv, gsinf, gcosf) arrays:
173      !!      sinus and cosinus of the angle between the north-south axe and the
174      !!      j-direction at t, u, v and f-points
175      !!
176      !! History :
177      !!   7.0  !  96-07  (O. Marti )  Original code
178      !!   8.0  !  98-06  (G. Madec )
179      !!   8.5  !  98-06  (G. Madec )  Free form, F90 + opt.
180      !!   9.2  !  07-04  (S. Masson)  Add T, F points and bugfix in cos lateral boundary
181      !!----------------------------------------------------------------------
182      INTEGER ::   ji, jj   ! dummy loop indices
183      INTEGER ::   ierr     ! local integer
184      REAL(wp) ::   &
185         zlam, zphi,            &  ! temporary scalars
186         zlan, zphh,            &  !    "         "
187         zxnpt, zynpt, znnpt,   &  ! x,y components and norm of the vector: T point to North Pole
188         zxnpu, zynpu, znnpu,   &  ! x,y components and norm of the vector: U point to North Pole
189         zxnpv, zynpv, znnpv,   &  ! x,y components and norm of the vector: V point to North Pole
190         zxnpf, zynpf, znnpf,   &  ! x,y components and norm of the vector: F point to North Pole
191         zxvvt, zyvvt, znvvt,   &  ! x,y components and norm of the vector: between V points below and above a T point
192         zxffu, zyffu, znffu,   &  ! x,y components and norm of the vector: between F points below and above a U point
193         zxffv, zyffv, znffv,   &  ! x,y components and norm of the vector: between F points left  and right a V point
194         zxuuf, zyuuf, znuuf       ! x,y components and norm of the vector: between U points below and above a F point
195      !!----------------------------------------------------------------------
196
197      ALLOCATE( gsint(jpi,jpj), gcost(jpi,jpj),   & 
198         &      gsinu(jpi,jpj), gcosu(jpi,jpj),   & 
199         &      gsinv(jpi,jpj), gcosv(jpi,jpj),   & 
200         &      gsinf(jpi,jpj), gcosf(jpi,jpj), STAT=ierr )
201      IF(lk_mpp)   CALL mpp_sum( ierr )
202      IF( ierr /= 0 )   CALL ctl_stop('angle: unable to allocate arrays' )
203
204      ! ============================= !
205      ! Compute the cosinus and sinus !
206      ! ============================= !
207      ! (computation done on the north stereographic polar plane)
208
209      DO jj = 2, jpjm1
210         DO ji = fs_2, jpi   ! vector opt.
211
212            ! north pole direction & modulous (at t-point)
213            zlam = glamt(ji,jj)
214            zphi = gphit(ji,jj)
215            zxnpt = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
216            zynpt = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
217            znnpt = zxnpt*zxnpt + zynpt*zynpt
218
219            ! north pole direction & modulous (at u-point)
220            zlam = glamu(ji,jj)
221            zphi = gphiu(ji,jj)
222            zxnpu = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
223            zynpu = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
224            znnpu = zxnpu*zxnpu + zynpu*zynpu
225
226            ! north pole direction & modulous (at v-point)
227            zlam = glamv(ji,jj)
228            zphi = gphiv(ji,jj)
229            zxnpv = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
230            zynpv = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
231            znnpv = zxnpv*zxnpv + zynpv*zynpv
232
233            ! north pole direction & modulous (at f-point)
234            zlam = glamf(ji,jj)
235            zphi = gphif(ji,jj)
236            zxnpf = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
237            zynpf = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
238            znnpf = zxnpf*zxnpf + zynpf*zynpf
239
240            ! j-direction: v-point segment direction (around t-point)
241            zlam = glamv(ji,jj  )
242            zphi = gphiv(ji,jj  )
243            zlan = glamv(ji,jj-1)
244            zphh = gphiv(ji,jj-1)
245            zxvvt =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
246               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
247            zyvvt =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
248               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
249            znvvt = SQRT( znnpt * ( zxvvt*zxvvt + zyvvt*zyvvt )  )
250            znvvt = MAX( znvvt, 1.e-14 )
251
252            ! j-direction: f-point segment direction (around u-point)
253            zlam = glamf(ji,jj  )
254            zphi = gphif(ji,jj  )
255            zlan = glamf(ji,jj-1)
256            zphh = gphif(ji,jj-1)
257            zxffu =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
258               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
259            zyffu =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
260               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
261            znffu = SQRT( znnpu * ( zxffu*zxffu + zyffu*zyffu )  )
262            znffu = MAX( znffu, 1.e-14 )
263
264            ! i-direction: f-point segment direction (around v-point)
265            zlam = glamf(ji  ,jj)
266            zphi = gphif(ji  ,jj)
267            zlan = glamf(ji-1,jj)
268            zphh = gphif(ji-1,jj)
269            zxffv =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
270               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
271            zyffv =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
272               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
273            znffv = SQRT( znnpv * ( zxffv*zxffv + zyffv*zyffv )  )
274            znffv = MAX( znffv, 1.e-14 )
275
276            ! j-direction: u-point segment direction (around f-point)
277            zlam = glamu(ji,jj+1)
278            zphi = gphiu(ji,jj+1)
279            zlan = glamu(ji,jj  )
280            zphh = gphiu(ji,jj  )
281            zxuuf =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
282               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
283            zyuuf =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
284               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
285            znuuf = SQRT( znnpf * ( zxuuf*zxuuf + zyuuf*zyuuf )  )
286            znuuf = MAX( znuuf, 1.e-14 )
287
288            ! cosinus and sinus using scalar and vectorial products
289            gsint(ji,jj) = ( zxnpt*zyvvt - zynpt*zxvvt ) / znvvt
290            gcost(ji,jj) = ( zxnpt*zxvvt + zynpt*zyvvt ) / znvvt
291
292            gsinu(ji,jj) = ( zxnpu*zyffu - zynpu*zxffu ) / znffu
293            gcosu(ji,jj) = ( zxnpu*zxffu + zynpu*zyffu ) / znffu
294
295            gsinf(ji,jj) = ( zxnpf*zyuuf - zynpf*zxuuf ) / znuuf
296            gcosf(ji,jj) = ( zxnpf*zxuuf + zynpf*zyuuf ) / znuuf
297
298            ! (caution, rotation of 90 degres)
299            gsinv(ji,jj) = ( zxnpv*zxffv + zynpv*zyffv ) / znffv
300            gcosv(ji,jj) =-( zxnpv*zyffv - zynpv*zxffv ) / znffv
301
302         END DO
303      END DO
304
305      ! =============== !
306      ! Geographic mesh !
307      ! =============== !
308
309      DO jj = 2, jpjm1
310         DO ji = fs_2, jpi   ! vector opt.
311            IF( MOD( ABS( glamv(ji,jj) - glamv(ji,jj-1) ), 360. ) < 1.e-8 ) THEN
312               gsint(ji,jj) = 0.
313               gcost(ji,jj) = 1.
314            ENDIF
315            IF( MOD( ABS( glamf(ji,jj) - glamf(ji,jj-1) ), 360. ) < 1.e-8 ) THEN
316               gsinu(ji,jj) = 0.
317               gcosu(ji,jj) = 1.
318            ENDIF
319            IF(      ABS( gphif(ji,jj) - gphif(ji-1,jj) )         < 1.e-8 ) THEN
320               gsinv(ji,jj) = 0.
321               gcosv(ji,jj) = 1.
322            ENDIF
323            IF( MOD( ABS( glamu(ji,jj) - glamu(ji,jj+1) ), 360. ) < 1.e-8 ) THEN
324               gsinf(ji,jj) = 0.
325               gcosf(ji,jj) = 1.
326            ENDIF
327         END DO
328      END DO
329
330      ! =========================== !
331      ! Lateral boundary conditions !
332      ! =========================== !
333
334      ! lateral boundary cond.: T-, U-, V-, F-pts, sgn
335      CALL lbc_lnk( gcost, 'T', -1. )   ;   CALL lbc_lnk( gsint, 'T', -1. )
336      CALL lbc_lnk( gcosu, 'U', -1. )   ;   CALL lbc_lnk( gsinu, 'U', -1. )
337      CALL lbc_lnk( gcosv, 'V', -1. )   ;   CALL lbc_lnk( gsinv, 'V', -1. )
338      CALL lbc_lnk( gcosf, 'F', -1. )   ;   CALL lbc_lnk( gsinf, 'F', -1. )
339
340   END SUBROUTINE angle
341
342
343   SUBROUTINE geo2oce ( pxx, pyy, pzz, cgrid,     &
344                        pte, ptn )
345      !!----------------------------------------------------------------------
346      !!                    ***  ROUTINE geo2oce  ***
347      !!     
348      !! ** Purpose :
349      !!
350      !! ** Method  :   Change wind stress from geocentric to east/north
351      !!
352      !! History :
353      !!        !         (O. Marti)  Original code
354      !!        !  91-03  (G. Madec)
355      !!        !  92-07  (M. Imbard)
356      !!        !  99-11  (M. Imbard) NetCDF format with IOIPSL
357      !!        !  00-08  (D. Ludicone) Reduced section at Bab el Mandeb
358      !!   8.5  !  02-06  (G. Madec)  F90: Free form
359      !!   3.0  !  07-08  (G. Madec)  geo2oce suppress lon/lat agruments
360      !!----------------------------------------------------------------------
361      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::  pxx, pyy, pzz
362      CHARACTER(len=1)            , INTENT(in   ) ::  cgrid
363      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::  pte, ptn
364      !!
365      REAL(wp), PARAMETER :: rpi = 3.141592653e0
366      REAL(wp), PARAMETER :: rad = rpi / 180.e0
367      INTEGER ::   ig     !
368      INTEGER ::   ierr   ! local integer
369      !!----------------------------------------------------------------------
370
371      IF( .NOT. ALLOCATED( gsinlon ) ) THEN
372         ALLOCATE( gsinlon(jpi,jpj,4) , gcoslon(jpi,jpj,4) ,   &
373            &      gsinlat(jpi,jpj,4) , gcoslat(jpi,jpj,4) , STAT=ierr )
374         IF( lk_mpp    )   CALL mpp_sum( ierr )
375         IF( ierr /= 0 )   CALL ctl_stop('geo2oce: unable to allocate arrays' )
376      ENDIF
377
378      SELECT CASE( cgrid)
379         CASE ( 'T' )   
380            ig = 1
381            IF( .NOT. linit(ig) ) THEN
382               gsinlon(:,:,ig) = SIN( rad * glamt(:,:) )
383               gcoslon(:,:,ig) = COS( rad * glamt(:,:) )
384               gsinlat(:,:,ig) = SIN( rad * gphit(:,:) )
385               gcoslat(:,:,ig) = COS( rad * gphit(:,:) )
386               linit(ig) = .TRUE.
387            ENDIF
388         CASE ( 'U' )   
389            ig = 2
390            IF( .NOT. linit(ig) ) THEN
391               gsinlon(:,:,ig) = SIN( rad * glamu(:,:) )
392               gcoslon(:,:,ig) = COS( rad * glamu(:,:) )
393               gsinlat(:,:,ig) = SIN( rad * gphiu(:,:) )
394               gcoslat(:,:,ig) = COS( rad * gphiu(:,:) )
395               linit(ig) = .TRUE.
396            ENDIF
397         CASE ( 'V' )   
398            ig = 3
399            IF( .NOT. linit(ig) ) THEN
400               gsinlon(:,:,ig) = SIN( rad * glamv(:,:) )
401               gcoslon(:,:,ig) = COS( rad * glamv(:,:) )
402               gsinlat(:,:,ig) = SIN( rad * gphiv(:,:) )
403               gcoslat(:,:,ig) = COS( rad * gphiv(:,:) )
404               linit(ig) = .TRUE.
405            ENDIF
406         CASE ( 'F' )   
407            ig = 4
408            IF( .NOT. linit(ig) ) THEN
409               gsinlon(:,:,ig) = SIN( rad * glamf(:,:) )
410               gcoslon(:,:,ig) = COS( rad * glamf(:,:) )
411               gsinlat(:,:,ig) = SIN( rad * gphif(:,:) )
412               gcoslat(:,:,ig) = COS( rad * gphif(:,:) )
413               linit(ig) = .TRUE.
414            ENDIF
415         CASE default   
416            WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid
417            CALL ctl_stop( ctmp1 )
418      END SELECT
419     
420      pte = - gsinlon(:,:,ig) * pxx + gcoslon(:,:,ig) * pyy
421      ptn = - gcoslon(:,:,ig) * gsinlat(:,:,ig) * pxx    &
422            - gsinlon(:,:,ig) * gsinlat(:,:,ig) * pyy    &
423            + gcoslat(:,:,ig) * pzz
424!!$   ptv =   gcoslon(:,:,ig) * gcoslat(:,:,ig) * pxx    &
425!!$         + gsinlon(:,:,ig) * gcoslat(:,:,ig) * pyy    &
426!!$         + gsinlat(:,:,ig) * pzz
427      !
428   END SUBROUTINE geo2oce
429
430   SUBROUTINE oce2geo ( pte, ptn, cgrid,     &
431                        pxx , pyy , pzz )
432      !!----------------------------------------------------------------------
433      !!                    ***  ROUTINE oce2geo  ***
434      !!     
435      !! ** Purpose :
436      !!
437      !! ** Method  :   Change vector from east/north to geocentric
438      !!
439      !! History :
440      !!        !         (A. Caubel)  oce2geo - Original code
441      !!----------------------------------------------------------------------
442      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN    ) ::  pte, ptn
443      CHARACTER(len=1)            , INTENT( IN    ) ::  cgrid
444      REAL(wp), DIMENSION(jpi,jpj), INTENT(   OUT ) ::  pxx , pyy , pzz
445      !!
446      REAL(wp), PARAMETER :: rpi = 3.141592653E0
447      REAL(wp), PARAMETER :: rad = rpi / 180.e0
448      INTEGER ::   ig     !
449      INTEGER ::   ierr   ! local integer
450      !!----------------------------------------------------------------------
451
452      IF( .NOT. ALLOCATED( gsinlon ) ) THEN
453         ALLOCATE( gsinlon(jpi,jpj,4) , gcoslon(jpi,jpj,4) ,   &
454            &      gsinlat(jpi,jpj,4) , gcoslat(jpi,jpj,4) , STAT=ierr )
455         IF( lk_mpp    )   CALL mpp_sum( ierr )
456         IF( ierr /= 0 )   CALL ctl_stop('oce2geo: unable to allocate arrays' )
457      ENDIF
458
459      SELECT CASE( cgrid)
460         CASE ( 'T' )   
461            ig = 1
462            IF( .NOT. linit(ig) ) THEN
463               gsinlon(:,:,ig) = SIN( rad * glamt(:,:) )
464               gcoslon(:,:,ig) = COS( rad * glamt(:,:) )
465               gsinlat(:,:,ig) = SIN( rad * gphit(:,:) )
466               gcoslat(:,:,ig) = COS( rad * gphit(:,:) )
467               linit(ig) = .TRUE.
468            ENDIF
469         CASE ( 'U' )   
470            ig = 2
471            IF( .NOT. linit(ig) ) THEN
472               gsinlon(:,:,ig) = SIN( rad * glamu(:,:) )
473               gcoslon(:,:,ig) = COS( rad * glamu(:,:) )
474               gsinlat(:,:,ig) = SIN( rad * gphiu(:,:) )
475               gcoslat(:,:,ig) = COS( rad * gphiu(:,:) )
476               linit(ig) = .TRUE.
477            ENDIF
478         CASE ( 'V' )   
479            ig = 3
480            IF( .NOT. linit(ig) ) THEN
481               gsinlon(:,:,ig) = SIN( rad * glamv(:,:) )
482               gcoslon(:,:,ig) = COS( rad * glamv(:,:) )
483               gsinlat(:,:,ig) = SIN( rad * gphiv(:,:) )
484               gcoslat(:,:,ig) = COS( rad * gphiv(:,:) )
485               linit(ig) = .TRUE.
486            ENDIF
487         CASE ( 'F' )   
488            ig = 4
489            IF( .NOT. linit(ig) ) THEN
490               gsinlon(:,:,ig) = SIN( rad * glamf(:,:) )
491               gcoslon(:,:,ig) = COS( rad * glamf(:,:) )
492               gsinlat(:,:,ig) = SIN( rad * gphif(:,:) )
493               gcoslat(:,:,ig) = COS( rad * gphif(:,:) )
494               linit(ig) = .TRUE.
495            ENDIF
496         CASE default   
497            WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid
498            CALL ctl_stop( ctmp1 )
499      END SELECT
500
501       pxx = - gsinlon(:,:,ig) * pte - gcoslon(:,:,ig) * gsinlat(:,:,ig) * ptn 
502       pyy =   gcoslon(:,:,ig) * pte - gsinlon(:,:,ig) * gsinlat(:,:,ig) * ptn
503       pzz =   gcoslat(:,:,ig) * ptn
504
505     
506   END SUBROUTINE oce2geo
507
508
509   SUBROUTINE repere ( px1, py1, px2, py2, kchoix, cd_type )
510      !!----------------------------------------------------------------------
511      !!                 ***  ROUTINE repere  ***
512      !!       
513      !! ** Purpose :   Change vector componantes between a geopgraphic grid
514      !!      and a stretched coordinates grid.
515      !!
516      !! ** Method  :   
517      !!
518      !! ** Action  :
519      !!
520      !! History :
521      !!        !  89-03  (O. Marti)  original code
522      !!        !  92-02  (M. Imbard)
523      !!        !  93-03  (M. Guyon)  symetrical conditions
524      !!        !  98-05  (B. Blanke)
525      !!   8.5  !  02-08  (G. Madec)  F90: Free form
526      !!----------------------------------------------------------------------
527      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   px1, py1   ! two horizontal components to be rotated
528      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   px2, py2   ! the two horizontal components in the model repere
529      INTEGER , INTENT(in   )                     ::   kchoix     ! type of transformation
530      !                                                           ! = 1 change from geographic to model grid.
531      !                                                           ! =-1 change from model to geographic grid
532      CHARACTER(len=1), INTENT(in   ), OPTIONAL   ::   cd_type    ! define the nature of pt2d array grid-points
533      !
534      CHARACTER(len=1) ::   cl_type      ! define the nature of pt2d array grid-points (T point by default)
535      !!----------------------------------------------------------------------
536
537      cl_type = 'T'
538      IF( PRESENT(cd_type) )   cl_type = cd_type
539         !
540      SELECT CASE (kchoix)
541      CASE ( 1)      ! change from geographic to model grid.
542         CALL rot_rep( px1, py1, cl_type, 'en->i', px2 )
543         CALL rot_rep( px1, py1, cl_type, 'en->j', py2 )
544      CASE (-1)      ! change from model to geographic grid
545         CALL rot_rep( px1, py1, cl_type, 'ij->e', px2 )
546         CALL rot_rep( px1, py1, cl_type, 'ij->n', py2 )
547      CASE DEFAULT   ;   CALL ctl_stop( 'repere: Syntax Error in the definition of kchoix (1 OR -1' )
548      END SELECT
549     
550   END SUBROUTINE repere
551
552
553   SUBROUTINE obs_rot ( psinu, pcosu, psinv, pcosv )
554      !!----------------------------------------------------------------------
555      !!                  ***  ROUTINE obs_rot  ***
556      !!
557      !! ** Purpose :   Copy gsinu, gcosu, gsinv and gsinv
558      !!                to input data for rotations of
559      !!                current at observation points
560      !!
561      !! History :
562      !!   9.2  !  09-02  (K. Mogensen)
563      !!----------------------------------------------------------------------
564      REAL(wp), DIMENSION(jpi,jpj), INTENT( OUT )::   psinu, pcosu, psinv, pcosv   ! copy of data
565      !!----------------------------------------------------------------------
566
567      ! Initialization of gsin* and gcos* at first call
568      ! -----------------------------------------------
569
570      IF( lmust_init ) THEN
571         IF(lwp) WRITE(numout,*)
572         IF(lwp) WRITE(numout,*) ' obs_rot : geographic <--> stretched'
573         IF(lwp) WRITE(numout,*) ' ~~~~~~~   coordinate transformation'
574
575         CALL angle       ! initialization of the transformation
576         lmust_init = .FALSE.
577
578      ENDIF
579
580      psinu(:,:) = gsinu(:,:)
581      pcosu(:,:) = gcosu(:,:)
582      psinv(:,:) = gsinv(:,:)
583      pcosv(:,:) = gcosv(:,:)
584
585   END SUBROUTINE obs_rot
586
587  !!======================================================================
588END MODULE geo2ocean
Note: See TracBrowser for help on using the repository browser.