SURFEX v8.1
General documentation of Surfex
fmattr.F90
Go to the documentation of this file.
1 ! ######spl
2  SUBROUTINE fmattr(HFILEM,HFIPRI,KNUMBR,KRESP)
3  USE parkind1, ONLY : jprb
4  USE yomhook , ONLY : lhook, dr_hook
5 ! #############################################
6 !
7 !!**** *FMATTR* - routine to attribute a logical unit to a file name
8 !!
9 !! PURPOSE
10 !! -------
11 !
12 ! The purpose of FMATTR is to attribute to the file named HFILEM
13 ! the logical unit number KNUMBR chosen among the free logical units
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! If FMATTR is called for the very first time, then all the management
19 !! arrays used by the FM-routines are initialized in FMINIT.
20 !! Otherwise, the name HFILEM is searched in the array CNAMFI, where
21 !! it should not exist ! Finally, a logical unit number is searched
22 !! in array CNAMFI. As soon as a free place is found (CNAMFI=CPUDFN),
23 !! this place becomes the logical unit number for HFILEM and CNAMFI is
24 !! set to HFILEM.
25 !!
26 !! EXTERNAL
27 !! --------
28 !!
29 !!
30 !! IMPLICIT ARGUMENTS
31 !! ------------------
32 !!
33 !! MODULE: MODD_FMDECLAR contains management parameters and
34 !! storage arrays to move information around at the
35 !! level of all "FM"-routines.
36 !! MODD_FMMULTI contains variables for multitasking
37 !!
38 !! REFERENCE
39 !! ---------
40 !!
41 !! see the Technical Specifications Report for the Meso-nh project
42 !! (in French)
43 !!
44 !! AUTHOR
45 !! ------
46 !!
47 !! C. FISCHER *METEO-FRANCE*
48 !!
49 !! MODIFICATIONS
50 !! -------------
51 !!
52 !! original 04/94
53 !! modified by C. Fischer 5/7/95 (locks for multitasking)
54 !! modified by V. Masson 16/09/96 (prints if error occurs)
55 !!
56 !----------------------------------------------------------------------------
57 !
58 !* 0. DECLARATIONS
59 ! ------------
60 !
61 USE modd_fmdeclar
62 USE modd_fmmulti
63 
64 IMPLICIT NONE
65 !
66 !* 0.1 Declarations of arguments
67 !
68 CHARACTER(LEN=*), INTENT(IN) ::HFILEM ! file name
69 
70 CHARACTER(LEN=*), INTENT(IN) ::HFIPRI ! file for prints in FM
71 
72 INTEGER, INTENT(OUT)::KNUMBR ! logical unit number
73 INTEGER, INTENT(OUT)::KRESP ! return-code if problems araised
74 !
75 !* 0.2 Declarations of local variables
76 !
77 INTEGER::IRESP=0,j,ilogiq=0,ilupri
78 CHARACTER(LEN=JPFINL)::YLOCFN,YLOCFN2
79 !
80 !* 0.3 Taskcommon for logical units
81 !
82 COMMON/TASKATTR/ILUPRI
83 !DIR$ TASKCOMMON TASKATTR
84 !
85 !----------------------------------------------------------------------------
86 !
87 !* 1. INITIALISATION AND TEST THAT FILE DOES NOT ALREADY EXIST
88 !
89 REAL(KIND=JPRB) :: ZHOOK_HANDLE
90 IF (lhook) CALL dr_hook('FMATTR',0,zhook_handle)
91 iresp = 0 ; ilogiq = 0 ; ilupri = 6
92 ylocfn=hfilem ; ylocfn=adjustl(ylocfn)
93 
94 
95 IF (lfcatt) THEN
96  CALL fminit
97  lfcatt=.false.
98 ELSE
99  IF (nopefi.LT.0) THEN
100  iresp=-50
101  GOTO 1000
102  ELSE
103  DO j=1,jpnxlu
104  IF (ylocfn.EQ.cnamfi(j)) THEN
105  iresp=-51
106  GOTO 1000
107  ENDIF
108  ENDDO
109  ENDIF
110 ENDIF
111 !
112 !* 2. WE LOOK FOR A FREE PLACE IN ARRAY CNAMFI
113 !
114 ! That place will become the number for the logical unit attributed to HFILEM
115 !
116 DO j=1,jpnxlu
117  IF (cnamfi(j).EQ.cpudfn) THEN
118  ilogiq=j
119  cnamfi(j)=ylocfn
120  EXIT
121  ENDIF
122 ENDDO
123 IF (ilogiq.EQ.0) THEN
124  iresp=-52
125  GOTO 1000
126 ENDIF
127 
128 knumbr=ilogiq ; nopefi=nopefi+1
129 !
130 !* 3. MESSAGE PRINTING WHATEVER THE ISSUE WAS
131 !
132 1000 CONTINUE
133 
134 IF (iresp.NE.0) THEN
135  ylocfn2=adjustl(hfipri)
136 !
137 ! in the special case where FMATTR is called to reserve a logical unit
138 ! for the output file itself (i.e. HFILEM=HFIPRI),
139 ! no print is performed because we do not know
140 ! whether this file was actually opened or not.
141 !
142  IF (ylocfn2.EQ.ylocfn) THEN
143  ilupri=ilogiq
144  ELSE
145  DO j=1,jpnxlu
146  IF (cnamfi(j).EQ.ylocfn2) THEN
147  ilupri=j
148  EXIT
149  ENDIF
150  ENDDO
151  WRITE (ilupri,*) ' exit from FMATTR with IRESP:',iresp
152  WRITE (ilupri,*) ' | HFILEM = ',hfilem
153  ENDIF
154 ENDIF
155 kresp=iresp
156 
157 IF (lhook) CALL dr_hook('FMATTR',1,zhook_handle)
158 RETURN
159  IF (lhook) CALL dr_hook('FMATTR',1,zhook_handle)
160  END SUBROUTINE fmattr
integer, parameter jpnxlu
integer, parameter jprb
Definition: parkind1.F90:32
subroutine fmattr(HFILEM, HFIPRI, KNUMBR, KRESP)
Definition: fmattr.F90:3
logical lhook
Definition: yomhook.F90:15
subroutine fminit
Definition: fminit.F90:3