1 | MODULE flowri |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE flowri *** |
---|
4 | !! |
---|
5 | !! Ocean floats: write floats trajectory in ascii ln_flo_ascii = T |
---|
6 | !! or in netcdf ( IOM or IOSPSL ) ln_flo_ascii = F |
---|
7 | !!====================================================================== |
---|
8 | !! History : OPA ! 1999-09 (Y. Drillet) : Original code |
---|
9 | !! - ! 2000-06 (J.-M. Molines) : Profiling floats for CLS |
---|
10 | !! NEMO 1.0 ! 2002-10 (A. Bozec) F90 : Free form and module |
---|
11 | !! 3.2 ! 2010-08 (slaw, cbricaud): netcdf outputs and others |
---|
12 | !!---------------------------------------------------------------------- |
---|
13 | #if defined key_floats |
---|
14 | !!---------------------------------------------------------------------- |
---|
15 | !! 'key_floats' float trajectories |
---|
16 | !!---------------------------------------------------------------------- |
---|
17 | USE flo_oce ! ocean drifting floats |
---|
18 | USE oce ! ocean dynamics and tracers |
---|
19 | USE dom_oce ! ocean space and time domain |
---|
20 | USE lib_mpp ! distribued memory computing library |
---|
21 | USE in_out_manager ! I/O manager |
---|
22 | USE phycst ! physic constants |
---|
23 | USE dianam ! build name of file (routine) |
---|
24 | USE ioipsl |
---|
25 | USE iom ! I/O library |
---|
26 | |
---|
27 | IMPLICIT NONE |
---|
28 | PRIVATE |
---|
29 | |
---|
30 | PUBLIC flo_wri ! routine called by floats.F90 |
---|
31 | PUBLIC flo_wri_alloc ! routine called by floats.F90 |
---|
32 | |
---|
33 | INTEGER :: jfl ! number of floats |
---|
34 | CHARACTER (len=80) :: clname ! netcdf output filename |
---|
35 | |
---|
36 | REAL(wp), ALLOCATABLE, DIMENSION(:) :: zlon , zlat, zdep ! 2D workspace |
---|
37 | REAL(wp), ALLOCATABLE, DIMENSION(:) :: ztem , zsal, zrho ! 2D workspace |
---|
38 | |
---|
39 | !!---------------------------------------------------------------------- |
---|
40 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
41 | !! $Id$ |
---|
42 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
43 | !!---------------------------------------------------------------------- |
---|
44 | CONTAINS |
---|
45 | |
---|
46 | INTEGER FUNCTION flo_wri_alloc() |
---|
47 | !!------------------------------------------------------------------- |
---|
48 | !! *** FUNCTION flo_wri_alloc *** |
---|
49 | !!------------------------------------------------------------------- |
---|
50 | ALLOCATE( ztem(jpnfl) , zsal(jpnfl) , zrho(jpnfl) , & |
---|
51 | zlon(jpnfl) , zlat(jpnfl) , zdep(jpnfl) , STAT=flo_wri_alloc) |
---|
52 | ! |
---|
53 | CALL mpp_sum ( 'flowri', flo_wri_alloc ) |
---|
54 | IF( flo_wri_alloc /= 0 ) CALL ctl_stop( 'STOP', 'flo_wri_alloc: failed to allocate arrays.' ) |
---|
55 | END FUNCTION flo_wri_alloc |
---|
56 | |
---|
57 | SUBROUTINE flo_wri( kt, Kmm ) |
---|
58 | !!--------------------------------------------------------------------- |
---|
59 | !! *** ROUTINE flo_wri *** |
---|
60 | !! |
---|
61 | !! ** Purpose : Write position of floats in "trajec_float.nc",according |
---|
62 | !! to ARIANE TOOLS (http://stockage.univ-brest.fr/~grima/Ariane/ ) n |
---|
63 | !! nomenclature |
---|
64 | !! |
---|
65 | !! |
---|
66 | !! ** Method : The frequency of ??? is nwritefl |
---|
67 | !! |
---|
68 | !!---------------------------------------------------------------------- |
---|
69 | !! * Arguments |
---|
70 | INTEGER, INTENT(in) :: kt ! time step |
---|
71 | INTEGER, INTENT(in) :: Kmm ! time level index |
---|
72 | |
---|
73 | !! * Local declarations |
---|
74 | INTEGER :: iafl , ibfl , icfl ! temporary integer |
---|
75 | INTEGER :: ia1fl, ib1fl, ic1fl ! " |
---|
76 | INTEGER :: iafloc,ibfloc,ia1floc,ib1floc ! " |
---|
77 | INTEGER :: irec, irecflo |
---|
78 | |
---|
79 | REAL(wp) :: zafl,zbfl,zcfl ! temporary real |
---|
80 | REAL(wp) :: ztime ! " |
---|
81 | |
---|
82 | INTEGER, DIMENSION(2) :: icount |
---|
83 | INTEGER, DIMENSION(2) :: istart |
---|
84 | INTEGER, DIMENSION(1) :: ish |
---|
85 | INTEGER, DIMENSION(2) :: ish2 |
---|
86 | !!---------------------------------------------------------------------- |
---|
87 | |
---|
88 | !----------------------------------------------------- |
---|
89 | ! I- Save positions, temperature, salinty and density |
---|
90 | !----------------------------------------------------- |
---|
91 | zlon(:)=0.0 ; zlat(:)=0.0 ; zdep(:)=0.0 |
---|
92 | ztem(:)=0.0 ; zsal(:)=0.0 ; zrho(:)=0.0 |
---|
93 | |
---|
94 | DO jfl = 1, jpnfl |
---|
95 | |
---|
96 | iafl = INT (tpifl(jfl)) ! I-index of the nearest point before |
---|
97 | ibfl = INT (tpjfl(jfl)) ! J-index of the nearest point before |
---|
98 | icfl = INT (tpkfl(jfl)) ! K-index of the nearest point before |
---|
99 | ia1fl = iafl + 1 ! I-index of the nearest point after |
---|
100 | ib1fl = ibfl + 1 ! J-index of the nearest point after |
---|
101 | ic1fl = icfl + 1 ! K-index of the nearest point after |
---|
102 | zafl = tpifl(jfl) - REAL(iafl,wp) ! distance ????? |
---|
103 | zbfl = tpjfl(jfl) - REAL(ibfl,wp) ! distance ????? |
---|
104 | zcfl = tpkfl(jfl) - REAL(icfl,wp) ! distance ????? |
---|
105 | |
---|
106 | IF( lk_mpp ) THEN |
---|
107 | |
---|
108 | iafloc = mi1( iafl ) |
---|
109 | ibfloc = mj1( ibfl ) |
---|
110 | |
---|
111 | IF( nldi <= iafloc .AND. iafloc <= nlei .AND. & |
---|
112 | & nldj <= ibfloc .AND. ibfloc <= nlej ) THEN |
---|
113 | |
---|
114 | !the float is inside of current proc's area |
---|
115 | ia1floc = iafloc + 1 |
---|
116 | ib1floc = ibfloc + 1 |
---|
117 | |
---|
118 | !save position of the float |
---|
119 | zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) & |
---|
120 | + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc) |
---|
121 | zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) & |
---|
122 | + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc) |
---|
123 | zdep(jfl) = (1.-zcfl)*gdepw(iafloc,ibfloc,icfl ,Kmm) + zcfl * gdepw(iafloc,ibfloc,ic1fl,Kmm) |
---|
124 | |
---|
125 | !save temperature, salinity and density at this position |
---|
126 | ztem(jfl) = ts(iafloc,ibfloc,icfl,jp_tem,Kmm) |
---|
127 | zsal (jfl) = ts(iafloc,ibfloc,icfl,jp_sal,Kmm) |
---|
128 | zrho (jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0 |
---|
129 | |
---|
130 | ENDIF |
---|
131 | |
---|
132 | ELSE ! mono proc case |
---|
133 | |
---|
134 | iafloc = iafl |
---|
135 | ibfloc = ibfl |
---|
136 | ia1floc = iafloc + 1 |
---|
137 | ib1floc = ibfloc + 1 |
---|
138 | |
---|
139 | !save position of the float |
---|
140 | zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) & |
---|
141 | + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc) |
---|
142 | zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) & |
---|
143 | + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc) |
---|
144 | zdep(jfl) = (1.-zcfl)*gdepw(iafloc,ibfloc,icfl ,Kmm) + zcfl * gdepw(iafloc,ibfloc,ic1fl,Kmm) |
---|
145 | |
---|
146 | ztem(jfl) = ts(iafloc,ibfloc,icfl,jp_tem,Kmm) |
---|
147 | zsal(jfl) = ts(iafloc,ibfloc,icfl,jp_sal,Kmm) |
---|
148 | zrho(jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0 |
---|
149 | |
---|
150 | ENDIF |
---|
151 | |
---|
152 | END DO ! loop on float |
---|
153 | |
---|
154 | !Only proc 0 writes all positions : SUM of positions on all procs |
---|
155 | IF( lk_mpp ) THEN |
---|
156 | CALL mpp_sum( 'flowri', zlon, jpnfl ) ! sums over the global domain |
---|
157 | CALL mpp_sum( 'flowri', zlat, jpnfl ) ! sums over the global domain |
---|
158 | CALL mpp_sum( 'flowri', zdep, jpnfl ) ! sums over the global domain |
---|
159 | CALL mpp_sum( 'flowri', ztem, jpnfl ) ! sums over the global domain |
---|
160 | CALL mpp_sum( 'flowri', zsal, jpnfl ) ! sums over the global domain |
---|
161 | CALL mpp_sum( 'flowri', zrho, jpnfl ) ! sums over the global domain |
---|
162 | ENDIF |
---|
163 | |
---|
164 | |
---|
165 | !-------------------------------------! |
---|
166 | ! II- WRITE WRITE WRITE WRITE WRITE ! |
---|
167 | !-------------------------------------! |
---|
168 | |
---|
169 | !--------------------------! |
---|
170 | ! II-1 Write in ascii file ! |
---|
171 | !--------------------------! |
---|
172 | |
---|
173 | IF( ln_flo_ascii )THEN |
---|
174 | |
---|
175 | IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN |
---|
176 | |
---|
177 | !II-1-a Open ascii file |
---|
178 | !---------------------- |
---|
179 | IF( kt == nn_it000 ) THEN |
---|
180 | CALL ctl_opn( numflo, 'trajec_float', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. ) |
---|
181 | irecflo = NINT( (nitend-nn_it000) / FLOAT(nn_writefl) ) |
---|
182 | WRITE(numflo,*)cexper,no,irecflo,jpnfl,nn_writefl |
---|
183 | ENDIF |
---|
184 | |
---|
185 | !II-1-b Write in ascii file |
---|
186 | !----------------------------- |
---|
187 | WRITE(numflo,*) zlon,zlat,zdep,nisobfl,ngrpfl,ztem,zsal, FLOAT(ndastp) |
---|
188 | |
---|
189 | |
---|
190 | !II-1-c Close netcdf file |
---|
191 | !------------------------- |
---|
192 | IF( kt == nitend ) CLOSE( numflo ) |
---|
193 | |
---|
194 | ENDIF |
---|
195 | |
---|
196 | !----------------------------------------------------- |
---|
197 | ! II-2 Write in netcdf file |
---|
198 | !----------------------------------------------------- |
---|
199 | |
---|
200 | ELSE |
---|
201 | |
---|
202 | !II-2-a Write with IOM |
---|
203 | !---------------------- |
---|
204 | |
---|
205 | #if defined key_iomput |
---|
206 | CALL iom_put( "traj_lon" , zlon ) |
---|
207 | CALL iom_put( "traj_lat" , zlat ) |
---|
208 | CALL iom_put( "traj_dep" , zdep ) |
---|
209 | CALL iom_put( "traj_temp" , ztem ) |
---|
210 | CALL iom_put( "traj_salt" , zsal ) |
---|
211 | CALL iom_put( "traj_dens" , zrho ) |
---|
212 | CALL iom_put( "traj_group" , REAL(ngrpfl,wp) ) |
---|
213 | #else |
---|
214 | |
---|
215 | !II-2-b Write with IOIPSL |
---|
216 | !------------------------ |
---|
217 | |
---|
218 | IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN |
---|
219 | |
---|
220 | |
---|
221 | !II-2-b-1 Open netcdf file |
---|
222 | !------------------------- |
---|
223 | IF( kt==nn_it000 )THEN ! Create and open |
---|
224 | |
---|
225 | CALL dia_nam( clname, nn_writefl, 'trajec_float' ) |
---|
226 | clname=TRIM(clname)//".nc" |
---|
227 | |
---|
228 | CALL fliocrfd( clname , (/ 'ntraj' , 't' /), (/ jpnfl , -1 /) , numflo ) |
---|
229 | |
---|
230 | CALL fliodefv( numflo, 'traj_lon' , (/1,2/), v_t=flio_r8, long_name="Longitude" , units="degrees_east" ) |
---|
231 | CALL fliodefv( numflo, 'traj_lat' , (/1,2/), v_t=flio_r8, long_name="Latitude" , units="degrees_north" ) |
---|
232 | CALL fliodefv( numflo, 'traj_depth' , (/1,2/), v_t=flio_r8, long_name="Depth" , units="meters" ) |
---|
233 | CALL fliodefv( numflo, 'time_counter', (/2/) , v_t=flio_r8, long_name="Time axis" & |
---|
234 | & , units="seconds since start of the run " ) |
---|
235 | CALL fliodefv( numflo, 'traj_temp' , (/1,2/), v_t=flio_r8, long_name="Temperature" , units="C" ) |
---|
236 | CALL fliodefv( numflo, 'traj_salt' , (/1,2/), v_t=flio_r8, long_name="Salinity" , units="PSU" ) |
---|
237 | CALL fliodefv( numflo, 'traj_dens' , (/1,2/), v_t=flio_r8, long_name="Density" , units="kg/m3" ) |
---|
238 | CALL fliodefv( numflo, 'traj_group' , (/1/) , v_t=flio_r8, long_name="number of the group" , units="no unit" ) |
---|
239 | |
---|
240 | CALL flioputv( numflo , 'traj_group' , REAL(ngrpfl,wp) ) |
---|
241 | |
---|
242 | ELSE ! Re-open |
---|
243 | |
---|
244 | CALL flioopfd( TRIM(clname), numflo , "WRITE" ) |
---|
245 | |
---|
246 | ENDIF |
---|
247 | |
---|
248 | !II-2-b-2 Write in netcdf file |
---|
249 | !------------------------------- |
---|
250 | irec = INT( (kt-nn_it000+1)/nn_writefl ) +1 |
---|
251 | ztime = ( kt-nn_it000 + 1 ) * rdt |
---|
252 | |
---|
253 | CALL flioputv( numflo , 'time_counter', ztime , start=(/irec/) ) |
---|
254 | |
---|
255 | DO jfl = 1, jpnfl |
---|
256 | |
---|
257 | istart = (/jfl,irec/) |
---|
258 | icfl = INT( tpkfl(jfl) ) ! K-index of the nearest point before |
---|
259 | |
---|
260 | CALL flioputv( numflo , 'traj_lon' , zlon(jfl) , start=istart ) |
---|
261 | CALL flioputv( numflo , 'traj_lat' , zlat(jfl) , start=istart ) |
---|
262 | CALL flioputv( numflo , 'traj_depth' , zdep(jfl) , start=istart ) |
---|
263 | CALL flioputv( numflo , 'traj_temp' , ztemp(icfl,jfl) , start=istart ) |
---|
264 | CALL flioputv( numflo , 'traj_salt' , zsal(icfl,jfl) , start=istart ) |
---|
265 | CALL flioputv( numflo , 'traj_dens' , zrho(icfl,jfl) , start=istart ) |
---|
266 | |
---|
267 | ENDDO |
---|
268 | |
---|
269 | !II-2-b-3 Close netcdf file |
---|
270 | !--------------------------- |
---|
271 | CALL flioclo( numflo ) |
---|
272 | |
---|
273 | ENDIF |
---|
274 | |
---|
275 | #endif |
---|
276 | ENDIF ! netcdf writing |
---|
277 | |
---|
278 | END SUBROUTINE flo_wri |
---|
279 | |
---|
280 | |
---|
281 | # else |
---|
282 | !!---------------------------------------------------------------------- |
---|
283 | !! Default option Empty module |
---|
284 | !!---------------------------------------------------------------------- |
---|
285 | CONTAINS |
---|
286 | SUBROUTINE flo_wri ! Empty routine |
---|
287 | END SUBROUTINE flo_wri |
---|
288 | #endif |
---|
289 | |
---|
290 | !!======================================================================= |
---|
291 | END MODULE flowri |
---|