geo2ocean.F90 26 KB

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