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.
flodom.F90 in branches/2011/dev_r2802_MERCATOR9_floats/NEMOGCM/NEMO/OPA_SRC/FLO – NEMO

source: branches/2011/dev_r2802_MERCATOR9_floats/NEMOGCM/NEMO/OPA_SRC/FLO/flodom.F90 @ 2844

Last change on this file since 2844 was 2844, checked in by cbricaud, 13 years ago

minor corrections

  • Property svn:keywords set to Id
File size: 19.4 KB
Line 
1MODULE flodom
2   !!======================================================================
3   !!                       ***  MODULE  flodom  ***
4   !! Ocean floats :   domain
5   !!======================================================================
6   !! History :  OPA          ! 1998-07 (Y.Drillet, CLIPPER)  Original code
7   !!            NEMO_3.3.1   ! 2011-09 (C.Bricaud,S.Law-Chune Mercator-Ocean):
8                              ! add Ariane convention, Comsecitc changes
9   !!----------------------------------------------------------------------
10#if   defined key_floats   ||   defined key_esopa
11   !!----------------------------------------------------------------------
12   !!   'key_floats'                                     float trajectories
13   !!----------------------------------------------------------------------
14   !!   flo_dom               : initialization of floats
15   !!   add_new_floats        : add new floats (long/lat/depth)
16   !!   add_new_ariane_floats : add new floats with araine convention (i/j/k)
17   !!   findmesh              : compute index of position
18   !!   dstnce                : compute distance between face mesh and floats
19   !!----------------------------------------------------------------------
20   USE oce             ! ocean dynamics and tracers
21   USE dom_oce         ! ocean space and time domain
22   USE flo_oce         ! ocean drifting floats
23   USE in_out_manager  ! I/O manager
24   USE lib_mpp         ! distribued memory computing library
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   flo_dom    ! routine called by floats.F90
30
31   CHARACTER (len=21) ::  clname1 = 'init_float'              ! floats initialisation filename
32   CHARACTER (len=21) ::  clname2 = 'init_float_ariane'       ! ariane floats initialisation filename
33
34   !! * Substitutions
35#  include "domzgr_substitute.h90"
36   !!----------------------------------------------------------------------
37   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
38   !! $Id$
39   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
40   !!----------------------------------------------------------------------
41CONTAINS
42
43   SUBROUTINE flo_dom
44      !! ---------------------------------------------------------------------
45      !!                  ***  ROUTINE flo_dom  ***
46      !!                 
47      !!  ** Purpose :   Initialisation of floats
48      !!
49      !!  ** Method  :   We put the floats  in the domain with the latitude,
50      !!               the longitude (degree) and the depth (m).
51      !!----------------------------------------------------------------------     
52      INTEGER            ::   jfl    ! dummy loop 
53      INTEGER            ::   inum   ! logical unit for file read
54      !!---------------------------------------------------------------------
55     
56      ! Initialisation with the geographical position or restart
57     
58      IF(lwp) WRITE(numout,*) 'flo_dom : compute initial position of floats'
59      IF(lwp) WRITE(numout,*) '~~~~~~~~'
60      IF(lwp) WRITE(numout,*) '           jpnfl = ',jpnfl
61     
62      !-------------------------!
63      ! FLOAT RESTART FILE READ !
64      !-------------------------!
65      IF( ln_rstflo )THEN
66
67         IF(lwp) WRITE(numout,*) '        float restart file read'
68         
69         ! open the restart file
70         !----------------------
71         CALL ctl_opn( inum, 'restart_float', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
72
73         ! read of the restart file
74         READ(inum,*)   ( tpifl  (jfl), jfl=1, jpnrstflo),   & 
75                        ( tpjfl  (jfl), jfl=1, jpnrstflo),   &
76                        ( tpkfl  (jfl), jfl=1, jpnrstflo),   &
77                        ( nisobfl(jfl), jfl=1, jpnrstflo),   &
78                        ( ngrpfl (jfl), jfl=1, jpnrstflo)   
79         CLOSE(inum)
80
81         ! if we want a  surface drift  ( like PROVOR floats )
82         IF( ln_argo ) nisobfl(1:jpnrstflo) = 0
83         
84         ! It is possible to add new floats.         
85         !---------------------------------
86         IF( jpnfl > jpnrstflo )THEN
87
88            IF(lwp) WRITE(numout,*) '        add new floats'
89
90            IF( ln_ariane )THEN  !Add new floats with ariane convention
91                CALL add_new_ariane_floats(jpnrstflo+1,jpnfl) 
92            ELSE                 !Add new floats with long/lat convention
93                CALL add_new_floats(jpnrstflo+1,jpnfl)
94            ENDIF
95         ENDIF
96
97      !--------------------------------------!
98      ! FLOAT INITILISATION: NO RESTART FILE !
99      !--------------------------------------!
100      ELSE    !ln_rstflo
101
102         IF( ln_ariane )THEN       !Add new floats with ariane convention
103            CALL add_new_ariane_floats(1,jpnfl)
104         ELSE                      !Add new floats with long/lat convention
105            CALL add_new_floats(1,jpnfl)
106         ENDIF
107
108      ENDIF
109           
110   END SUBROUTINE flo_dom
111
112   SUBROUTINE add_new_floats(kfl_start, kfl_end)
113      !! -------------------------------------------------------------
114      !!                 ***  SUBROUTINE add_new_arianefloats  ***
115      !!         
116      !! ** Purpose :   
117      !!
118      !!       First initialisation of floats
119      !!       the initials positions of floats are written in a file
120      !!       with a variable to know if it is a isobar float a number
121      !!       to identified who want the trajectories of this float and
122      !!       an index for the number of the float         
123      !!       open the init file
124      !!               
125      !! ** Method  :
126      !!----------------------------------------------------------------------
127      INTEGER, INTENT(in) :: kfl_start, kfl_end
128      !!
129      INTEGER           :: inum ! file unit
130      INTEGER           :: jfl,ji, jj, jk ! dummy loop indices
131      INTEGER           :: itrash         ! trash var for reading
132      INTEGER           :: ifl            ! number of floats to read
133      REAL(wp)          :: zdxab, zdyad
134      LOGICAL           :: llinmesh
135      CHARACTER(len=80) :: cltmp
136
137      INTEGER , DIMENSION(jpnfl) ::   iimfl, ijmfl, ikmfl       ! index mesh of floats
138      INTEGER , DIMENSION(jpnfl) ::   idomfl, ivtest, ihtest    !   -     
139      REAL(wp), DIMENSION(jpnfl) ::   zgifl, zgjfl,  zgkfl
140      !!---------------------------------------------------------------------
141      ifl = kfl_end-kfl_start+1
142
143      ! we get the init values
144      !-----------------------
145      CALL ctl_opn( inum , clname1, 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
146      DO jfl = kfl_start,kfl_end
147         READ(inum,*) flxx(jfl),flyy(jfl),flzz(jfl), nisobfl(jfl),ngrpfl(jfl),itrash
148         if(lwp)write(numout,*)'read:',jfl,flxx(jfl),flyy(jfl),flzz(jfl), nisobfl(jfl),ngrpfl(jfl),itrash ; call flush(numout)
149      END DO
150      CLOSE(inum)
151           
152      ! Test to find the grid point coordonate with the geographical position           
153      !----------------------------------------------------------------------
154      DO jfl = kfl_start,kfl_end
155         ihtest(jfl) = 0
156         ivtest(jfl) = 0
157         ikmfl(jfl) = 0
158# if   defined key_mpp_mpi
159         DO ji = MAX(nldi,2), nlei
160            DO jj = MAX(nldj,2), nlej   ! NO vector opt.
161# else         
162         DO ji = 2, jpi
163            DO jj = 2, jpj   ! NO vector opt.
164# endif                     
165               ! For each float we find the indexes of the mesh                     
166               CALL findmesh(glamf(ji-1,jj-1),gphif(ji-1,jj-1),   &
167                             glamf(ji-1,jj  ),gphif(ji-1,jj  ),   &
168                             glamf(ji  ,jj  ),gphif(ji  ,jj  ),   &
169                             glamf(ji  ,jj-1),gphif(ji  ,jj-1),   &
170                             flxx(jfl)       ,flyy(jfl)       ,   &
171                             glamt(ji  ,jj  ),gphit(ji  ,jj  ), llinmesh)
172               IF( llinmesh )THEN
173                  iimfl(jfl) = ji
174                  ijmfl(jfl) = jj
175                  ihtest(jfl) = ihtest(jfl)+1
176                  DO jk = 1, jpk-1
177                     IF( (fsdepw(ji,jj,jk) <= flzz(jfl)) .AND. (fsdepw(ji,jj,jk+1) > flzz(jfl)) ) THEN
178                        ikmfl(jfl) = jk
179                        ivtest(jfl) = ivtest(jfl) + 1
180                     ENDIF
181                  END DO
182               ENDIF
183            END DO
184         END DO
185
186         ! If the float is in a mesh computed by an other processor we put iimfl=ijmfl=-1               
187         IF( ihtest(jfl) ==  0 ) THEN
188            iimfl(jfl) = -1
189            ijmfl(jfl) = -1
190         ENDIF
191      END DO
192
193      !Test if each float is in one and only one proc
194      !----------------------------------------------
195      IF( lk_mpp )   THEN
196         CALL mpp_sum(ihtest,jpnfl)
197         CALL mpp_sum(ivtest,jpnfl)
198      ENDIF
199      DO jfl = kfl_start,kfl_end
200
201         IF( (ihtest(jfl) > 1 ) .OR. ( ivtest(jfl) > 1) ) THEN
202             WRITE(cltmp,'(A10,i4.4,A20)' )'THE FLOAT',jfl,' IS NOT IN ONLY ONE MESH'
203             CALL ctl_stop('STOP',TRIM(cltmp) )
204         ENDIF
205         IF( (ihtest(jfl) == 0) ) THEN
206             WRITE(cltmp,'(A10,i4.4,A20)' )'THE FLOAT',jfl,' IS IN NO MESH'
207             CALL ctl_stop('STOP',TRIM(cltmp) )
208         ENDIF
209      END DO
210
211      ! We compute the distance between the float and the face of the mesh           
212      !-------------------------------------------------------------------
213      DO jfl = kfl_start,kfl_end
214
215         ! Made only if the float is in the domain of the processor             
216         IF( (iimfl(jfl) >= 0) .AND. (ijmfl(jfl) >= 0) ) THEN
217
218            ! TEST TO KNOW IF THE FLOAT IS NOT INITIALISED IN THE COAST
219            idomfl(jfl) = 0
220            IF( tmask(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) == 0. ) idomfl(jfl) = 1
221
222            ! Computation of the distance between the float and the faces of the mesh
223            !            zdxab
224            !             .
225            !        B----.---------C
226            !        |    .         |
227            !        |<------>flo   |
228            !        |        ^     |
229            !        |        |.....|....zdyad
230            !        |        |     |
231            !        A--------|-----D
232            !
233            zdxab = dstnce( flxx(jfl), flyy(jfl), glamf(iimfl(jfl)-1,ijmfl(jfl)-1), flyy(jfl) )
234            zdyad = dstnce( flxx(jfl), flyy(jfl), flxx(jfl), gphif(iimfl(jfl)-1,ijmfl(jfl)-1) )
235
236            ! Translation of this distances (in meter) in indexes
237            zgifl(jfl)= (iimfl(jfl)-0.5) + zdxab/e1u(iimfl(jfl)-1,ijmfl(jfl)) + (mig(1)-jpizoom)
238            zgjfl(jfl)= (ijmfl(jfl)-0.5) + zdyad/e2v(iimfl(jfl),ijmfl(jfl)-1) + (mjg(1)-jpjzoom)
239            zgkfl(jfl) = (( fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - flzz(jfl) )* ikmfl(jfl))   &
240               &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
241               &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl) ) )                             &
242               &                 + (( flzz(jfl)-fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) ) *(ikmfl(jfl)+1))   &
243               &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
244               &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) )
245         ELSE
246            zgifl(jfl) = 0.e0
247            zgjfl(jfl) = 0.e0
248            zgkfl(jfl) = 0.e0
249         ENDIF
250
251      END DO
252                 
253      ! The sum of all the arrays zgifl, zgjfl, zgkfl give 3 arrays with the positions of all the floats.
254      IF( lk_mpp )   THEN
255         CALL mpp_sum( zgjfl, ifl )   ! sums over the global domain
256         CALL mpp_sum( zgkfl, ifl )
257      ENDIF
258           
259      DO jfl = kfl_start,kfl_end
260         tpifl(jfl) = zgifl(jfl)
261         tpjfl(jfl) = zgjfl(jfl)
262         tpkfl(jfl) = zgkfl(jfl)
263      END DO
264
265      ! WARNING : initial position not in the sea         
266      IF( .NOT. ln_rstflo ) THEN
267         DO jfl =  kfl_start,kfl_end
268            IF( idomfl(jfl) == 1 ) THEN
269               IF(lwp) WRITE(numout,*)'*****************************'
270               IF(lwp) WRITE(numout,*)'!!!!!!!  WARNING   !!!!!!!!!!'
271               IF(lwp) WRITE(numout,*)'*****************************'
272               IF(lwp) WRITE(numout,*)'The float number',jfl,'is out of the sea.'
273               IF(lwp) WRITE(numout,*)'geographical position',flxx(jfl),flyy(jfl),flzz(jfl)
274               IF(lwp) WRITE(numout,*)'index position',tpifl(jfl),tpjfl(jfl),tpkfl(jfl)
275            ENDIF
276         END DO
277      ENDIF
278
279   END SUBROUTINE add_new_floats
280
281   SUBROUTINE add_new_ariane_floats(kfl_start, kfl_end)
282      !! -------------------------------------------------------------
283      !!                 ***  SUBROUTINE add_new_arianefloats  ***
284      !!         
285      !! ** Purpose :   
286      !!       First initialisation of floats with ariane convention
287      !!       
288      !!       The indexes are read directly from file (warning ariane
289      !!       convention, are refered to
290      !!       U,V,W grids - and not T-)
291      !!       The isobar advection is managed with the sign of tpkfl ( >0 -> 3D
292      !!       advection, <0 -> 2D)
293      !!       Some variables are not read, as - gl         : time index; 4th
294      !!       column       
295      !!                                       - transport  : transport ; 5th
296      !!                                       column
297      !!       and paste in the jtrash var
298      !!       At the end, ones need to replace the indexes on T grid
299      !!       RMQ : there is no float groups identification !
300      !!
301      !!               
302      !! ** Method  :
303      !!----------------------------------------------------------------------
304      INTEGER, INTENT(in) :: kfl_start, kfl_end
305      !!
306      INTEGER  :: inum         ! file unit
307      INTEGER  :: ierr, ifl
308      INTEGER  :: jfl, jfl1    ! dummy loop indices
309      INTEGER  :: itrash       ! trash var for reading 
310      CHARACTER(len=80) :: cltmp
311
312      !!----------------------------------------------------------------------
313      nisobfl(kfl_start:kfl_end) = 1 ! we assume that by default we want 3D advection
314
315      ifl = kfl_end - kfl_start + 1  ! number of floats to read 
316
317      ! we check that the number of floats in the init_file are consistant with the namelist
318      IF( lwp ) THEN
319
320         jfl1=0
321         ierr=0
322         CALL ctl_opn( inum, clname2, 'OLD', 'FORMATTED', 'SEQUENTIAL',  1, numout, .TRUE., 1 )
323         DO WHILE (ierr .EQ. 0)
324            jfl1=jfl1+1
325            READ(inum,*, iostat=ierr)
326         END DO
327         CLOSE(inum)
328         IF( (jfl1-1) .NE. ifl )THEN
329            WRITE(cltmp,'(A25,A20,A3,i4.4,A10,i4.4)')"the number of floats in ",TRIM(clname2), &
330                                                     " = ",jfl1," is not equal to jfl= ",ifl
331            CALL ctl_stop('STOP',TRIM(cltmp) )
332         ENDIF
333
334      ENDIF
335           
336      ! we get the init values
337      CALL ctl_opn( inum, clname2, 'OLD', 'FORMATTED', 'SEQUENTIAL', 1, numout, .TRUE., 1 )
338      DO jfl = kfl_start, kfl_end
339          READ(inum,*) tpifl(jfl),tpjfl(jfl),tpkfl(jfl),itrash, itrash
340             
341          IF ( tpkfl(jfl) .LT. 0. ) nisobfl(jfl) = 0 !set the 2D advection according to init_float
342          ngrpfl(jfl)=jfl
343      END DO
344
345      ! conversion from ariane index to T grid index
346      tpkfl(kfl_start:kfl_end) = abs(tpkfl)-0.5 ! reversed vertical axis
347      tpifl(kfl_start:kfl_end) = tpifl+0.5
348      tpjfl(kfl_start:kfl_end) = tpjfl+0.5
349
350
351   END SUBROUTINE add_new_ariane_floats
352
353
354   SUBROUTINE findmesh( pax, pay, pbx, pby,   &
355                        pcx, pcy, pdx, pdy,   &
356                        px  ,py  ,ptx, pty, ldinmesh )
357      !! -------------------------------------------------------------
358      !!                ***  ROUTINE findmesh  ***
359      !!     
360      !! ** Purpose :   Find the index of mesh for the point spx spy
361      !!
362      !! ** Method  :
363      !!----------------------------------------------------------------------
364      REAL(wp) ::   &
365         pax, pay, pbx, pby,    &     ! ???
366         pcx, pcy, pdx, pdy,    &     ! ???
367         px, py,                &     ! longitude and latitude
368         ptx, pty                     ! ???
369      LOGICAL ::  ldinmesh            ! ???
370      !!
371      REAL(wp) ::   zabt, zbct, zcdt, zdat, zabpt, zbcpt, zcdpt, zdapt
372      !!---------------------------------------------------------------------
373      !! Statement function
374      REAL(wp) ::   fsline
375      REAL(wp) ::   psax, psay, psbx, psby, psx, psy
376      fsline( psax, psay, psbx, psby, psx, psy ) = psy  * ( psbx - psax )   &
377         &                                       - psx  * ( psby - psay )   &
378         &                                       + psax *   psby - psay * psbx
379      !!---------------------------------------------------------------------
380     
381      ! 4 semi plane defined by the 4 points and including the T point
382      zabt = fsline(pax,pay,pbx,pby,ptx,pty)
383      zbct = fsline(pbx,pby,pcx,pcy,ptx,pty)
384      zcdt = fsline(pcx,pcy,pdx,pdy,ptx,pty)
385      zdat = fsline(pdx,pdy,pax,pay,ptx,pty)
386     
387      ! 4 semi plane defined by the 4 points and including the extrememity
388      zabpt = fsline(pax,pay,pbx,pby,px,py)
389      zbcpt = fsline(pbx,pby,pcx,pcy,px,py)
390      zcdpt = fsline(pcx,pcy,pdx,pdy,px,py)
391      zdapt = fsline(pdx,pdy,pax,pay,px,py)
392       
393      ! We compare the semi plane T with the semi plane including the point
394      ! to know if it is in this  mesh.
395      ! For numerical reasons it is possible that for a point which is on
396      ! the line we don't have exactly zero with fsline function. We want
397      ! that a point can't be in 2 mesh in the same time, so we put the
398      ! coefficient to zero if it is smaller than 1.E-12
399     
400      IF( ABS(zabpt) <= 1.E-12 ) zabpt = 0.
401      IF( ABS(zbcpt) <= 1.E-12 ) zbcpt = 0.
402      IF( ABS(zcdpt) <= 1.E-12 ) zcdpt = 0.
403      IF( ABS(zdapt) <= 1.E-12 ) zdapt = 0.
404      IF( (zabt*zabpt >  0.) .AND. (zbct*zbcpt >= 0. ) .AND. ( zcdt*zcdpt >= 0. ) .AND. ( zdat*zdapt > 0. )   &
405         .AND. ( px <= MAX(pcx,pdx) ) .AND. ( px >= MIN(pax,pbx) )    &
406         .AND. ( py <= MAX(pby,pcy) ) .AND. ( py >= MIN(pay,pdy) ) ) THEN
407         ldinmesh=.TRUE.
408      ELSE
409         ldinmesh=.FALSE.
410      ENDIF
411      !
412   END SUBROUTINE findmesh
413
414
415   FUNCTION dstnce( pla1, phi1, pla2, phi2 )
416      !! -------------------------------------------------------------
417      !!                 ***  Function dstnce  ***
418      !!         
419      !! ** Purpose :   returns distance (in m) between two geographical
420      !!                points
421      !! ** Method  :
422      !!----------------------------------------------------------------------
423      REAL(wp), INTENT(in) ::   pla1, phi1, pla2, phi2   ! ???
424      !!
425      REAL(wp) ::   dly1, dly2, dlx1, dlx2, dlx, dls, dld, dpi
426      REAL(wp) ::   dstnce
427      !!---------------------------------------------------------------------
428      !
429      dpi  = 2.* ASIN(1.)
430      dls  = dpi / 180.
431      dly1 = phi1 * dls
432      dly2 = phi2 * dls
433      dlx1 = pla1 * dls
434      dlx2 = pla2 * dls
435      !
436      dlx = SIN(dly1) * SIN(dly2) + COS(dly1) * COS(dly2) * COS(dlx2-dlx1)
437      !
438      IF( ABS(dlx) > 1.0 ) dlx = 1.0
439      !
440      dld = ATAN(DSQRT( 1.d0 * ( 1.-dlx )/( 1.+dlx ) )) * 222.24 / dls
441      dstnce = dld * 1000.
442      !
443   END FUNCTION dstnce
444
445
446#  else
447   !!----------------------------------------------------------------------
448   !!   Default option                                         Empty module
449   !!----------------------------------------------------------------------
450CONTAINS
451   SUBROUTINE flo_dom                 ! Empty routine
452         WRITE(*,*) 'flo_dom: : You should not have seen this print! error?'
453   END SUBROUTINE flo_dom
454#endif
455
456   !!======================================================================
457END MODULE flodom
Note: See TracBrowser for help on using the repository browser.