2875839751b77d9454f2a3c2cf90c95335de1f74
[MNH-git_open_source-lfs.git] / src / MNH / open_nestpgd_files.f90
1 !MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
4 !MNH_LIC for details. version 1.
5 !-----------------------------------------------------------------
6 !--------------- special set of characters for RCS information
7 !-----------------------------------------------------------------
8 ! $Source$ $Revision$
9 !-----------------------------------------------------------------
10 !#############################
11 MODULE MODI_OPEN_NESTPGD_FILES
12 !#############################
13 !
14 INTERFACE
15       SUBROUTINE OPEN_NESTPGD_FILES(HPGD,HNESTPGD)
16 !
17 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HPGD     ! name of the input  pgd files
18 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HNESTPGD ! name of the output pgd files
19 END SUBROUTINE OPEN_NESTPGD_FILES
20 END INTERFACE
21 END MODULE MODI_OPEN_NESTPGD_FILES
22 !     ############################################
23       SUBROUTINE OPEN_NESTPGD_FILES(HPGD,HNESTPGD)
24 !     ############################################
25 !
26 !!****  *OPEN_NESTPGD_FILES* - openning of the files used in PREP_NEST_PGD
27 !!                         
28 !!
29 !!    PURPOSE
30 !!    -------
31 !!
32 !!**  METHOD
33 !!    ------
34 !!
35 !!    CAUTION:
36 !!    This routine supposes the name of the namelist file is 'PRE_NEST_PGD1.nam'.
37 !!
38 !!    EXTERNAL
39 !!    --------
40 !!
41 !!    Routine FMOPEN
42 !!
43 !!    IMPLICIT ARGUMENTS
44 !!    ------------------
45 !!
46 !!      Module MODD_LUNIT     :  contains logical unit names for all models
47 !!         CLUOUT0  : name of output-listing
48 !!
49 !!    REFERENCE
50 !!    ---------
51 !!
52 !!      Book 2
53 !!
54 !!    AUTHOR
55 !!    ------
56 !!      
57 !!      V.Masson  Meteo-France
58 !!
59 !!    MODIFICATIONS
60 !!    -------------
61 !!      Original     26/09/96
62 !!                   30/07/97 (Masson) group MODI_OPEN_LUOUTn
63 !!                   15/10/01 (I.Mallet) allow namelists in different orders
64 !!                   07/06/2010 (J.escobar from Ivan Ristic) bug PGI
65 !!                   30/12/2012 (S.Bielli) Add NAM_NCOUT for netcdf output
66 !!    J.Escobar : 15/09/2015 : WENO5 & JPHEXT <> 1 
67 !!                   11/2015 (M.Moge) disable the creation of files on multiple 
68 !!                                 Z-levels when using parallel IO for PREP_PGD
69 !!                   01/2016 (M.Moge) Bug fix : open the output file using Z-parallel IO
70 !-------------------------------------------------------------------------------
71 !
72 !*       0.    DECLARATIONS
73 !              ------------
74 !
75 USE MODD_LUNIT
76 USE MODD_CONF
77 USE MODD_NESTING
78 USE MODD_PARAMETERS
79 !
80 USE MODI_OPEN_LUOUTn
81 !
82 USE MODE_IO_ll
83 USE MODE_FM
84 USE MODE_POS
85 !
86 USE MODE_MODELN_HANDLER
87 !
88 #ifdef MNH_NCWRIT
89 USE MODN_NCOUT
90 #endif
91 USE MODN_CONFIO
92 !
93 USE MODD_PARAMETERS, ONLY : JPHEXT  
94 USE MODD_CONF, ONLY       : NHALO_CONF_MNH => NHALO
95 !
96 USE  MODN_CONFZ
97 !
98 IMPLICIT NONE
99 !
100 !*       0.1   Declaration of arguments
101 !              ------------------------
102 !
103 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HPGD     ! name of the input  pgd files
104 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HNESTPGD ! name of the output pgd files
105 !
106 !*       0.2   Declaration of local variables
107 !              ------------------------------
108 !
109 INTEGER :: IRESP      ! return-code if problems eraised
110 INTEGER :: ILUOUT0    ! logical unit for listing file
111 INTEGER :: ININAR     ! number of articles initially present in a FM file
112 LOGICAL :: GFOUND     ! Return code when searching namelist
113 !
114 CHARACTER(LEN=28) :: HPRE_NEST_PGD ! name of namelist file
115 INTEGER           :: IPRE_NEST_PGD ! logical unit of namelist file
116 !
117 CHARACTER(LEN=28)                        :: YPGD      ! name of the pgd file for each model
118 CHARACTER(LEN=28)                        :: YLUOUT    ! name of output listing file for each model
119 CHARACTER(LEN=2)                         :: YNEST     ! to define the output pgd file names
120 CHARACTER(LEN=28)                        :: YPGD1, YPGD2, YPGD3, YPGD4, &
121                                             YPGD5, YPGD6, YPGD7, YPGD8
122 !                                                     ! name of all pgd files
123 !                                                     ! in the namelist
124 INTEGER                        :: IDAD    ! father of one model
125 INTEGER                        :: JPGD    ! loop counter
126 LOGICAL                        :: GADD    !
127 CHARACTER(LEN=21), DIMENSION(JPMODELMAX) :: YSHORTPGD 
128 INTEGER                                  :: NHALO_MNH
129 !
130 INTEGER :: ILUNAM,ILUOUT              ! Logical unit number for the EXSPA file
131 !
132 !*       0.3   Declaration of namelists
133 !              ------------------------
134 !
135 NAMELIST/NAM_PGD1/ YPGD1
136 NAMELIST/NAM_PGD2/ YPGD2, IDAD
137 NAMELIST/NAM_PGD3/ YPGD3, IDAD
138 NAMELIST/NAM_PGD4/ YPGD4, IDAD
139 NAMELIST/NAM_PGD5/ YPGD5, IDAD
140 NAMELIST/NAM_PGD6/ YPGD6, IDAD
141 NAMELIST/NAM_PGD7/ YPGD7, IDAD
142 NAMELIST/NAM_PGD8/ YPGD8, IDAD
143 NAMELIST/NAM_NEST_PGD/ YNEST
144 NAMELIST/NAM_CONF_NEST/JPHEXT, NHALO_MNH
145 !-------------------------------------------------------------------------------
146 !
147 !*       1.    SET DEFAULT NAMES
148 !              -----------------
149 !
150 DO JPGD=1,JPMODELMAX
151   HPGD    (JPGD)='                           '
152   HNESTPGD(JPGD)='                           '
153 END DO
154 !
155 HPRE_NEST_PGD='PRE_NEST_PGD1.nam'
156 CLUOUT0='OUTPUT_LISTING0'
157 !
158 !-------------------------------------------------------------------------------
159 !
160 !*       2.    OPENNING OF CLUOUT0
161 !              -------------------
162 !
163 CALL OPEN_ll(UNIT=ILUOUT0,FILE=CLUOUT0,IOSTAT=IRESP,FORM='FORMATTED',ACTION='WRITE', &
164      MODE=GLOBAL)
165 !
166 !-------------------------------------------------------------------------------
167 !
168 !*       3.    OPENNING OF PRE_NEST_PGD1.nam
169 !              -----------------------------
170 !
171 CALL OPEN_ll(UNIT=IPRE_NEST_PGD,FILE=HPRE_NEST_PGD,IOSTAT=IRESP,FORM='FORMATTED',ACTION='READ', &
172      MODE=GLOBAL)
173 !reading of NAM_CONFZ
174 CALL FMLOOK_ll(HPRE_NEST_PGD,HPRE_NEST_PGD,ILUOUT,IRESP)
175 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONFZ',GFOUND)
176 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONFZ)
177 !
178 !JUAN
179 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONF_NEST',GFOUND)
180 IF (GFOUND) THEN
181    NHALO_MNH = NHALO_CONF_MNH
182    READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONF_NEST)
183    NHALO_CONF_MNH = NHALO_MNH
184 END IF
185 !JUAN
186 !
187 !-------------------------------------------------------------------------------
188 !
189 !*       4.    READING OF THE OTHER FILE NAMES
190 !              -------------------------------
191 !
192 YPGD1='                            '
193 YPGD2='                            '
194 YPGD3='                            '
195 YPGD4='                            '
196 YPGD5='                            '
197 YPGD6='                            '
198 YPGD7='                            '
199 YPGD8='                            '
200 NDAD(:)=0
201 GADD=.TRUE.
202 !
203 DO JPGD=1,JPMODELMAX
204   IDAD=0
205   IF (JPGD==1) THEN
206     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD1',GFOUND)
207     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD1)
208   END IF
209   IF (JPGD==2) THEN
210     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD2',GFOUND)
211     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD2)
212   END IF
213   IF (JPGD==3) THEN
214     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD3',GFOUND)
215     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD3)
216   END IF
217   IF (JPGD==4) THEN
218     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD4',GFOUND)
219     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD4)
220   END IF
221   IF (JPGD==5) THEN
222     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD5',GFOUND)
223     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD5)
224   END IF
225   IF (JPGD==6) THEN
226     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD6',GFOUND)
227     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD6)
228   END IF
229   IF (JPGD==7) THEN
230     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD7',GFOUND)
231     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD7)
232   END IF
233   IF (JPGD==8) THEN
234     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD8',GFOUND)
235     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD8)
236   END IF
237   !
238   IF (JPGD==1) YPGD=YPGD1
239   IF (JPGD==2) YPGD=YPGD2
240   IF (JPGD==3) YPGD=YPGD3
241   IF (JPGD==4) YPGD=YPGD4
242   IF (JPGD==5) YPGD=YPGD5
243   IF (JPGD==6) YPGD=YPGD6
244   IF (JPGD==7) YPGD=YPGD7
245   IF (JPGD==8) YPGD=YPGD8
246   !
247   IF (LEN_TRIM(YPGD) == 0) THEN
248     IF (JPGD==1) THEN
249       WRITE(ILUOUT0,*) 'No pgd file was present for model 1 in namelist NAM_PGD1'
250 !callabortstop
251       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
252       CALL ABORT
253       STOP
254     ELSE
255       GADD=.FALSE.
256       CYCLE
257     END IF
258   END IF
259   !
260   IF ( (IDAD<1 .OR. IDAD>JPMODELMAX) .AND. (JPGD>1) ) THEN
261       WRITE(ILUOUT0,*) 'No father indicated for model ',JPGD,' in namelist NAM_PGD',JPGD
262 !callabortstop
263       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
264       CALL ABORT
265       STOP
266   END IF
267   !
268   IF (GADD) THEN
269     NMODEL=JPGD
270     !
271     IF (IDAD>=JPGD) THEN
272       WRITE(ILUOUT0,*) 'pgd files are not correctly ordered:'
273       WRITE(ILUOUT0,*) ' in namelist NAM_PGD',JPGD,' was found IDAD= ', IDAD
274 !callabortstop
275       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
276       CALL ABORT
277       STOP
278     END IF
279     !
280     NDAD(JPGD)=IDAD
281     HPGD(JPGD)=YPGD
282   END IF
283 END DO
284 !
285 !-------------------------------------------------------------------------------
286 !
287 !*       5.    NAMES OF OUTPUT PGD FILES
288 !              -------------------------
289 !
290 CALL POSNAM(IPRE_NEST_PGD,'NAM_NEST_PGD',GFOUND,ILUOUT0)
291 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_NEST_PGD)
292 HNESTPGD(:) = '                            '
293 !
294 YSHORTPGD(:)=HPGD(:)
295 DO JPGD=1,NMODEL
296   HNESTPGD(JPGD) = ADJUSTR( YSHORTPGD(JPGD))//'.nest'//ADJUSTL(YNEST)
297   HNESTPGD(JPGD) = ADJUSTL(HNESTPGD(JPGD))
298 END DO
299 #ifdef MNH_NCWRIT
300 CALL POSNAM(IPRE_NEST_PGD,'NAM_NCOUT',GFOUND,ILUOUT0)
301 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_NCOUT)
302 #endif
303 !
304 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONFIO',GFOUND,ILUOUT0)
305 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONFIO)
306 CALL SET_CONFIO_ll(LCDF4, LLFIOUT, LLFIREAD)
307 !
308 !-------------------------------------------------------------------------------
309 CALL CLOSE_ll(HPRE_NEST_PGD)
310 !-------------------------------------------------------------------------------
311 !
312 !*       6.    OPENING OF INPUT AND OUTPUT PGD FILES
313 !              -------------------------------------
314 !
315 DO JPGD=1,NMODEL
316   CALL FMOPEN_ll(HPGD(JPGD),'READ',CLUOUT0,0,2,NVERB,ININAR,IRESP,OPARALLELIO=.FALSE.)
317   CALL FMOPEN_ll(HNESTPGD(JPGD),'WRITE',CLUOUT0,0,1,NVERB,ININAR,IRESP)
318 END DO
319 !
320 !-------------------------------------------------------------------------------
321 !
322 !*       7.    OPENING OF OUPUT LISTING FILES FOR ALL MODELS
323 !              ----------------------------------------------
324 !
325 DO JPGD=1,NMODEL
326   CALL GOTO_MODEL(JPGD)
327   WRITE(YLUOUT,'("OUTPUT_LISTING",I0)') JPGD
328   CALL OPEN_LUOUT_n(YLUOUT)
329 END DO
330 !
331 !-------------------------------------------------------------------------------
332 !
333 END SUBROUTINE OPEN_NESTPGD_FILES