SURFEX v8.1
General documentation of Surfex
fmclos.F90
Go to the documentation of this file.
1 ! ######spl
2  SUBROUTINE fmclos(HFILEM,HSTATU,HFIPRI,KRESP)
3  USE parkind1, ONLY : jprb
4  USE yomhook , ONLY : lhook, dr_hook
5 ! #############################################
6 !
7 !!**** *FMCLOS* - routine to close a meso-nh file opened with the "FM"-routines
8 !!
9 !! PURPOSE
10 !! -------
11 !
12 ! The purpose of FMCLOS is to close a mesonh file composed of the DESFM
13 ! and the LFIFM part. The LFIFM file is closed
14 ! using the LFI-package for direct access Fortran files. The DESFM file is
15 ! closed using a classical CLOSE statement.
16 !
17 !!** METHOD
18 !! ------
19 !!
20 !! The closure is proceeded in 4 steps:
21 !! 1. close DESFM
22 !! 2. close LFIFM by calling LFIFER
23 !! 3. erase the file from the management arrays (FMFREE)
24 !! 4. the cpio and storage command is loaded into the pipe
25 !! the pipe has the special fortran unit 10
26 !!
27 !! EXTERNAL
28 !! --------
29 !!
30 !! FMLOOK,FMFREE,LFIFER,CLOSE,FLUSH
31 !!
32 !! IMPLICIT ARGUMENTS
33 !! ------------------
34 !!
35 !! MODULE: MODD_FMDECLAR contains management parameters and
36 !! storage arrays to move information around at the
37 !! level of all "FM"-routines.
38 !! MODD_FMMULTI contains variables for multitasking
39 !!
40 !! REFERENCE
41 !! ---------
42 !!
43 !! see the Technical Specifications Report for the Meso-nh project
44 !! (in French)
45 !!
46 !! AUTHOR
47 !! ------
48 !!
49 !! C. FISCHER *METEO-FRANCE*
50 !!
51 !! MODIFICATIONS
52 !! -------------
53 !!
54 !! original 06/94
55 !! modified by C. Fischer 4/11/94 (write in the pipe)
56 !! modified by C. Fischer 5/7/95 (locks for multitasking)
57 !! modified by P. Jabouille 26/06/96 (case NFITYP=2 :
58 !! file is not sent to the remote machine)
59 !! modified by V. Masson 16/09/96 (prints if error occurs)
60 !!
61 !----------------------------------------------------------------------------
62 !
63 !* 0. DECLARATIONS
64 ! ------------
65 !
66 USE modd_fmdeclar
67 USE modd_fmmulti
68 
69 IMPLICIT NONE
70 !
71 !* 0.1 Declarations of arguments
72 !
73 CHARACTER(LEN=*), INTENT(IN) ::HFILEM ! file name
74 CHARACTER(LEN=*), INTENT(IN) ::HSTATU ! status for the closed file
75 
76 CHARACTER(LEN=*), INTENT(IN) ::HFIPRI ! file for prints in FM
77 
78 INTEGER, INTENT(OUT)::KRESP ! return-code if problems araised
79 
80 !
81 !* 0.2 Declarations of local variables
82 !
83 INTEGER::IRESP,IROWF,IPOSNU,J,INUMBR,IFMFNL,ILUPRI,IERR
84 CHARACTER(LEN=7)::YSTATU
85 CHARACTER(LEN=JPFINL)::YFNDES,YFNLFI
86 CHARACTER(LEN=LEN(HFILEM))::YINTFN
87 CHARACTER(LEN=10)::YTRANS,YCPIO
88 CHARACTER(LEN=100)::YCOMMAND
89 LOGICAL::GSTATU
90 !
91 !* 0.3 Taskcommon for logical units
92 !
93 COMMON/TASKCLOS/ILUPRI,INUMBR,IRESP,YFNDES,YFNLFI,YSTATU
94 !DIR$ TASKCOMMON TASKCLOS
95 !
96 !----------------------------------------------------------------------------
97 !
98 !* 1.1 THE NAME OF DESFM=HFILEM.des
99 !
100 REAL(KIND=JPRB) :: ZHOOK_HANDLE
101 IF (lhook) CALL dr_hook('FMCLOS',0,zhook_handle)
102 iresp = 0 ; irowf = 0 ; iposnu = 0 ; ilupri = 6 ; ierr = 0
103 ifmfnl=jpfinl-4
104 ytrans='transfer.x'
105 
106 irowf=len(hfilem)
107 
108 IF (irowf.EQ.0) THEN
109  iresp=-59
110  GOTO 1000
111 ELSEIF (irowf.GT.ifmfnl) THEN
112  iresp=-60
113  GOTO 1000
114 ENDIF
115 yintfn=adjustr(hfilem)
116 yfndes=yintfn//'.des'
117 yfndes=adjustl(yfndes)
118 !
119 !* 1.2 TEST FOR FILE EXISTENCE AND SEARCH OF ITS LOGICAL UNIT
120 !
121 CALL FMLOOK(YFNDES,HFIPRI,INUMBR,IRESP)
122 IF (iresp.NE.0) THEN
123  GOTO 1000
124 ELSEIF (len(hstatu).LE.0) THEN
125  iresp=-41
126  GOTO 1000
127 ELSE
128  gstatu=hstatu.EQ.'KEEP'.OR.hstatu.EQ.'DELETE'
129  IF (gstatu) THEN
130  ystatu=hstatu(1:min0(len(hstatu),len(ystatu)))
131  ELSE
132  ystatu='DEFAULT'
133  ENDIF
134 ENDIF
135 !
136 !* 1.3 THE LOGICAL UNIT OF DESFM IS RELEASED FOR "FM"
137 !
138 CALL FMFREE(YFNDES,HFIPRI,IRESP)
139 IF (iresp.NE.0) GOTO 1000
140 !
141 !* 2. CLOSURE OF DESFM
142 !
143 ! case of a namelist
144 !
145 CLOSE (UNIT=INUMBR,IOSTAT=IRESP,STATUS=YSTATU)
146 IF (iresp.NE.0) GOTO 1000
147 !
148 !* 3.1 THE NAME OF LFIFM=HFILEM.lfi
149 !
150 yfnlfi=yintfn//'.lfi'
151 yfnlfi=adjustl(yfnlfi)
152 !
153 !* 3.2 TEST FOR FILE EXISTENCE AND SEARCH OF ITS LOGICAL UNIT
154 !
155 CALL FMLOOK(YFNLFI,HFIPRI,INUMBR,IRESP)
156 IF (iresp.NE.0) GOTO 1000
157 !
158 !* 3.3 THE LOGICAL UNIT FOR LFIFM IS RELEASED FOR "FM"
159 !
160 CALL FMFREE(YFNLFI,HFIPRI,IRESP)
161 IF (iresp.NE.0) GOTO 1000
162 !
163 !* 4. CLOSURE OF LFI
164 !
165 ! case of a LFI file
166 !
167 CALL LFIFER(IRESP,INUMBR,YSTATU)
168 IF (iresp.NE.0) GOTO 1000
169 !
170 !* 5. INPUT FOR THE UNIX SYSTEM TO SAVE AND SEND THE FILE
171 !
172 print*,'KTYPE=',nfityp(inumbr)
173 SELECT CASE (nfityp(inumbr))
174 CASE(:-1)
175  iresp=-66
176  GOTO 1000
177 CASE(0)
178  ycpio='NIL'
179 CASE(1)
180  ycpio='MESONH'
181 CASE(2)
182  print*,'FILE ',hfilem,' NOT TRANSFERED'
183  GOTO 1000
184 CASE(3:)
185  iresp=-66
186  GOTO 1000
187 END SELECT
188 WRITE (ycommand,20) ytrans,ycpio,hfilem
189 !
190 ! write into the pipe : the "flush" forces instanteneous buffer transfer
191 ! which is necessary for parallel treatment
192 !
193 print*,'YCOMMAND=',ycommand
194 WRITE (10,'(A100)') ycommand
195 !CALL FLUSH(10,IERR)
196 !
197 !* 6. UPDATING OF ARRAY NFITYP
198 !
199 nfityp(inumbr)=jpniil
200 !
201 !* 7. MESSAGE PRINTING WHATEVER THE ISSUE WAS
202 !
203 1000 CONTINUE
204 
205 IF (iresp.NE.0) THEN
206 yfnlfi=adjustl(hfipri)
207 DO j=1,jpnxlu
208  IF (cnamfi(j).EQ.yfnlfi) THEN
209  ilupri=j
210  EXIT
211  ENDIF
212 ENDDO
213 WRITE (ilupri,*) ' exit from FMCLOS with IRESP:',iresp
214 WRITE (ilupri,*) ' | HFILEM = ',hfilem
215 WRITE (ilupri,*) ' | HSTATU = ',hstatu
216 ENDIF
217 kresp=iresp
218 
219 ! format: 10c for transfer.x and mesonh/nil
220 ! 32c for file name
221 ! if you have to change this format one day, don't forget the blank after 1H
222 20 FORMAT(a10,1h ,a10,1h ,a32)
223 
224 IF (lhook) CALL dr_hook('FMCLOS',1,zhook_handle)
225 RETURN
226  IF (lhook) CALL dr_hook('FMCLOS',1,zhook_handle)
227  END SUBROUTINE fmclos
integer, dimension(1:jpnxlu) nfityp
integer, parameter jpfinl
subroutine fmclos(HFILEM, HSTATU, HFIPRI, KRESP)
Definition: fmclos.F90:3
integer, parameter jpnxlu
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15
integer, parameter jpniil