SURFEX v8.1
General documentation of Surfex
fmopen.F90
Go to the documentation of this file.
1 ! ######spl
2  SUBROUTINE fmopen(HFILEM,HSTATU,HFIPRI,KNPRAR,KFTYPE,KVERB,&
3  KNINAR,KRESP)
4  USE parkind1, ONLY : jprb
5  USE yomhook , ONLY : lhook, dr_hook
6 ! ############################################################
7 !
8 !!**** *FMOPEN* - routine to open a meso-nh file (DESFM+LFIFM)
9 !!
10 !! PURPOSE
11 !! -------
12 !
13 ! The purpose of FMOPEN is to open a meso-nh file for the "FM"-routines.
14 ! It is composed of two distinct fortran files: DESFM and LFIFM. DESFM is
15 ! a namelist formatted file. LFIFM is a LFI file, managed by the LFI-package.
16 ! LFIFM is a fortran unformatted, direct access file which is
17 ! manipulated by the FM-routines FMREAD and FMWRIT.
18 ! The namelist file is a fortran 90 standard formatted file.
19 !
20 !!** METHOD
21 !! ------
22 !!
23 !! The opening is performed in 4 main steps:
24 !! 1. a logical unit is reserved for DESFM (first call to FMATTR)
25 !! 2. the DESFM file is created by a
26 !! formatted, fortran open. The name of the file is obtained by
27 !! appending ".des" to HFILEM.
28 !! 3. a logical unit is reserved for LFIFM (second call to FMATTR)
29 !! 4. the LFIFM file is opened in the LFIOUV routine to
30 !! which most of the explicit input arguments of FMOPEN are passed.
31 !! The name of that file is obtained by appending ".lfi"
32 !! to HFILEM.
33 !!
34 !! EXTERNAL
35 !! --------
36 !!
37 !! FMATTR,LFIOUV,OPEN
38 !!
39 !! IMPLICIT ARGUMENTS
40 !! ------------------
41 !!
42 !! MODULE: MODD_FMDECLAR contains management parameters and
43 !! storage arrays to move information around at the
44 !! level of all "FM"-routines.
45 !! MODD_FMMULTI contains variables for multitasking
46 !!
47 !! REFERENCE
48 !! ---------
49 !!
50 !! see the Technical Specifications Report for the Meso-nh project
51 !! (in French)
52 !!
53 !! AUTHOR
54 !! ------
55 !!
56 !! C. FISCHER *METEO-FRANCE*
57 !!
58 !! MODIFICATIONS
59 !! -------------
60 !!
61 !! original 06/94
62 !! modified by C. Fischer 5/7/95 (locks for multitasking)
63 !! modified by V. Masson 16/09/96 (prints if error occurs)
64 !!
65 !----------------------------------------------------------------------------
66 !
67 !* 0. DECLARATIONS
68 ! ------------
69 !
70 USE modd_fmdeclar
71 USE modd_fmmulti
72 
73 IMPLICIT NONE
74 !
75 !* 0.1 Declarations of arguments
76 !
77 CHARACTER(LEN=*), INTENT(IN) ::HFILEM ! name of the file
78 CHARACTER(LEN=*), INTENT(IN) ::HSTATU ! status of the file at opening
79 CHARACTER(LEN=*), INTENT(IN) ::HFIPRI ! file for prints in FM
80 
81 INTEGER, INTENT(IN) ::KNPRAR ! number of predicted articles (not vital)
82 INTEGER, INTENT(IN) ::KFTYPE ! type of FM-file
83 INTEGER, INTENT(IN) ::KVERB ! level of verbose
84 
85 INTEGER, INTENT(OUT)::KNINAR ! number of articles initially present in the file
86 INTEGER, INTENT(OUT)::KRESP ! return-code if a problem araised
87 
88 !
89 !* 0.2 Declarations of local variables
90 !
91 INTEGER::IRESOU,INPRAR,IROWF,IRESP,J,INUMBR,IFMFNL,IMELEV,ILUPRI
92 CHARACTER(LEN=JPFINL)::YFNDES,YFNLFI
93 CHARACTER(LEN=LEN(HFILEM))::YINTFN
94 LOGICAL::GNEWFI,GNAMFI=.true.,gfater=.true.,gstats
95 !
96 !* 0.3 Taskcommon for logical units
97 !
98 COMMON/TASKOPEN/ILUPRI,INUMBR,IRESP,YFNDES,YFNLFI
99 !DIR$ TASKCOMMON TASKOPEN
100 !
101 !----------------------------------------------------------------------------
102 !
103 !* 1. INITIALIZATION
104 !
105 REAL(KIND=JPRB) :: ZHOOK_HANDLE
106 IF (lhook) CALL dr_hook('FMOPEN',0,zhook_handle)
107 inprar=knprar+0;kninar=0
108 iresou = 0 ; irowf = 0 ; iresp = 0 ; ilupri = 6
109 !
110 !* the model's verbose level is connected to the LFI verbose
111 !
112 SELECT CASE (kverb)
113 CASE(:2)
114  gstats=.false. ; imelev=0
115 CASE(3:6)
116  gstats=.false. ; imelev=1
117 CASE(7:9)
118  gstats=.false. ; imelev=2
119 CASE(10:)
120  gstats=.true. ; imelev=2
121 END SELECT
122 
123 IF (nopefi.GE.jpnxfm) THEN
124  iresp=-44
125  GOTO 1000
126 ENDIF
127 !
128 !* 2. LOGICAL UNIT FOR DESFM
129 !
130 ! the fortran name for DESFM
131 !
132 ifmfnl=jpfinl-4
133 
134 irowf=len(hfilem)
135 
136 IF (irowf.EQ.0) THEN
137  iresp=-45
138  GOTO 1000
139 ELSEIF (irowf.GT.ifmfnl) THEN
140  iresp=-49
141  GOTO 1000
142 ENDIF
143 yintfn=adjustr(hfilem)
144 yfndes=yintfn//'.des'
145 yfndes=adjustl(yfndes)
146 
147 CALL FMATTR(YFNDES,HFIPRI,INUMBR,IRESP)
148 IF (iresp.NE.0) GOTO 1000
149 
150 !
151 !* 3. FILE OPENING FOR DESFM
152 !
153 ! case of a namelist: sequential, formatted fortran open
154 !
155 OPEN(unit=inumbr,file=yfndes,form='FORMATTED',delim='QUOTE',iostat=iresp)
156 IF (iresp.NE.0) GOTO 1000
157 !
158 !* 4. LOGICAL UNIT FOR LFIFM
159 !
160 ! the fortran name for LFIFM
161 !
162 yfnlfi=yintfn//'.lfi'
163 yfnlfi=adjustl(yfnlfi)
164 
165 CALL FMATTR(YFNLFI,HFIPRI,INUMBR,IRESP)
166 IF (iresp.NE.0) GOTO 1000
167 !
168 !* 5. FILE OPENING FOR LFIFM
169 !
170 ! case of a LFI-file: direct access, unformatted open via LFIOUV
171 !
172 CALL LFIOUV(IRESOU,INUMBR,GNAMFI,YFNLFI,HSTATU,GFATER,GSTATS,IMELEV,INPRAR,&
173  kninar)
174 IF (iresou.NE.0.AND.iresou.NE.-11) THEN
175  iresp=iresou
176  GOTO 1000
177 ENDIF
178 
179 !
180 !* 6. TEST IF FILE IS NEWLY DEFINED
181 !
182 
183 gnewfi=(kninar.EQ.0).OR.(kverb.LT.7)
184 IF (.NOT.gnewfi) THEN
185 yfnlfi=adjustl(hfipri)
186 DO j=1,jpnxlu
187  IF (cnamfi(j).EQ.yfnlfi) THEN
188  ilupri=j
189  EXIT
190  ENDIF
191 ENDDO
192 WRITE (ilupri,*) ' file ',inumbr,'previously created with LFI'
193 ENDIF
194 !
195 !* 7. UPDATE OF THE FILE TYPE ARRAY
196 !
197 nfityp(inumbr)=kftype
198 !
199 !* 8. MESSAGE PRINTING WHATEVER THE ISSUE WAS
200 !
201 1000 CONTINUE
202 
203 IF (iresp.NE.0) THEN
204 yfnlfi=adjustl(hfipri)
205 DO j=1,jpnxlu
206  IF (cnamfi(j).EQ.yfnlfi) THEN
207  ilupri=j
208  EXIT
209  ENDIF
210 ENDDO
211 WRITE (ilupri,*) ' exit from FMOPEN with IRESP:',iresp
212 WRITE (ilupri,*) ' | HFILEM = ',hfilem
213 WRITE (ilupri,*) ' | HSTATU = ',hstatu
214 WRITE (ilupri,*) ' | KNPRAR = ',knprar
215 WRITE (ilupri,*) ' | KFTYPE = ',kftype
216 ENDIF
217 kresp=iresp
218 
219 IF (lhook) CALL dr_hook('FMOPEN',1,zhook_handle)
220 RETURN
221  IF (lhook) CALL dr_hook('FMOPEN',1,zhook_handle)
222  END SUBROUTINE fmopen
subroutine fmopen(HFILEM, HSTATU, HFIPRI, KNPRAR, KFTYPE, KVERB, KNINAR, KRESP)
Definition: fmopen.F90:4
integer, parameter jpnxfm
subroutine gstats(KNUM, KSWITCH)
Definition: gstats.F90:2
integer, dimension(1:jpnxlu) nfityp
integer, parameter jpfinl
integer, parameter jpnxlu
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15