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 ) |
---|
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 :: kt ! time step |
---|
71 | |
---|
72 | !! * Local declarations |
---|
73 | INTEGER :: iafl , ibfl , icfl ! temporary integer |
---|
74 | INTEGER :: ia1fl, ib1fl, ic1fl ! " |
---|
75 | INTEGER :: iafloc,ibfloc,ia1floc,ib1floc ! " |
---|
76 | INTEGER :: irec, irecflo |
---|
77 | |
---|
78 | REAL(wp) :: zafl,zbfl,zcfl ! temporary real |
---|
79 | REAL(wp) :: ztime ! " |
---|
80 | |
---|
81 | INTEGER, DIMENSION(2) :: icount |
---|
82 | INTEGER, DIMENSION(2) :: istart |
---|
83 | INTEGER, DIMENSION(1) :: ish |
---|
84 | INTEGER, DIMENSION(2) :: ish2 |
---|
85 | !!---------------------------------------------------------------------- |
---|
86 | |
---|
87 | !----------------------------------------------------- |
---|
88 | ! I- Save positions, temperature, salinty and density |
---|
89 | !----------------------------------------------------- |
---|
90 | zlon(:)=0.0 ; zlat(:)=0.0 ; zdep(:)=0.0 |
---|
91 | ztem(:)=0.0 ; zsal(:)=0.0 ; zrho(:)=0.0 |
---|
92 | |
---|
93 | DO jfl = 1, jpnfl |
---|
94 | |
---|
95 | iafl = INT (tpifl(jfl)) ! I-index of the nearest point before |
---|
96 | ibfl = INT (tpjfl(jfl)) ! J-index of the nearest point before |
---|
97 | icfl = INT (tpkfl(jfl)) ! K-index of the nearest point before |
---|
98 | ia1fl = iafl + 1 ! I-index of the nearest point after |
---|
99 | ib1fl = ibfl + 1 ! J-index of the nearest point after |
---|
100 | ic1fl = icfl + 1 ! K-index of the nearest point after |
---|
101 | zafl = tpifl(jfl) - REAL(iafl,wp) ! distance ????? |
---|
102 | zbfl = tpjfl(jfl) - REAL(ibfl,wp) ! distance ????? |
---|
103 | zcfl = tpkfl(jfl) - REAL(icfl,wp) ! distance ????? |
---|
104 | |
---|
105 | IF( lk_mpp ) THEN |
---|
106 | |
---|
107 | iafloc = mi1( iafl ) |
---|
108 | ibfloc = mj1( ibfl ) |
---|
109 | |
---|
110 | IF( nldi <= iafloc .AND. iafloc <= nlei .AND. & |
---|
111 | & nldj <= ibfloc .AND. ibfloc <= nlej ) THEN |
---|
112 | |
---|
113 | !the float is inside of current proc's area |
---|
114 | ia1floc = iafloc + 1 |
---|
115 | ib1floc = ibfloc + 1 |
---|
116 | |
---|
117 | !save position of the float |
---|
118 | zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) & |
---|
119 | + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc) |
---|
120 | zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) & |
---|
121 | + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc) |
---|
122 | zdep(jfl) = (1.-zcfl)*gdepw_n(iafloc,ibfloc,icfl ) + zcfl * gdepw_n(iafloc,ibfloc,ic1fl) |
---|
123 | |
---|
124 | !save temperature, salinity and density at this position |
---|
125 | ztem(jfl) = tsn(iafloc,ibfloc,icfl,jp_tem) |
---|
126 | zsal (jfl) = tsn(iafloc,ibfloc,icfl,jp_sal) |
---|
127 | zrho (jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0 |
---|
128 | |
---|
129 | ENDIF |
---|
130 | |
---|
131 | ELSE ! mono proc case |
---|
132 | |
---|
133 | iafloc = iafl |
---|
134 | ibfloc = ibfl |
---|
135 | ia1floc = iafloc + 1 |
---|
136 | ib1floc = ibfloc + 1 |
---|
137 | |
---|
138 | !save position of the float |
---|
139 | zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) & |
---|
140 | + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc) |
---|
141 | zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) & |
---|
142 | + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc) |
---|
143 | zdep(jfl) = (1.-zcfl)*gdepw_n(iafloc,ibfloc,icfl ) + zcfl * gdepw_n(iafloc,ibfloc,ic1fl) |
---|
144 | |
---|
145 | ztem(jfl) = tsn(iafloc,ibfloc,icfl,jp_tem) |
---|
146 | zsal(jfl) = tsn(iafloc,ibfloc,icfl,jp_sal) |
---|
147 | zrho(jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0 |
---|
148 | |
---|
149 | ENDIF |
---|
150 | |
---|
151 | END DO ! loop on float |
---|
152 | |
---|
153 | !Only proc 0 writes all positions : SUM of positions on all procs |
---|
154 | IF( lk_mpp ) THEN |
---|
155 | CALL mpp_sum( 'flowri', zlon, jpnfl ) ! sums over the global domain |
---|
156 | CALL mpp_sum( 'flowri', zlat, jpnfl ) ! sums over the global domain |
---|
157 | CALL mpp_sum( 'flowri', zdep, jpnfl ) ! sums over the global domain |
---|
158 | CALL mpp_sum( 'flowri', ztem, jpnfl ) ! sums over the global domain |
---|
159 | CALL mpp_sum( 'flowri', zsal, jpnfl ) ! sums over the global domain |
---|
160 | CALL mpp_sum( 'flowri', zrho, jpnfl ) ! sums over the global domain |
---|
161 | ENDIF |
---|
162 | |
---|
163 | |
---|
164 | !-------------------------------------! |
---|
165 | ! II- WRITE WRITE WRITE WRITE WRITE ! |
---|
166 | !-------------------------------------! |
---|
167 | |
---|
168 | !--------------------------! |
---|
169 | ! II-1 Write in ascii file ! |
---|
170 | !--------------------------! |
---|
171 | |
---|
172 | IF( ln_flo_ascii )THEN |
---|
173 | |
---|
174 | IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN |
---|
175 | |
---|
176 | !II-1-a Open ascii file |
---|
177 | !---------------------- |
---|
178 | IF( kt == nn_it000 ) THEN |
---|
179 | CALL ctl_opn( numflo, 'trajec_float', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. ) |
---|
180 | irecflo = NINT( (nitend-nn_it000) / FLOAT(nn_writefl) ) |
---|
181 | WRITE(numflo,*)cexper,no,irecflo,jpnfl,nn_writefl |
---|
182 | ENDIF |
---|
183 | |
---|
184 | !II-1-b Write in ascii file |
---|
185 | !----------------------------- |
---|
186 | WRITE(numflo,*) zlon,zlat,zdep,nisobfl,ngrpfl,ztem,zsal, FLOAT(ndastp) |
---|
187 | |
---|
188 | |
---|
189 | !II-1-c Close netcdf file |
---|
190 | !------------------------- |
---|
191 | IF( kt == nitend ) CLOSE( numflo ) |
---|
192 | |
---|
193 | ENDIF |
---|
194 | |
---|
195 | !----------------------------------------------------- |
---|
196 | ! II-2 Write in netcdf file |
---|
197 | !----------------------------------------------------- |
---|
198 | |
---|
199 | ELSE |
---|
200 | |
---|
201 | !II-2-a Write with IOM |
---|
202 | !---------------------- |
---|
203 | |
---|
204 | #if defined key_iomput |
---|
205 | CALL iom_put( "traj_lon" , zlon ) |
---|
206 | CALL iom_put( "traj_lat" , zlat ) |
---|
207 | CALL iom_put( "traj_dep" , zdep ) |
---|
208 | CALL iom_put( "traj_temp" , ztem ) |
---|
209 | CALL iom_put( "traj_salt" , zsal ) |
---|
210 | CALL iom_put( "traj_dens" , zrho ) |
---|
211 | CALL iom_put( "traj_group" , REAL(ngrpfl,wp) ) |
---|
212 | #else |
---|
213 | |
---|
214 | !II-2-b Write with IOIPSL |
---|
215 | !------------------------ |
---|
216 | |
---|
217 | IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN |
---|
218 | |
---|
219 | |
---|
220 | !II-2-b-1 Open netcdf file |
---|
221 | !------------------------- |
---|
222 | IF( kt==nn_it000 )THEN ! Create and open |
---|
223 | |
---|
224 | CALL dia_nam( clname, nn_writefl, 'trajec_float' ) |
---|
225 | clname=TRIM(clname)//".nc" |
---|
226 | |
---|
227 | CALL fliocrfd( clname , (/ 'ntraj' , 't' /), (/ jpnfl , -1 /) , numflo ) |
---|
228 | |
---|
229 | CALL fliodefv( numflo, 'traj_lon' , (/1,2/), v_t=flio_r8, long_name="Longitude" , units="degrees_east" ) |
---|
230 | CALL fliodefv( numflo, 'traj_lat' , (/1,2/), v_t=flio_r8, long_name="Latitude" , units="degrees_north" ) |
---|
231 | CALL fliodefv( numflo, 'traj_depth' , (/1,2/), v_t=flio_r8, long_name="Depth" , units="meters" ) |
---|
232 | CALL fliodefv( numflo, 'time_counter', (/2/) , v_t=flio_r8, long_name="Time axis" & |
---|
233 | & , units="seconds since start of the run " ) |
---|
234 | CALL fliodefv( numflo, 'traj_temp' , (/1,2/), v_t=flio_r8, long_name="Temperature" , units="C" ) |
---|
235 | CALL fliodefv( numflo, 'traj_salt' , (/1,2/), v_t=flio_r8, long_name="Salinity" , units="PSU" ) |
---|
236 | CALL fliodefv( numflo, 'traj_dens' , (/1,2/), v_t=flio_r8, long_name="Density" , units="kg/m3" ) |
---|
237 | CALL fliodefv( numflo, 'traj_group' , (/1/) , v_t=flio_r8, long_name="number of the group" , units="no unit" ) |
---|
238 | |
---|
239 | CALL flioputv( numflo , 'traj_group' , REAL(ngrpfl,wp) ) |
---|
240 | |
---|
241 | ELSE ! Re-open |
---|
242 | |
---|
243 | CALL flioopfd( TRIM(clname), numflo , "WRITE" ) |
---|
244 | |
---|
245 | ENDIF |
---|
246 | |
---|
247 | !II-2-b-2 Write in netcdf file |
---|
248 | !------------------------------- |
---|
249 | irec = INT( (kt-nn_it000+1)/nn_writefl ) +1 |
---|
250 | ztime = ( kt-nn_it000 + 1 ) * rdt |
---|
251 | |
---|
252 | CALL flioputv( numflo , 'time_counter', ztime , start=(/irec/) ) |
---|
253 | |
---|
254 | DO jfl = 1, jpnfl |
---|
255 | |
---|
256 | istart = (/jfl,irec/) |
---|
257 | icfl = INT( tpkfl(jfl) ) ! K-index of the nearest point before |
---|
258 | |
---|
259 | CALL flioputv( numflo , 'traj_lon' , zlon(jfl) , start=istart ) |
---|
260 | CALL flioputv( numflo , 'traj_lat' , zlat(jfl) , start=istart ) |
---|
261 | CALL flioputv( numflo , 'traj_depth' , zdep(jfl) , start=istart ) |
---|
262 | CALL flioputv( numflo , 'traj_temp' , ztemp(icfl,jfl) , start=istart ) |
---|
263 | CALL flioputv( numflo , 'traj_salt' , zsal(icfl,jfl) , start=istart ) |
---|
264 | CALL flioputv( numflo , 'traj_dens' , zrho(icfl,jfl) , start=istart ) |
---|
265 | |
---|
266 | ENDDO |
---|
267 | |
---|
268 | !II-2-b-3 Close netcdf file |
---|
269 | !--------------------------- |
---|
270 | CALL flioclo( numflo ) |
---|
271 | |
---|
272 | ENDIF |
---|
273 | |
---|
274 | #endif |
---|
275 | ENDIF ! netcdf writing |
---|
276 | |
---|
277 | END SUBROUTINE flo_wri |
---|
278 | |
---|
279 | |
---|
280 | # else |
---|
281 | !!---------------------------------------------------------------------- |
---|
282 | !! Default option Empty module |
---|
283 | !!---------------------------------------------------------------------- |
---|
284 | CONTAINS |
---|
285 | SUBROUTINE flo_wri ! Empty routine |
---|
286 | END SUBROUTINE flo_wri |
---|
287 | #endif |
---|
288 | |
---|
289 | !!======================================================================= |
---|
290 | END MODULE flowri |
---|