SURFEX v8.1
General documentation of Surfex
pgd.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 pgd
7 ! ###########
8 !!
9 !! PURPOSE
10 !! -------
11 !! This program prepares the physiographic data fields.
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 !! F. Mereyde Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !!
36 !! Original 21/07/95
37 !! Modification 26/07/95 Treatment of orography and subgrid-scale
38 !! orography roughness length (V. Masson)
39 !! Modification 22/05/96 Variable CSTORAGE_TYPE (V. Masson)
40 !! Modification 25/05/96 Modification of splines, correction on z0rel
41 !! and set limits for some surface varaibles
42 !! Modification 12/06/96 Treatment of a rare case for ZPGDZ0EFF (Masson)
43 !! Modification 22/11/96 removes the filtering. It will have to be
44 !! performed in ADVANCED_PREP_PGD (Masson)
45 !! Modification 15/03/99 **** MAJOR MODIFICATION **** (Masson)
46 !! PGD fields are now defined from the cover
47 !! type fractions in the grid meshes
48 !! User can still include its own data, and
49 !! even additional (dummy) fields
50 !! Modificatio 06/00 patch approach, for vegetation related variable (Solmon/Masson)
51 ! averaging is performed on subclass(=patch) of nature
52 !! 08/03/01 add chemical emission treatment (D.Gazen)
53 !! Modification 15/10/01 allow namelists in different orders (I.Mallet)
54 !! Modification 07/11 new routine write_pgd_surf_atmn.F90 for writing PGD field (B.Decharme)
55 !! flag_update now in write_pgd_surf_atmn.F90 (B.Decharme)
56 !!
57 !!
58 !! ################################
59 !! 13/10/03 EXTERNALIZED VERSION (V. Masson)
60 !! ################################
61 !!
62 !----------------------------------------------------------------------------
63 !
64 !* 0. DECLARATION
65 ! -----------
66 !
69 USE modd_surfex_omp, ONLY : nblocktot
70 !
72 !
74 !
80 USE modi_open_namelist
81 USE modi_close_namelist
82 !
83 USE modi_get_lonlat_n
84 !
85 USE modi_init_index_mpi
86 USE modi_io_buff_clean
87 USE modi_pgd_orog_filter
88 USE modi_pgd_surf_atm
89 USE modi_pgd_grid_surf_atm
90 USE modi_write_header_fa
91 USE modi_write_header_mnh
92 USE modi_write_pgd_surf_atm_n
93 USE modi_init_output_nc_n
94 USE modi_get_size_full_n
95 !
96 USE mode_pos_surf
97 !
99 !
100 USE yomhook ,ONLY : lhook, dr_hook
101 USE parkind1 ,ONLY : jprb
102 !
103 USE modi_get_luout
104 !
106 !
107 IMPLICIT NONE
108 !
109 #ifdef SFX_MPI
110 include 'mpif.h'
111 #endif
112 !
113 #ifndef AIX64
114 !$ INCLUDE 'omp_lib.h'
115 #endif
116 !
117 !* 0.2 Declaration of local variables
118 ! ------------------------------
119 !
120 INTEGER :: ILUOUT
121 INTEGER :: ILUNAM
122 LOGICAL :: GFOUND
123 !
124  CHARACTER(LEN=28) :: YLUOUT ='LISTING_PGD' ! name of the listing
125  CHARACTER(LEN=100) :: YNAME
126 !
127 #ifdef SFX_MPI
128 INTEGER, DIMENSION(MPI_STATUS_SIZE) :: ISTATUS
129 #endif
130 INTEGER :: ILEVEL, INFOMPI
131 INTEGER :: INW, JNW
132 INTEGER :: IRET, ISIZE_FULL
133 DOUBLE PRECISION :: XTIME0
134 REAL(KIND=JPRB) :: ZHOOK_HANDLE
135 !
136 !------------------------------------------------------------------------------
137 !
138 #ifdef SFX_MPI
139  CALL mpi_init_thread(mpi_thread_multiple,ilevel,infompi)
140 #endif
141 !
142 IF (lhook) CALL dr_hook('PGD',0,zhook_handle)
143 !
144  CALL surfex_alloc_list(1)
145 CSOFTWARE='PGD '
146 !
147 #ifdef SFX_MPI
148 ncomm = mpi_comm_world
149  CALL mpi_comm_size(ncomm,nproc,infompi)
150  CALL mpi_comm_rank(ncomm,nrank,infompi)
151 #endif
152 !
153 !
154 !* 1. Set default names and parallelized I/O
155 ! --------------------------------------
156 !
157  IF (nrank>=10) THEN
158  WRITE(yname,fmt='(A15,I2)') trim(yluout),nrank
159 ELSE
160  WRITE(yname,fmt='(A15,I1)') trim(yluout),nrank
161 ENDIF
162  cluout_lfi = adjustl(adjustr(yluout)//'.txt')
163  cluout_nc = adjustl(adjustr(yname)//'.txt')
164  CALL get_luout('ASCII ',iluout)
165 CLUOUT_LFI = ADJUSTL(ADJUSTR(YLUOUT)//'.txt')
166 OPEN(unit=iluout,file=adjustl(adjustr(yluout)//'.txt'),form='FORMATTED',action='WRITE')
167 !
168 ! 1.3 output file name read in namelist
169 ! ---------------------------------
170  CALL open_namelist('ASCII ',ilunam,cnamelist)
171  CALL posnam(ilunam,'NAM_IO_OFFLINE',gfound)
172 IF (gfound) READ (unit=ilunam,nml=nam_io_offline)
173  CALL posnam(ilunam,'NAM_WRITE_SURF_ATM',gfound)
174 IF (gfound) READ (unit=ilunam,nml=nam_write_surf_atm)
175  CALL close_namelist('ASCII ',ilunam)
176 !
177 CFILEOUT = ADJUSTL(ADJUSTR(CPGDFILE)//'.txt') ! output of PGD program
178 CFILEOUT_FA = ADJUSTL(ADJUSTR(CPGDFILE)//'.fa')
179 CFILEOUT_LFI = CPGDFILE
180 CFILEOUT_NC = ADJUSTL(ADJUSTR(CPGDFILE)//'.nc')
181 !
182  CALL goto_model(1)
183 !
184 !$OMP PARALLEL
185 !$ NBLOCKTOT = OMP_GET_NUM_THREADS()
186 !$OMP END PARALLEL
187 !
188  CALL prep_log_mpi
189 !
190  CALL wlog_mpi(' ')
191 !
192  CALL wlog_mpi('NBLOCKTOT ',klog=nblocktot)
193 !
194 #ifdef SFX_MPI
195 xtime0 = mpi_wtime()
196 #endif
197 !
198 !* 2. Preparation of surface physiographic fields
199 ! -------------------------------------------
200 !
201  CALL init_index_mpi(ysc%DTCO,ysc%U,ysc%UG,ysc%GCP,csurf_filetype,'PGD',yalg_mpi,xio_frac)
202  !
203  CALL pgd_grid_surf_atm(ysc%UG, ysc%U, ysc%GCP, csurf_filetype,&
204  ' ',' ',.false.,hdir='H')
205  !
206  CALL get_size_full_n(csurf_filetype, ysc%U%NDIM_FULL, ysc%U%NSIZE_FULL, isize_full)
207 ysc%U%NSIZE_FULL = isize_full
208 !
209  CALL pgd_surf_atm(ysc,csurf_filetype,' ',' ',.false.)
210 !
212 !
213 !* 3. writing of surface physiographic fields
214 ! ---------------------------------------
215 !
216 !* building of the header for the opening of the file in case of Arpege file
217 IF (nrank==npio) THEN
218  IF (csurf_filetype=='FA ') THEN
219  lfanocompact = .true.
220  CALL write_header_fa(ysc%GCP, ysc%UG%G%CGRID, ysc%UG%XGRID_FULL_PAR, csurf_filetype,'PGD')
221  END IF
222 END IF
223 !
224 ALLOCATE(ysc%DUO%CSELECT(0))
225 !
226 ldef = .true.
227 !
228 IF (csurf_filetype=="NC ") THEN
229  CALL init_output_nc_n (ysc%TM%BDD, ysc%CHE, ysc%CHN, ysc%CHU, &
230  ysc%SM%DTS, ysc%TM%DTT, ysc%DTZ, ysc%IM, &
231  ysc%UG, ysc%U, ysc%DUO%CSELECT)
232 ENDIF
233 !
234 inw = 1
235 IF (csurf_filetype=="NC ") inw = 2
236 !
237 lfirst_write = .true.
238 ncpt_write = 0
239 !
240 DO jnw = 1,inw
241  !
242  IF (lwrite_coord) CALL get_lonlat_n(ysc%DTCO, ysc%U, ysc%UG, ysc%DUO%CSELECT, csurf_filetype)
243  !
244  !* writing of the fields
245  CALL io_buff_clean
246  ! FLAG_UPDATE now in WRITE_PGD_SURF_ATM_n
248  !
249  ldef = .false.
250  lfirst_write = .false.
251  ncpt_write = 0
252  CALL io_buff_clean
253  !
254 ENDDO
255 !
256 !* closes the file
257 IF (nrank==npio) THEN
258  IF (csurf_filetype=='FA ') THEN
259 #ifdef SFX_FA
260  CALL fairme(iret,nunit_fa,'UNKNOWN')
261 #endif
262  END IF
263 !
264  !* add informations in the file
265  IF (csurf_filetype=='LFI ' .AND. lmnh_compatible) CALL write_header_mnh
266 !
267 !* 3. Close parallelized I/O
268 ! ----------------------
269 !
270  WRITE(iluout,*) ' '
271  WRITE(iluout,*) ' ----------------------'
272  WRITE(iluout,*) ' | PGD ENDS CORRECTLY |'
273  WRITE(iluout,*) ' ----------------------'
274 !
275  WRITE(*,*) ' '
276  WRITE(*,*) ' ----------------------'
277  WRITE(*,*) ' | PGD ENDS CORRECTLY |'
278  WRITE(*,*) ' ----------------------'
279  !
280  CLOSE(iluout)
281  !
282 ENDIF
283 !
284  CALL surfex_deallo_list
285 !
286 IF (ALLOCATED(nindex)) DEALLOCATE(nindex)
287 IF (ALLOCATED(nnum)) DEALLOCATE(nnum)
288 IF (ALLOCATED(nsize_task)) DEALLOCATE(nsize_task)
289 !
290  CALL end_log_mpi
291 !
292 IF (lhook) CALL dr_hook('PGD',1,zhook_handle)
293 !
294 #ifdef SFX_MPI
295  CALL mpi_finalize(infompi)
296 #endif
297 !
298 !-------------------------------------------------------------------------------
299 !
300 END PROGRAM pgd
character(len=28) cnamelist
subroutine write_header_mnh
subroutine fairme(KREP, KNUMER, CDSTTU)
Definition: fairme.F90:232
character(len=6) csurf_filetype
subroutine get_lonlat_n(DTCO, U, UG, HSELECT, HPROGRAM)
Definition: get_lonlatn.F90:7
subroutine write_pgd_surf_atm_n(YSC, HPROGRAM)
subroutine init_index_mpi(DTCO, U, UG, GCP, HPROGRAM, HINIT, HALG, PIO_FRAC, OSHADOWS)
subroutine io_buff_clean
subroutine get_size_full_n(HPROGRAM, KDIM_FULL, KSIZE_FULL_IN, KSIZE
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
program pgd
Definition: pgd.F90:6
subroutine pgd_surf_atm(YSC, HPROGRAM, HFILE, HFILETYPE, OZS)
Definition: pgd_surf_atm.F90:7
character(len=28), save cluout_lfi
integer, dimension(:), allocatable nnum
subroutine pgd_orog_filter(U, UG, HPROGRAM)
subroutine goto_model(KMODEL)
subroutine surfex_deallo_list
integer, parameter jprb
Definition: parkind1.F90:32
character(len=28), save cluout_nc
subroutine end_log_mpi
type(surfex_t), pointer ysc
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine init_output_nc_n(BDD, CHE, CHN, CHU, DTS, DTT, DTZ, IM
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:7
subroutine pgd_grid_surf_atm(UG, U, GCP, HPROGRAM, HFILE, HFILETYPE
integer, dimension(:), allocatable nsize_task
logical lhook
Definition: yomhook.F90:15
integer, dimension(:), allocatable nindex
subroutine surfex_alloc_list(KMODEL)
character(len=4) yalg_mpi
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)
logical, save lfanocompact
subroutine prep_log_mpi
subroutine wlog_mpi(HLOG, PLOG, KLOG, KLOG2, OLOG)
subroutine write_header_fa(GCP, HGRID, PGRID_PAR, CFILETYPE, HWRITE)