SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
init_io_surf_fan.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 ! ######################
6  SUBROUTINE init_io_surf_fa_n (DTCO, U, &
7  hprogram,hmask,haction)
8 ! ######################
9 !
10 !!**** *INIT_IO_SURF_FA* Keep in memory the output files
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!
16 !!** IMPLICIT ARGUMENTS
17 !! ------------------
18 !! None
19 !!
20 !! REFERENCE
21 !! ---------
22 !!
23 !! AUTHOR
24 !! ------
25 !! V. Masson *Meteo France*
26 !!
27 !! MODIFICATIONS
28 !! -------------
29 !!
30 !! P. Le Moigne 04/2004: distinguish in and out file name
31 !! P. Le Moigne 04/2006: special HACTION='GTMSK' to initialize
32 !! a mask different of 'FULL ' in order
33 !! to read dimensions only.
34 !! B. Decharme 2008 : Change to switch between offline and online run
35 !! In online run, the mask must be always global
36 !! B. Decharme 2013 : Allocate work variables to write in FA in AROME case
37 !
38 !* 0. DECLARATIONS
39 ! ------------
40 !
41 !
42 !
43 !
45 USE modd_surf_atm_n, ONLY : surf_atm_t
46 !
47 USE modd_surfex_mpi, ONLY : nrank, nindex, npio, nsize
48 !
49 USE modd_surfex_omp, ONLY : nindx2sfx, nwork, nwork2, xwork, xwork2, xwork3, &
50  nwork_full, nwork2_full, xwork_full, xwork2_full
51 !
52 USE modd_csts, ONLY : xpi
53 !
54 USE modd_io_surf_fa,ONLY: nunit_fa, cfilein_fa,cfileout_fa,cdnomc,iverbfa, &
55  nluout,nfull,nfull_ext, cmask, lopen, &
56  ndgl, ndlon, ndlux, ndgux, perpk, pebeta, &
57  pelon0, pelat0, pedelx, pedely, pelon1, pelat1
58 !
59 !
60 USE modi_abor1_sfx
61 USE modi_get_luout
63 USE modi_get_dim_full_n
64 USE modi_get_size_full_n
65 USE modi_get_type_dim_n
66 USE modi_get_surf_mask_n
67 USE modi_get_1d_mask
68 !
69 USE yomhook ,ONLY : lhook, dr_hook
70 USE parkind1 ,ONLY : jprb
71 !
72 IMPLICIT NONE
73 !
74 !
75 TYPE(data_cover_t), INTENT(INOUT) :: dtco
76 TYPE(surf_atm_t), INTENT(INOUT) :: u
77 !
78  CHARACTER(LEN=6), INTENT(IN) :: hprogram
79  CHARACTER(LEN=6), INTENT(IN) :: hmask
80  CHARACTER(LEN=5), INTENT(IN) :: haction
81 !
82 INTEGER :: ilu, iret, il
83 !
84 INTEGER :: inb ! number of articles in the file
85 INTEGER :: ityptr, itronc, inlati, inxlon, iniver
86 INTEGER, DIMENSION (1000) :: inlopa, inozpa
87 !
88 REAL, DIMENSION (1000) :: zsinla
89 REAL, DIMENSION (200) :: zahybr, zbhybr
90 REAL :: zslapo, zclopo, zslopo, zcodil, zrefer
91 LOGICAL :: loutfac
92 !
93 REAL(KIND=JPRB) :: zhook_handle
94 !
95 !------------------------------------------------------------------------------
96 !
97 IF (lhook) CALL dr_hook('INIT_IO_SURF_FA_N',0,zhook_handle)
98 !
99 IF(hprogram/='FA '.AND.hprogram/='AROME ') THEN
100  CALL abor1_sfx('INIT_IO_SURF_FA_N -- HPROGRAM should be FA or AROME')
101 ENDIF
102 !
103  CALL get_luout(hprogram,nluout)
104 !
105 !$OMP BARRIER
106 !
107 IF (nrank==npio) lopen=.false.
108 !
109 IF (haction=='GTMSK') THEN
110  IF (nrank==npio) THEN
111 !$OMP SINGLE
112  CALL faitou(iret,nunit_fa,.true.,cfilein_fa,'OLD',.true.,.false.,iverbfa,0,inb,cdnomc)
113  WRITE(nluout,*)'HPROGRAM ',hprogram,' IO_INIT HACTION==GTMSK',nunit_fa,cfilein_fa
114 !$OMP END SINGLE
115  lopen=.true.
116  ENDIF
117  cmask = hmask
118  IF (lhook) CALL dr_hook('INIT_IO_SURF_FA_N',1,zhook_handle)
119  RETURN
120 ENDIF
121 !
122 IF (haction == 'READ ') THEN
123  IF (nrank==npio) THEN
124 !$OMP SINGLE
125  CALL faitou(iret,nunit_fa,.true.,cfilein_fa,'OLD',.true.,.false.,iverbfa,0,inb,cdnomc)
126  WRITE(nluout,*)'HPROGRAM ',hprogram,' IO_INIT HACTION==READ',nunit_fa,cfilein_fa
127  CALL facage(cdnomc,.true.)
128 !$OMP END SINGLE
129  lopen=.true.
130  ENDIF
131  !
132  IF (hmask /= 'EXTZON') THEN
133  cmask = 'FULL '
134  CALL read_surf(&
135  hprogram,'DIM_FULL',nfull,iret,hdir='A')
136  !
137  nfull_ext = nfull
138  IF (hprogram=='AROME ') THEN
139  u%NDIM_FULL = nfull
140  ENDIF
141  ENDIF
142  !
143 ELSE
144  ! NFULL must be known in every case.
145  CALL get_dim_full_n(u, &
146  nfull)
147 ENDIF
148 !
149 IF (hmask == 'EXTZON') THEN
150  IF (nrank==npio) THEN
151 !$OMP SINGLE
152  CALL facies(cdnomc, ityptr, zslapo, zclopo, zslopo, &
153  zcodil, itronc, inlati, inxlon, inlopa, &
154  inozpa, zsinla, iniver, zrefer, zahybr, &
155  zbhybr, loutfac)
156  nfull_ext = inlati*inxlon
157  ndgl = inlati
158  ndlon = inxlon
159  nfull = inlopa(4)*inlopa(6)
160  ndlux = inlopa(4)
161  ndgux = inlopa(6)
162  pebeta = zslapo
163  perpk = zsinla(2)
164  pelon0 = zsinla(3)*180./xpi
165  pelat0 = zsinla(4)*180./xpi
166  pedelx = zsinla(7)
167  pedely = zsinla(8)
168  pelon1 = zsinla(13)*180./xpi
169  pelat1 = zsinla(14)*180./xpi
170 !$OMP END SINGLE
171  ENDIF
172 ENDIF
173 !
174 IF (.NOT.ALLOCATED(nindex)) THEN
175  ALLOCATE(nindex(nfull))
176  nindex(:) = 0
177 ENDIF
178 !
179 !------------------------------------------------------------------------------
180  cmask=hmask
181 !------------------------------------------------------------------------------
182 !
183 IF (hprogram=='AROME ') THEN
184  nfull = u%NDIM_FULL
185  ilu = nfull
186  il = nfull
187  nsize = nfull
188  nindx2sfx = nfull
189  IF(.NOT.ASSOCIATED(nwork )) ALLOCATE(nwork(nfull))
190  IF(.NOT.ASSOCIATED(xwork )) ALLOCATE(xwork(nfull))
191  IF(.NOT.ASSOCIATED(nwork2)) ALLOCATE(nwork2(nfull,10))
192  IF(.NOT.ASSOCIATED(xwork2)) ALLOCATE(xwork2(nfull,10))
193  IF(.NOT.ASSOCIATED(xwork3)) ALLOCATE(xwork3(nfull,10,10))
194  IF (nrank==npio) THEN
195  IF(.NOT.ASSOCIATED(nwork_full )) ALLOCATE(nwork_full(nfull))
196  IF(.NOT.ASSOCIATED(xwork_full )) ALLOCATE(xwork_full(nfull))
197  IF(.NOT.ASSOCIATED(nwork2_full)) ALLOCATE(nwork2_full(nfull,10))
198  IF(.NOT.ASSOCIATED(xwork2_full)) ALLOCATE(xwork2_full(nfull,10))
199  ELSE
200  IF(.NOT.ASSOCIATED(nwork_full )) ALLOCATE(nwork_full(0))
201  IF(.NOT.ASSOCIATED(xwork_full )) ALLOCATE(xwork_full(0))
202  IF(.NOT.ASSOCIATED(nwork2_full)) ALLOCATE(nwork2_full(0,0))
203  IF(.NOT.ASSOCIATED(xwork2_full)) ALLOCATE(xwork2_full(0,0))
204  ENDIF
205 ELSE
206  CALL get_size_full_n(u, &
207  hprogram,nfull,ilu)
208  IF (ilu>nsize) nsize = ilu
209  il = ilu
210  CALL get_type_dim_n(dtco, u, &
211  hmask,il)
212 ENDIF
213 !
214  CALL get_mask(ilu,il)
215 !
216 !------------------------------------------------------------------------------
217 IF (lhook) CALL dr_hook('INIT_IO_SURF_FA_N',1,zhook_handle)
218 !------------------------------------------------------------------------------
219 !
220  CONTAINS
221 !
222 SUBROUTINE get_mask(KLU,KL)
223 !
224 USE modd_mask, ONLY: nmask_full
225 USE modd_io_surf_fa, ONLY: nmask
226 !
227 IMPLICIT NONE
228 !
229 INTEGER, INTENT(INOUT) :: klu
230 INTEGER, INTENT(IN) :: kl
231 !
232 REAL, DIMENSION(KL) :: zfull
233 INTEGER, DIMENSION(KL) :: imask
234 REAL(KIND=JPRB) :: zhook_handle
235 !
236 IF (lhook) CALL dr_hook('INIT_IO_SURF_FA_N:GET_MASK',0,zhook_handle)
237 !
238 IF (hprogram=='AROME ') THEN
239  zfull = 1.
240  CALL get_1d_mask(klu,klu,zfull,imask)
241  IF (ALLOCATED(nmask_full)) THEN
242  IF (klu>SIZE(nmask_full)) DEALLOCATE(nmask_full)
243  ENDIF
244 ELSE
245  CALL get_surf_mask_n(dtco, u, &
246  hmask,kl,imask,klu,nluout)
247  IF (ALLOCATED(nmask_full)) THEN
248  IF (kl>SIZE(nmask_full)) DEALLOCATE(nmask_full)
249  ENDIF
250 ENDIF
251 !
252 IF (.NOT.ALLOCATED(nmask_full)) ALLOCATE(nmask_full(klu))
253 !
254 nmask_full(1:kl) = imask(:)
255 !
256 nmask => nmask_full(1:kl)
257 !
258 IF (lhook) CALL dr_hook('INIT_IO_SURF_FA_N:GET_MASK',1,zhook_handle)
259 !
260 END SUBROUTINE get_mask
261 !
262 END SUBROUTINE init_io_surf_fa_n
263 
subroutine get_type_dim_n(DTCO, U, HTYPE, KDIM)
subroutine get_dim_full_n(U, KDIM_FULL)
subroutine init_io_surf_fa_n(DTCO, U, HPROGRAM, HMASK, HACTION)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine get_surf_mask_n(DTCO, U, HTYPE, KDIM, KMASK, KLU, KLUOUT)
subroutine get_mask(KLU, YTYPE, IMASK)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine get_1d_mask(KSIZE, KFRAC, PFRAC, KMASK)
Definition: get_1d_mask.F90:5
subroutine get_size_full_n(U, HPROGRAM, KDIM_FULL, KSIZE_FULL)