Juan 19/04/2016 : Pb IOZ/NETCDF , missing OPARALLELIO=.FALSE. for PGD files
[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 !!                   J.Escobar : 19/04/2016 : Pb IOZ/NETCDF , missing OPARALLELIO=.FALSE. for PGD files
71 !-------------------------------------------------------------------------------
72 !
73 !*       0.    DECLARATIONS
74 !              ------------
75 !
76 USE MODD_LUNIT
77 USE MODD_CONF
78 USE MODD_NESTING
79 USE MODD_PARAMETERS
80 !
81 USE MODI_OPEN_LUOUTn
82 !
83 USE MODE_IO_ll
84 USE MODE_FM
85 USE MODE_POS
86 !
87 USE MODE_MODELN_HANDLER
88 !
89 #ifdef MNH_NCWRIT
90 USE MODN_NCOUT
91 #endif
92 USE MODN_CONFIO
93 !
94 USE MODD_PARAMETERS, ONLY : JPHEXT  
95 USE MODD_CONF, ONLY       : NHALO_CONF_MNH => NHALO
96 !
97 USE  MODN_CONFZ
98 !
99 IMPLICIT NONE
100 !
101 !*       0.1   Declaration of arguments
102 !              ------------------------
103 !
104 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HPGD     ! name of the input  pgd files
105 CHARACTER(LEN=28), DIMENSION(:), INTENT(OUT) :: HNESTPGD ! name of the output pgd files
106 !
107 !*       0.2   Declaration of local variables
108 !              ------------------------------
109 !
110 INTEGER :: IRESP      ! return-code if problems eraised
111 INTEGER :: ILUOUT0    ! logical unit for listing file
112 INTEGER :: ININAR     ! number of articles initially present in a FM file
113 LOGICAL :: GFOUND     ! Return code when searching namelist
114 !
115 CHARACTER(LEN=28) :: HPRE_NEST_PGD ! name of namelist file
116 INTEGER           :: IPRE_NEST_PGD ! logical unit of namelist file
117 !
118 CHARACTER(LEN=28)                        :: YPGD      ! name of the pgd file for each model
119 CHARACTER(LEN=28)                        :: YLUOUT    ! name of output listing file for each model
120 CHARACTER(LEN=2)                         :: YNEST     ! to define the output pgd file names
121 CHARACTER(LEN=28)                        :: YPGD1, YPGD2, YPGD3, YPGD4, &
122                                             YPGD5, YPGD6, YPGD7, YPGD8
123 !                                                     ! name of all pgd files
124 !                                                     ! in the namelist
125 INTEGER                        :: IDAD    ! father of one model
126 INTEGER                        :: JPGD    ! loop counter
127 LOGICAL                        :: GADD    !
128 CHARACTER(LEN=21), DIMENSION(JPMODELMAX) :: YSHORTPGD 
129 INTEGER                                  :: NHALO_MNH
130 !
131 INTEGER :: ILUNAM,ILUOUT              ! Logical unit number for the EXSPA file
132 !
133 !*       0.3   Declaration of namelists
134 !              ------------------------
135 !
136 NAMELIST/NAM_PGD1/ YPGD1
137 NAMELIST/NAM_PGD2/ YPGD2, IDAD
138 NAMELIST/NAM_PGD3/ YPGD3, IDAD
139 NAMELIST/NAM_PGD4/ YPGD4, IDAD
140 NAMELIST/NAM_PGD5/ YPGD5, IDAD
141 NAMELIST/NAM_PGD6/ YPGD6, IDAD
142 NAMELIST/NAM_PGD7/ YPGD7, IDAD
143 NAMELIST/NAM_PGD8/ YPGD8, IDAD
144 NAMELIST/NAM_NEST_PGD/ YNEST
145 NAMELIST/NAM_CONF_NEST/JPHEXT, NHALO_MNH
146 !-------------------------------------------------------------------------------
147 !
148 !*       1.    SET DEFAULT NAMES
149 !              -----------------
150 !
151 DO JPGD=1,JPMODELMAX
152   HPGD    (JPGD)='                           '
153   HNESTPGD(JPGD)='                           '
154 END DO
155 !
156 HPRE_NEST_PGD='PRE_NEST_PGD1.nam'
157 CLUOUT0='OUTPUT_LISTING0'
158 !
159 !-------------------------------------------------------------------------------
160 !
161 !*       2.    OPENNING OF CLUOUT0
162 !              -------------------
163 !
164 CALL OPEN_ll(UNIT=ILUOUT0,FILE=CLUOUT0,IOSTAT=IRESP,FORM='FORMATTED',ACTION='WRITE', &
165      MODE=GLOBAL)
166 !
167 !-------------------------------------------------------------------------------
168 !
169 !*       3.    OPENNING OF PRE_NEST_PGD1.nam
170 !              -----------------------------
171 !
172 CALL OPEN_ll(UNIT=IPRE_NEST_PGD,FILE=HPRE_NEST_PGD,IOSTAT=IRESP,FORM='FORMATTED',ACTION='READ', &
173      MODE=GLOBAL)
174 !reading of NAM_CONFZ
175 CALL FMLOOK_ll(HPRE_NEST_PGD,HPRE_NEST_PGD,ILUOUT,IRESP)
176 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONFZ',GFOUND)
177 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONFZ)
178 !
179 !JUAN
180 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONF_NEST',GFOUND)
181 IF (GFOUND) THEN
182    NHALO_MNH = NHALO_CONF_MNH
183    READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONF_NEST)
184    NHALO_CONF_MNH = NHALO_MNH
185 END IF
186 !JUAN
187 !
188 !-------------------------------------------------------------------------------
189 !
190 !*       4.    READING OF THE OTHER FILE NAMES
191 !              -------------------------------
192 !
193 YPGD1='                            '
194 YPGD2='                            '
195 YPGD3='                            '
196 YPGD4='                            '
197 YPGD5='                            '
198 YPGD6='                            '
199 YPGD7='                            '
200 YPGD8='                            '
201 NDAD(:)=0
202 GADD=.TRUE.
203 !
204 DO JPGD=1,JPMODELMAX
205   IDAD=0
206   IF (JPGD==1) THEN
207     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD1',GFOUND)
208     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD1)
209   END IF
210   IF (JPGD==2) THEN
211     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD2',GFOUND)
212     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD2)
213   END IF
214   IF (JPGD==3) THEN
215     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD3',GFOUND)
216     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD3)
217   END IF
218   IF (JPGD==4) THEN
219     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD4',GFOUND)
220     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD4)
221   END IF
222   IF (JPGD==5) THEN
223     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD5',GFOUND)
224     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD5)
225   END IF
226   IF (JPGD==6) THEN
227     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD6',GFOUND)
228     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD6)
229   END IF
230   IF (JPGD==7) THEN
231     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD7',GFOUND)
232     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD7)
233   END IF
234   IF (JPGD==8) THEN
235     CALL POSNAM(IPRE_NEST_PGD,'NAM_PGD8',GFOUND)
236     IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_PGD8)
237   END IF
238   !
239   IF (JPGD==1) YPGD=YPGD1
240   IF (JPGD==2) YPGD=YPGD2
241   IF (JPGD==3) YPGD=YPGD3
242   IF (JPGD==4) YPGD=YPGD4
243   IF (JPGD==5) YPGD=YPGD5
244   IF (JPGD==6) YPGD=YPGD6
245   IF (JPGD==7) YPGD=YPGD7
246   IF (JPGD==8) YPGD=YPGD8
247   !
248   IF (LEN_TRIM(YPGD) == 0) THEN
249     IF (JPGD==1) THEN
250       WRITE(ILUOUT0,*) 'No pgd file was present for model 1 in namelist NAM_PGD1'
251 !callabortstop
252       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
253       CALL ABORT
254       STOP
255     ELSE
256       GADD=.FALSE.
257       CYCLE
258     END IF
259   END IF
260   !
261   IF ( (IDAD<1 .OR. IDAD>JPMODELMAX) .AND. (JPGD>1) ) THEN
262       WRITE(ILUOUT0,*) 'No father indicated for model ',JPGD,' in namelist NAM_PGD',JPGD
263 !callabortstop
264       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
265       CALL ABORT
266       STOP
267   END IF
268   !
269   IF (GADD) THEN
270     NMODEL=JPGD
271     !
272     IF (IDAD>=JPGD) THEN
273       WRITE(ILUOUT0,*) 'pgd files are not correctly ordered:'
274       WRITE(ILUOUT0,*) ' in namelist NAM_PGD',JPGD,' was found IDAD= ', IDAD
275 !callabortstop
276       CALL CLOSE_ll(CLUOUT0,IOSTAT=IRESP)
277       CALL ABORT
278       STOP
279     END IF
280     !
281     NDAD(JPGD)=IDAD
282     HPGD(JPGD)=YPGD
283   END IF
284 END DO
285 !
286 !-------------------------------------------------------------------------------
287 !
288 !*       5.    NAMES OF OUTPUT PGD FILES
289 !              -------------------------
290 !
291 CALL POSNAM(IPRE_NEST_PGD,'NAM_NEST_PGD',GFOUND,ILUOUT0)
292 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_NEST_PGD)
293 HNESTPGD(:) = '                            '
294 !
295 YSHORTPGD(:)=HPGD(:)
296 DO JPGD=1,NMODEL
297   HNESTPGD(JPGD) = ADJUSTR( YSHORTPGD(JPGD))//'.nest'//ADJUSTL(YNEST)
298   HNESTPGD(JPGD) = ADJUSTL(HNESTPGD(JPGD))
299 END DO
300 #ifdef MNH_NCWRIT
301 CALL POSNAM(IPRE_NEST_PGD,'NAM_NCOUT',GFOUND,ILUOUT0)
302 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_NCOUT)
303 #endif
304 !
305 CALL POSNAM(IPRE_NEST_PGD,'NAM_CONFIO',GFOUND,ILUOUT0)
306 IF (GFOUND) READ(UNIT=IPRE_NEST_PGD,NML=NAM_CONFIO)
307 CALL SET_CONFIO_ll(LCDF4, LLFIOUT, LLFIREAD)
308 !
309 !-------------------------------------------------------------------------------
310 CALL CLOSE_ll(HPRE_NEST_PGD)
311 !-------------------------------------------------------------------------------
312 !
313 !*       6.    OPENING OF INPUT AND OUTPUT PGD FILES
314 !              -------------------------------------
315 !
316 DO JPGD=1,NMODEL
317   CALL FMOPEN_ll(HPGD(JPGD),'READ',CLUOUT0,0,2,NVERB,ININAR,IRESP,OPARALLELIO=.FALSE.)
318   CALL FMOPEN_ll(HNESTPGD(JPGD),'WRITE',CLUOUT0,0,1,NVERB,ININAR,IRESP,OPARALLELIO=.FALSE.)
319 END DO
320 !
321 !-------------------------------------------------------------------------------
322 !
323 !*       7.    OPENING OF OUPUT LISTING FILES FOR ALL MODELS
324 !              ----------------------------------------------
325 !
326 DO JPGD=1,NMODEL
327   CALL GOTO_MODEL(JPGD)
328   WRITE(YLUOUT,'("OUTPUT_LISTING",I0)') JPGD
329   CALL OPEN_LUOUT_n(YLUOUT)
330 END DO
331 !
332 !-------------------------------------------------------------------------------
333 !
334 END SUBROUTINE OPEN_NESTPGD_FILES