SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
prep.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 PROGRAM prep
7 !------------------------
8 !!
9 !! PURPOSE
10 !! -------
11 !! This program prepares the initial file for offline run
12 !!
13 !! METHOD
14 !! ------
15 !!
16 !!
17 !! EXTERNAL
18 !! --------
19 !!
20 !!
21 !! IMPLICIT ARGUMENTS
22 !! ------------------
23 !!
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !! AUTHOR
29 !! ------
30 !!
31 !! P. LeMoigne Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !!
36 !! Original 22/04/04
37 !!
38 !----------------------------------------------------------------------------
39 !
40 USE mode_pos_surf
41 !
42 USE modd_surfex_omp, ONLY : nwork, nwork2, xwork, xwork2, xwork3, nblocktot, &
43  nwork_full, nwork2_full, xwork_full, xwork2_full
44 !
49 USE modd_surf_par
50 USE modd_surf_conf, ONLY : csoftware
51 !
52 USE modd_sfx_oasis, ONLY : loasis
53 !
54 USE modi_open_namelist
55 USE modi_close_namelist
56 USE modi_read_all_namelists
57 USE modi_get_luout
58 !
59 USE modi_init_pgd_surf_atm
60 USE modi_io_buff_clean
61 USE modi_prep_surf_atm
62 USE modi_write_diag_surf_atm_n
63 USE modi_write_header_mnh
64 USE modi_write_surf_atm_n
65 !
66 USE modi_get_lonlat_n
67 USE modi_flag_update
68 USE modi_abor1_sfx
69 !
70 USE modi_sfx_oasis_init
71 USE modi_sfx_oasis_read_nam
72 USE modi_sfx_oasis_prep
73 USE modi_sfx_oasis_end
74 !
75 USE modi_init_output_nc_n
76 !
78 !------------------------------------------------------------------------------
79 !
80 !
81 USE yomhook ,ONLY : lhook, dr_hook
82 USE parkind1 ,ONLY : jprb
83 !
86 !
87 IMPLICIT NONE
88 !
89 #ifndef AIX64
90 include 'omp_lib.h'
91 #endif
92 !
93 #ifdef SFX_MPI
94 include 'mpif.h'
95 #endif
96 !
97 !* 0. Declaration of local variables
98 ! ------------------------------
99 !
100 INTEGER :: iluout
101 INTEGER :: ilunam
102 INTEGER :: iyear, imonth, iday
103 REAL :: ztime
104 LOGICAL :: gfound
105 
106 REAL, DIMENSION(0) :: zzs
107  CHARACTER(LEN=28) :: yatmfile =' ' ! name of the Atmospheric file
108  CHARACTER(LEN=6) :: yatmfiletype =' ' ! type of the Atmospheric file
109  CHARACTER(LEN=28) :: ypgdfile =' ' ! name of the pgd file
110  CHARACTER(LEN=6) :: ypgdfiletype =' ' ! type of the pgd file
111  CHARACTER(LEN=28) :: yluout ='LISTING_PREP ' ! name of listing
112 !
113 INTEGER, DIMENSION(11) :: idatef
114 !
115 INTEGER :: jnw, inw
116 INTEGER :: iret, inb
117 #ifdef CPLOASIS
118 INTEGER :: ilocal_comm, infompi, inproc
119 #endif
120 REAL(KIND=JPRB) :: zhook_handle
121 !
122 !------------------------------------------------------------------------------
123 !
124 !
125 !* 1. Set default names and parallelized I/O
126 ! --------------------------------------
127 !
128 #ifdef CPLOASIS
129 !Must be call before DRHOOK !
130  CALL sfx_oasis_init(cnamelist,ilocal_comm,'PRE')
131 #else
132 loasis = .false.
133 #endif
134 !
135 IF (lhook) CALL dr_hook('PREP',0,zhook_handle)
136 !
137 #ifdef CPLOASIS
138 IF(loasis)THEN
139  CALL mpi_comm_size(ilocal_comm,inproc,infompi)
140  IF(inproc>1)THEN
141  CALL abor1_sfx('PREP: FOR PREP"WITH OASIS ONLY 1 PROC MUST BE USED')
142  ENDIF
143 ENDIF
144 #endif
145 !
146 ! Allocations of Surfex Types
147  CALL surfex_alloc_list(1)
148 !
149  csoftware='PREP'
150 !
151 ! 1.1 initializations
152 ! ---------------
153 !
154 iyear = nundef
155 imonth = nundef
156 iday = nundef
157 ztime = xundef
158 !
159 lprep = .true.
160 !
161 ! 1.2 output listing
162 ! --------------
163  cluout_lfi = adjustl(adjustr(yluout)//'.txt')
164  CALL get_luout('ASCII ',iluout)
165 OPEN (unit=iluout,file=adjustl(adjustr(yluout)//'.txt'),form='FORMATTED',action='WRITE')
166 !
167 ! 1.3 output file name read in namelist
168 ! ---------------------------------
169 !
170  CALL open_namelist('ASCII ',ilunam,cnamelist)
171 !
172  CALL posnam(ilunam,'NAM_IO_OFFLINE',gfound)
173 IF (gfound) READ (unit=ilunam,nml=nam_io_offline)
174 !
175  cfilepgd = adjustl(adjustr(cpgdfile)//'.txt')
176  cfilein = adjustl(adjustr(cpgdfile)//'.txt') ! output of PGD program
177  cfilein_save = cfilein
178  cfileout = adjustl(adjustr(cprepfile)//'.txt')
179 !
180  cfilepgd_fa = adjustl(adjustr(cpgdfile)//'.fa')
181  cfilein_fa = adjustl(adjustr(cpgdfile)//'.fa')
182  cfilein_fa_save = cfilein_fa
183  cfileout_fa = adjustl(adjustr(cprepfile)//'.fa')
184 !
185  cfilepgd_lfi = cpgdfile
186  cfilein_lfi = cpgdfile
187  cfilein_lfi_save = cfilein_lfi
188  cfileout_lfi = cprepfile
189 !
190  cfilepgd_nc = adjustl(adjustr(cpgdfile)//'.nc')
191  cfilein_nc = adjustl(adjustr(cpgdfile)//'.nc')
192  cfilein_nc_save = cfilein_nc
193  cfileout_nc = adjustl(adjustr(cprepfile)//'.nc')
194 !
195  CALL close_namelist('ASCII ',ilunam)
196 !
197 ! Reading all namelist (also assimilation)
198  ysurf_cur => ysurf_list(1)
199  CALL read_all_namelists(ysurf_cur, &
200  csurf_filetype,'PRE',.false.)
201 !
202 !* 1.4. Reads SFX - OASIS coupling namelists
203 ! ------------------------------------
204 !
205  CALL sfx_oasis_read_nam(csurf_filetype,xtstep_surf,'PRE')
206 !
207 !* 1.5. Goto model of Surfex Types
208 ! ---------------------------
209 !
210  icurrent_model = 1
211 !
212 !* 2. Preparation of surface physiographic fields
213 ! -------------------------------------------
214 !
215 !$OMP PARALLEL
216 !$ NBLOCKTOT = OMP_GET_NUM_THREADS()
217 !$OMP END PARALLEL
218 !
219  CALL io_buff_clean
220  CALL init_pgd_surf_atm(ysurf_cur, &
221  csurf_filetype,'PRE',yatmfile,yatmfiletype, &
222  iyear, imonth, iday, ztime )
223 !
224  CALL io_buff_clean
225  CALL prep_surf_atm(ysurf_cur, &
226  csurf_filetype,yatmfile,yatmfiletype,ypgdfile,ypgdfiletype)
227 !
228 !* 3. Preparation of SFX-OASIS grid, mask, areas files
229 ! ------------------------------------------------
230 !
231 IF(loasis)THEN
232  CALL sfx_oasis_prep(ysurf_cur%IM%I, ysurf_cur%UG, ysurf_cur%U, &
233  csurf_filetype)
234 ENDIF
235 !
236 !* 4. Store of surface physiographic fields
237 ! -------------------------------------
238 !
239  CALL flag_update(ysurf_cur%IM%DGI, ysurf_cur%DGU, &
240  .false.,.true.,.false.,.false.)
241 !
242 !* opens the file
243 IF (csurf_filetype=='FA ') THEN
244 #ifdef SFX_FA
245  lfanocompact = .true.
246  idatef(1)=ysurf_cur%U%TTIME%TDATE%YEAR
247  idatef(2)=ysurf_cur%U%TTIME%TDATE%MONTH
248  idatef(3)=ysurf_cur%U%TTIME%TDATE%DAY
249  idatef(4)=nint(ysurf_cur%U%TTIME%TIME/3600.)
250  idatef(5)=nint(ysurf_cur%U%TTIME%TIME/60.) - idatef(4) * 60
251  idatef(6)=1
252  idatef(7:11)=0
253  CALL faitou(iret,nunit_fa,.true.,cfileout_fa,'NEW',.true.,.false.,iverbfa,0,inb,cdnomc)
254  CALL fandar(iret,nunit_fa,idatef)
255 #endif
256 END IF
257 !
258 ldef = .true.
259 !
260 IF (csurf_filetype=="NC ") THEN
261  CALL init_output_nc_n(ysurf_cur%TM%BDD, ysurf_cur%CHE, ysurf_cur%CHN, ysurf_cur%CHU, &
262  ysurf_cur%SM%DTS, ysurf_cur%TM%DTT, ysurf_cur%DTZ, ysurf_cur%IM%I, &
263  ysurf_cur%UG, ysurf_cur%U, ysurf_cur%DGU)
264 ENDIF
265 !
266 inw = 1
267 IF (csurf_filetype=="NC ") inw = 2
268 !
269 DO jnw = 1,inw
270  !
271  IF (lwrite_coord) CALL get_lonlat_n(ysurf_cur, &
272  csurf_filetype)
273  !
274  !* writes into the file
275  CALL io_buff_clean
276  !
277  ! FLAG_UPDATE now in WRITE_PGD_SURF_ATM_n
278  CALL write_surf_atm_n(ysurf_cur, &
279  csurf_filetype,'PRE',lland_use) !no pgd field
280  CALL write_diag_surf_atm_n(ysurf_cur, &
281  csurf_filetype,'ALL')
282  !
283  ldef = .false.
284  CALL io_buff_clean
285  !
286 ENDDO
287 !
288 !* closes the file
289 IF (csurf_filetype=='FA ') THEN
290 #ifdef SFX_FA
291  CALL fairme(iret,nunit_fa,'UNKNOWN')
292 #endif
293 END IF
294 !
295 !* add informations in the file
296 IF (csurf_filetype=='LFI ' .AND. lmnh_compatible) CALL write_header_mnh
297 !
298 !
299 !* 4. Close parallelized I/O
300 ! ----------------------
301 !
302 WRITE(iluout,*) ' '
303 WRITE(iluout,*) ' -----------------------'
304 WRITE(iluout,*) ' | PREP ENDS CORRECTLY |'
305 WRITE(iluout,*) ' -----------------------'
306 !
307 WRITE(*,*) ' '
308 WRITE(*,*) ' -----------------------'
309 WRITE(*,*) ' | PREP ENDS CORRECTLY |'
310 WRITE(*,*) ' -----------------------'
311 !
312  CLOSE(iluout)
313 !
314  CALL surfex_deallo_list
315 !
316 IF (ASSOCIATED(nwork)) DEALLOCATE(nwork)
317 IF (ASSOCIATED(xwork)) DEALLOCATE(xwork)
318 IF (ASSOCIATED(nwork2)) DEALLOCATE(nwork2)
319 IF (ASSOCIATED(xwork2)) DEALLOCATE(xwork2)
320 IF (ASSOCIATED(xwork3)) DEALLOCATE(xwork3)
321 IF (ASSOCIATED(nwork_full)) DEALLOCATE(nwork_full)
322 IF (ASSOCIATED(xwork_full)) DEALLOCATE(xwork_full)
323 IF (ASSOCIATED(nwork2_full)) DEALLOCATE(nwork2_full)
324 IF (ASSOCIATED(xwork2_full)) DEALLOCATE(xwork2_full)
325 !
326 IF (lhook) CALL dr_hook('PREP',1,zhook_handle)
327 !
328 ! * OASIS must be finalized after the last DR_HOOK call
329 !
330 IF(loasis)THEN
331  CALL sfx_oasis_end
332 ENDIF
333 !
334 !-------------------------------------------------------------------------------
335 !
336 END PROGRAM prep
subroutine init_output_nc_n(BDD, CHE, CHN, CHU, DTS, DTT, DTZ, I, UG, U, DGU)
subroutine write_header_mnh
subroutine sfx_oasis_read_nam(HPROGRAM, PTSTEP_SURF, HINIT)
subroutine get_lonlat_n(YSC, HPROGRAM)
Definition: get_lonlatn.F90:6
subroutine io_buff_clean
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine flag_update(DGI, DGU, ONOWRITE_CANOPY, OPGD, OPROVAR_TO_DIAG, OSELECT)
Definition: flag_update.F90:6
subroutine write_diag_surf_atm_n(YSC, HPROGRAM, HWRITE)
subroutine sfx_oasis_init(HNAMELIST, KLOCAL_COMM, HINIT)
subroutine surfex_deallo_list
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine init_pgd_surf_atm(YSC, HPROGRAM, HINIT, HATMFILE, HATMFILETYPE, KYEAR, KMONTH, KDAY, PTIME)
subroutine read_all_namelists(YSC, HPROGRAM, HINIT, ONAM_READ)
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine write_surf_atm_n(YSC, HPROGRAM, HWRITE, OLAND_USE)
subroutine sfx_oasis_end
subroutine surfex_alloc_list(KMODEL)
subroutine prep_surf_atm(YSC, HPROGRAM, HATMFILE, HATMFILETYPE, HPGDFILE, HPGDFILETYPE)
program prep
Definition: prep.F90:6
subroutine sfx_oasis_prep(I, UG, U, HPROGRAM)
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)