SURFEX v8.1
General documentation of Surfex
fmfree.F90
Go to the documentation of this file.
1 ! ######spl
2  SUBROUTINE fmfree(HFILEM,HFIPRI,KRESP)
3  USE parkind1, ONLY : jprb
4  USE yomhook , ONLY : lhook, dr_hook
5 ! ######################################
6 !
7 !!**** *FMFREE* - routine to release a logical unit for FM
8 !!
9 !! PURPOSE
10 !! -------
11 !
12 ! The purpose of FMFREE is to free the logical unit attributed to
13 ! the file named HFILEM.
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! The association between the file named HFILEM and its logical unit
19 !! (ILOGIQ, say) was performed by a previous call to FMATTR. This link
20 !! is broken by setting the value CNAMFI(ILOGIQ) back to CPUDFN, so that
21 !! HFILEM does not appear anymore in CNAMFI.
22 !!
23 !! EXTERNAL
24 !! --------
25 !!
26 !!
27 !! IMPLICIT ARGUMENTS
28 !! ------------------
29 !!
30 !! MODULE: MODD_FMDECLAR contains management parameters and
31 !! storage arrays to move information around at the
32 !! level of all "FM"-routines.
33 !! MODD_FMMULTI contains variables for multitasking
34 !!
35 !! REFERENCE
36 !! ---------
37 !!
38 !! see the Technical Specifications Report for the Meso-nh project
39 !! (in French)
40 !!
41 !! AUTHOR
42 !! ------
43 !!
44 !! C. FISCHER *METEO-FRANCE*
45 !!
46 !! MODIFICATIONS
47 !! -------------
48 !!
49 !! original 06/94
50 !! modified by C. Fischer 5/7/95 (locks for multitasking)
51 !! modified by V. Masson 16/09/96 (prints if error occurs)
52 !!
53 !----------------------------------------------------------------------------
54 !
55 !* 0. DECLARATIONS
56 ! ------------
57 !
58 USE modd_fmdeclar
59 USE modd_fmmulti
60 
61 IMPLICIT NONE
62 !
63 !* 0.1 Declarations of arguments
64 !
65 CHARACTER(LEN=*), INTENT(IN) ::HFILEM ! file name
66 
67 CHARACTER(LEN=*), INTENT(IN) ::HFIPRI ! file for prints in FM
68 
69 INTEGER, INTENT(OUT)::KRESP ! return-code if problems araised
70 
71 !
72 !* 0.2 Declarations of local variables
73 !
74 INTEGER::IRESP=0,j,ilogiq=0,ilupri
75 CHARACTER(LEN=JPFINL)::YLOCFN,YLOCFN2
76 !
77 !* 0.3 Taskcommon for logical units
78 !
79 COMMON/TASKFREE/ILUPRI
80 !DIR$ TASKCOMMON TASKFREE
81 !
82 !----------------------------------------------------------------------------
83 !
84 !* 1. THE NAME IS SEARCHED IN CNAMFI AND ERASED
85 !
86 REAL(KIND=JPRB) :: ZHOOK_HANDLE
87 IF (lhook) CALL dr_hook('FMFREE',0,zhook_handle)
88 iresp = 0 ; ilogiq = 0 ; ilupri = 6
89 ylocfn=hfilem ; ylocfn=adjustl(ylocfn)
90 
91 
92 DO j=1,jpnxlu
93  IF (ylocfn.EQ.cnamfi(j)) THEN
94  ilogiq=j
95  cnamfi(j)=cpudfn
96  EXIT
97  ENDIF
98 ENDDO
99 IF (ilogiq.EQ.0) THEN
100  iresp=-42
101  GOTO 1000
102 ENDIF
103 
104 nopefi=nopefi-1
105 
106 
107 !
108 !* 2. MESSAGE PRINTING WHATEVER THE ISSUE WAS
109 !
110 1000 CONTINUE
111 
112 IF (iresp.NE.0) THEN
113  ylocfn2=adjustl(hfipri)
114  IF (ylocfn2.EQ.ylocfn) THEN
115 ! special case where HFILEM is the output listing itself: no print in this case
116 ! because we do not know whether this file has already been closed or not
117  ilupri=ilogiq
118  ELSE
119 ! most common case is this one
120  DO j=1,jpnxlu
121  IF (cnamfi(j).EQ.ylocfn2) THEN
122  ilupri=j
123  EXIT
124  ENDIF
125  ENDDO
126  WRITE (ilupri,*) ' exit from FMFREE with IRESP:',iresp
127  WRITE (ilupri,*) ' | HFILEM = ',hfilem
128  ENDIF
129 ENDIF
130 kresp=iresp
131 
132 IF (lhook) CALL dr_hook('FMFREE',1,zhook_handle)
133 RETURN
134  IF (lhook) CALL dr_hook('FMFREE',1,zhook_handle)
135  END SUBROUTINE fmfree
integer, parameter jpnxlu
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15
subroutine fmfree(HFILEM, HFIPRI, KRESP)
Definition: fmfree.F90:3