SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
modi_gltools_avevai.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 !GLT_LIC The GELATO model is a seaice model used in stand-alone or embedded mode.
6 !GLT_LIC It has been developed by Meteo-France. The holder of GELATO is Meteo-France.
7 !GLT_LIC
8 !GLT_LIC This software is governed by the CeCILL-C license under French law and biding
9 !GLT_LIC by the rules of distribution of free software. See the CeCILL-C_V1-en.txt
10 !GLT_LIC (English) and CeCILL-C_V1-fr.txt (French) for details. The CeCILL is a free
11 !GLT_LIC software license, explicitly compatible with the GNU GPL
12 !GLT_LIC (see http://www.gnu.org/licenses/license-list.en.html#CeCILL)
13 !GLT_LIC
14 !GLT_LIC The CeCILL-C licence agreement grants users the right to modify and re-use the
15 !GLT_LIC software governed by this free software license. The exercising of this right
16 !GLT_LIC is conditional upon the obligation to make available to the community the
17 !GLT_LIC modifications made to the source code of the software so as to contribute to
18 !GLT_LIC its evolution.
19 !GLT_LIC
20 !GLT_LIC In consideration of access to the source code and the rights to copy, modify
21 !GLT_LIC and redistribute granted by the license, users are provided only with a limited
22 !GLT_LIC warranty and the software's author, the holder of the economic rights, and the
23 !GLT_LIC successive licensors only have limited liability. In this respect, the risks
24 !GLT_LIC associated with loading, using, modifying and/or developing or reproducing the
25 !GLT_LIC software by the user are brought to the user's attention, given its Free
26 !GLT_LIC Software status, which may make it complicated to use, with the result that its
27 !GLT_LIC use is reserved for developers and experienced professionals having in-depth
28 !GLT_LIC computer knowledge. Users are therefore encouraged to load and test the
29 !GLT_LIC suitability of the software as regards their requirements in conditions enabling
30 !GLT_LIC the security of their systems and/or data to be ensured and, more generally, to
31 !GLT_LIC use and operate it in the same conditions of security.
32 !GLT_LIC
33 !GLT_LIC The GELATO sofware is cureently distibuted with the SURFEX software, available at
34 !GLT_LIC http://www.cnrm.meteo.fr/surfex. The fact that you download the software deemed that
35 !GLT_LIC you had knowledge of the CeCILL-C license and that you accept its terms.
36 !GLT_LIC Attempts to use this software in a way not complying with CeCILL-C license
37 !GLT_LIC may lead to prosecution.
38 !GLT_LIC
39 ! =======================================================================
40 ! ====================== MODULE modi_gltools_avevai =======================
41 ! =======================================================================
42 !
43 ! Goal:
44 ! -----
45 ! Write a diagnostic field in Vairmer format
46 !
47 ! Created : 2004/03 (D. Salas y Melia)
48 ! Modified: 2012/07 (D. Salas y Melia) Parallelism
49 !
50 ! -------------------- BEGIN MODULE modi_gltools_avevai -------------------
51 !
52 !THXS_SFX!MODULE modi_gltools_avevai
53 !THXS_SFX!INTERFACE
54 !THXS_SFX!!
55 !THXS_SFX!SUBROUTINE gltools_avevai &
56 !THXS_SFX! ( tpind,tpnam,pfield,pcumdia,pwgt )
57 !THXS_SFX!!
58 !THXS_SFX! USE modd_glt_param
59 !THXS_SFX! USE modd_types_glt
60 !THXS_SFX! TYPE(t_ind), INTENT(inout) :: &
61 !THXS_SFX! tpind
62 !THXS_SFX! TYPE(t_def), INTENT(in) :: &
63 !THXS_SFX! tpnam
64 !THXS_SFX! REAL, DIMENSION(:,:), INTENT(in) :: &
65 !THXS_SFX! pfield
66 !THXS_SFX! REAL, DIMENSION(:,:,:), INTENT(inout) :: &
67 !THXS_SFX! pcumdia
68 !THXS_SFX! REAL, DIMENSION(:,:), OPTIONAL, INTENT(inout) :: &
69 !THXS_SFX! pwgt
70 !THXS_SFX!END SUBROUTINE gltools_avevai
71 !THXS_SFX!!
72 !THXS_SFX!END INTERFACE
73 !THXS_SFX!END MODULE modi_gltools_avevai
74 !
75 ! -------------------- END MODULE modi_gltools_avevai ---------------------
76 !
77 !
78 ! -----------------------------------------------------------------------
79 ! -------------------------- SUBROUTINE gltools_avevai --------------------------
80 !
81 SUBROUTINE gltools_avevai &
82  ( tpind,tpnam,pfield,pcumdia,pwgt )
83 !
84  USE modd_glt_param
85  USE modd_types_glt
87  USE modi_gltools_strlower
88 #if ! defined in_surfex
89  USE mode_gltools_mpi
90  USE mode_gltools_bound
91 #else
92 #if ! defined in_arpege
94 #endif
95 #endif
96  IMPLICIT NONE
97 !
98 !* Arguments
99 !
100  TYPE(t_ind), INTENT(inout) :: &
101  tpind
102  TYPE(t_def), INTENT(in) :: &
103  tpnam
104  REAL, DIMENSION(:,:), INTENT(in) :: &
105  pfield
106  REAL, DIMENSION(:,:,:), INTENT(inout) :: &
107  pcumdia
108  REAL, DIMENSION(:,:), OPTIONAL, INTENT(inout) :: &
109  pwgt
110 !
111 !* Local variables
112 !
113  LOGICAL :: &
114  yis0d,yis2d
115  CHARACTER(1) :: &
116  ypos
117  CHARACTER(6) :: &
118  ytype
119  INTEGER :: &
120  ix,iy,ixc,iyc,ilu,ifld
121  REAL, DIMENSION(:,:), ALLOCATABLE :: &
122  zwork2
123  REAL, DIMENSION(:,:), ALLOCATABLE :: &
124  zwork2_g
125  REAL(KIND=4), DIMENSION(:,:), ALLOCATABLE :: &
126  zwork2_gr4
127 !
128 !
129 !
130 ! 1. Initialisation
131 ! ==================
132 !
133 ! .. Get sizes of input data field
134 !
135  ix = SIZE( pfield,1 )
136  iy = SIZE( pfield,2 )
137  yis0d = ( ix==1 .AND. iy==1 )
138  yis2d = ( ix==nx .AND. iy==ny )
139 !
140 ! .. Accumulation
141 !
142  IF ( yis2d ) THEN
143  tpind%i2d = tpind%i2d+1
144  ifld = tpind%i2d
145  ELSE IF ( yis0d ) THEN
146  tpind%i0d = tpind%i0d+1
147  ifld = tpind%i0d
148  ELSE
149  IF (lwg) THEN
150  WRITE(noutlu,*) '==> Input field size=',ix,iy
151  WRITE(noutlu,*) '==> Routine gltools_avevai can only be used to write &
152  & fields with dimensions',nxglo,nyglo,' or 1,1.'
153  WRITE(noutlu,*) 'We stop.'
154  ENDIF
155  stop
156  ENDIF
157  pcumdia(ifld,:,:) = pcumdia(ifld,:,:) + pfield(:,:)
158 !
159 ! .. Define parameters
160 !
161  ypos = tpnam%loc
162  ytype = gltools_strlower( trim(tpnam%typ) )
163 !
164 !
165 !
166 ! 2. Average and save (if last time step)
167 ! ========================================
168 !
169  IF ( (tpind%cur==tpind%end) .OR. &
170  ( modulo(tpind%cur * dtt, dttave * xday2sec) .LE. epsil1) &
171  ) THEN
172 !
173 ! .. Average
174 !
175 ! Specialised averaging (for e.g. ice salinity, we want an average only
176 ! for time steps when there is sea ice !)
177 !
178  IF ( yis2d ) THEN
179  ALLOCATE( zwork2(nx,ny))
180  IF ( present(pwgt) ) THEN
181  WHERE( pwgt(:,:)>0. .AND. pfield(:,:)<xbig20 )
182  zwork2(:,:) = pcumdia(ifld,:,:) / pwgt(:,:)
183  ELSEWHERE
184  zwork2(:,:) = xbig20
185  ENDWHERE
186 ! Regular averaging
187  ELSE
188  zwork2(:,:) = pcumdia(ifld,:,:) / float( tpind%nts )
189  ENDIF
190 !
191 ! .. Boundary conditions
192 !
193 #if ! defined in_surfex
194  CALL gltools_bound( ypos,ytype,zwork2,pval=xbig20 )
195 #endif
196 !
197 ! .. Gather the field to be written
198 !
199  ALLOCATE( zwork2_g(nxglo,nyglo))
200  ALLOCATE( zwork2_gr4(nxglo,nyglo) )
201 #if ! defined in_surfex
202  CALL gather2d( zwork2,zwork2_g )
203 #else
204 #if ! defined in_arpege
205  CALL gather_and_write_mpi( zwork2,zwork2_g )
206 #endif
207 #endif
208  DEALLOCATE( zwork2)
209 !
210 ! .. Correction of bounding with large value on mask for U and V fields
211 !
212  IF ( lwg ) THEN
213  IF ( ypos=='U' .OR. ypos=='V' ) THEN
214  WHERE( zwork2_g(:,:)<-xbig19 )
215  zwork2_g(:,:) = xbig20
216  ENDWHERE
217  ENDIF
218  ENDIF
219 !
220  ELSE
221 !
222  ALLOCATE( zwork2_g(ix,iy))
223  ALLOCATE( zwork2_gr4(ix,iy) )
224  zwork2_g(:,:) = pcumdia(ifld,:,:) / float( tpind%nts )
225 !
226  IF ( modulo(tpind%cur * dtt, dttave * xday2sec) .LE. epsil1) THEN
227 ! Reset accumulation field and weights
228  pcumdia(ifld,:,:)=0.
229  IF ( present(pwgt) ) pwgt(:,:)=0.
230  ENDIF
231 
232 
233  ENDIF
234 !
235  IF ( gelato_myrank == gelato_leadproc ) THEN
236 !
237 ! .. Convert to single precision
238 !
239  zwork2_gr4(:,:) = zwork2_g(:,:)
240 !
241 !
242 !
243 ! 3. Write data
244 ! ==============
245 !
246 !
247 ! .. Define logical unit for writing
248 !
249  IF ( yis2d ) THEN
250  ilu = n2valu
251  ELSE IF ( yis0d ) THEN
252  ilu = n0valu
253  ENDIF
254 !
255 ! .. Write data
256 !
257  WRITE(ilu) trim( tpnam%sna )
258  WRITE(ilu) zwork2_gr4(:,:)
259 !
260  ENDIF
261 !
262 ! .. Deallocate in reverse order (see comments in imod_thermo.f90)
263 !
264  DEALLOCATE( zwork2_g )
265  DEALLOCATE( zwork2_gr4 )
266 !
267  ENDIF
268 !
269  END SUBROUTINE gltools_avevai
270 !
271 ! ------------------------ END SUBROUTINE gltools_avevai ------------------------
272 ! -----------------------------------------------------------------------
character(len=len(hstring)) function gltools_strlower(hstring)
subroutine gltools_avevai(tpind, tpnam, pfield, pcumdia, pwgt)