SURFEX v8.1
General documentation of Surfex
fm_read.F90
Go to the documentation of this file.
1 ! ######spl
2  SUBROUTINE fm_read(HFILEM,HRECFM,HFIPRI,KLENG,KFIELD,KGRID,&
3  KLENCH,HCOMMENT,KRESP)
4  USE parkind1, ONLY : jprb
5  USE yomhook , ONLY : lhook, dr_hook
6 ! ###########################################################
7 !
8 !!**** *FM_READ* - routine to read a single data article in a "FM"-file
9 !!
10 !! PURPOSE
11 !! -------
12 !
13 ! The purpose of FMREAD is to read one single article of data in
14 ! a Meso-nh file. This routine only holds for LFI-files (not namelists)
15 !
16 !!** METHOD
17 !! ------
18 !!
19 !! The unformatted fortran read operation is actually executed in the
20 !! routine LFILEC. You just need to indicate the name of the file
21 !! without the ".lfi" suffix,
22 !! and the name of the article you want to read, as well as the length of
23 !! the field. LFILEC then knows how
24 !! to get the record number of the desired field by referring to an intern
25 !! table of association.
26 !! In FMREAD, the data is first stored in IWORK and then split in KGRID
27 !! (IWORK(1)=C-grid indicator) and KFIELD (integer or real data field)
28 !! which are both stored on the same LFI logical article.
29 !!
30 !! EXTERNAL
31 !! --------
32 !!
33 !! FMLOOK,LFINFO,LFILEC,CHAR
34 !!
35 !! IMPLICIT ARGUMENTS
36 !! ------------------
37 !!
38 !! MODULE: MODD_FMDECLAR contains management parameters and
39 !! storage arrays to move information around at the
40 !! level of all "FM"-routines.
41 !!
42 !! REFERENCE
43 !! ---------
44 !!
45 !! see the Technical Specifications Report for the Meso-nh project
46 !! (in French)
47 !!
48 !! AUTHOR
49 !! ------
50 !!
51 !! C. FISCHER *METEO-FRANCE*
52 !!
53 !! MODIFICATIONS
54 !! -------------
55 !!
56 !! original 06/94
57 !! modified by V. Masson 16/09/96 (prints if error occurs)
58 !!
59 !----------------------------------------------------------------------------
60 !
61 !* 0. DECLARATIONS
62 ! ------------
63 !
64 USE modd_fmdeclar
65 
66 IMPLICIT NONE
67 !
68 !* 0.1 Declarations of arguments
69 !
70 CHARACTER(LEN=*), INTENT(IN) ::HFILEM ! file name
71 CHARACTER(LEN=*), INTENT(IN) ::HRECFM ! name of the desired article
72 
73 CHARACTER(LEN=*), INTENT(IN) ::HFIPRI ! file for prints in FM
74 
75 INTEGER, INTENT(IN) ::KLENG ! length of the data field
76 
77 INTEGER(KIND=8),DIMENSION(1:KLENG),INTENT(OUT)::KFIELD ! array containing
78  ! the data field
79 INTEGER, INTENT(OUT)::KGRID ! C-grid indicator (u,v,w,T)
80 INTEGER, INTENT(OUT)::KLENCH ! length of comment string
81 
82 CHARACTER(LEN=JPXKRK), INTENT(OUT)::HCOMMENT ! comment string
83 
84 INTEGER, INTENT(OUT)::KRESP ! return-code if problems occured
85 
86 !
87 !* 0.2 Declarations of local variables
88 !
89 INTEGER::IRESP,ILENGA,IPOSEX,ITOTAL,INUMBR,J,IROW,IFMFNL,ILUPRI
90 INTEGER(KIND=8),DIMENSION(:),ALLOCATABLE::IWORK,IWORKNEW
91 INTEGER,DIMENSION(1:JPXKRK)::ICOMMENT
92 CHARACTER(LEN=JPFINL)::YFNLFI
93 CHARACTER(LEN=LEN(HFILEM))::YINTFN
94 INTEGER :: DATASIZE,ITYPCOD,NEWSIZE
95 !
96 !* 0.3 Taskcommon for logical units
97 !
98 COMMON/TASKREAD/ILUPRI,INUMBR,IRESP
99 !DIR$ TASKCOMMON TASKREAD
100 !
101 !----------------------------------------------------------------------------
102 !
103 !* 1.1 THE NAME OF LFIFM
104 !
105 REAL(KIND=JPRB) :: ZHOOK_HANDLE
106 IF (lhook) CALL dr_hook('FM_READ',0,zhook_handle)
107 iresp = 0 ; irow = 0 ; ilupri = 6
108 ifmfnl=jpfinl-4
109 
110 irow=len(hfilem)
111 
112 IF (irow.EQ.0) THEN
113  iresp=-61
114  GOTO 1000
115 ELSEIF (irow.GT.ifmfnl) THEN
116  iresp=-62
117  GOTO 1000
118 ENDIF
119 yintfn=adjustr(hfilem)
120 yfnlfi=yintfn//'.lfi'
121 yfnlfi=adjustl(yfnlfi)
122 
123 !
124 !* 1.2 WE LOOK FOR THE FILE'S LOGICAL UNIT
125 !
126 CALL FMLOOK(YFNLFI,HFIPRI,INUMBR,IRESP)
127 IF (iresp.NE.0) GOTO 1000
128 
129 !
130 !* 2.a LET'S GET SOME INFORMATION ON THE DESIRED ARTICLE
131 !
132 !ILENGA=0
133 !print *,' ***FM_READ ILENGA mis a 0 avant CALL LFINFO'
134 CALL LFINFO(IRESP,INUMBR,HRECFM,ILENGA,IPOSEX)
135 !print *,' ***FM_READ ILENGA,IRESP AP LFINFO ',ILENGA,IRESP
136 IF (iresp.NE.0) THEN
137  GOTO 1000
138 ELSEIF (ilenga.EQ.0) THEN
139 !print *,' ***FM_READ passage IRESP=-47 GOTO 1000'
140  iresp=-47
141  GOTO 1000
142 ELSEIF (ilenga.GT.jpxfie) THEN
143  iresp=-48
144  GOTO 1000
145 ENDIF
146 
147 !
148 !* 2.b UNFORMATTED DIRECT ACCESS READ OPERATION
149 !
150 itotal=ilenga
151 IF(ALLOCATED(iwork)) DEALLOCATE(iwork)
152 ALLOCATE(iwork(itotal))
153 
154 CALL LFILEC(IRESP,INUMBR,HRECFM,IWORK,ITOTAL)
155 IF (iresp.NE.0) GOTO 1000
156 !
157 !* 2.c THE GRID INDICATOR AND THE COMMENT STRING
158 !* ARE SEPARATED FROM THE DATA
159 !
160 kgrid=iwork(1)
161 klench=iwork(2)
162 IF (klench < 0 .OR. klench > jpxkrk) THEN
163  iresp=-58
164  GOTO 1000
165 END IF
166 !
167 datasize=itotal-klench-2
168 !
169 !pas de compression
170 !
171 !CALL GET_COMPHEADER(IWORK(3+KLENCH),DATASIZE,NEWSIZE,ITYPCOD)
172 !IF (NEWSIZE >= 0) THEN
173  !! compressed field found
174  !WRITE (ILUPRI,*) TRIM(HRECFM),' is compressed (old/new/kleng SIZE):',DATASIZE,NEWSIZE,KLENG
175  !IF (KLENG /= NEWSIZE) THEN
176  !IRESP=-63
177  !GOTO 1000
178  !ENDIF
179 !
180  !ALLOCATE(IWORKNEW(NEWSIZE))
181  !CALL DECOMPRESS_FIELD(IWORKNEW,NEWSIZE,IWORK(3+KLENCH),DATASIZE,ITYPCOD)
182  !KFIELD(1:KLENG) = IWORKNEW(1:KLENG)
183  !DEALLOCATE(IWORKNEW)
184 !ELSE
185  IF (kleng > datasize) THEN
186  iresp=-63
187  GOTO 1000
188  END IF
189  kfield(1:kleng)=iwork(klench+3:klench+2+kleng)
190 !END IF
191 !
192 SELECT CASE (klench)
193 CASE(-10:-1)
194  iresp=-58
195  GOTO 1000
196 CASE(0)
197  kfield(1:kleng)=iwork(3:itotal)
198 CASE(1:JPXKRK)
199  icomment(1:klench)=iwork(3:klench+2)
200  DO j=1,klench
201  hcomment(j:j)=char(icomment(j))
202  ENDDO
203 CASE(JPXKRK+1:)
204  iresp=-56
205  GOTO 1000
206 END SELECT
207 !
208 DEALLOCATE(iwork)
209 !
210 ! this is a pure binary field: no uncompressing of any kind
211 !
212 !* 3. MESSAGE PRINTING WHATEVER THE ISSUE WAS
213 !
214 1000 CONTINUE
215 
216 IF (iresp.NE.0) THEN
217  yfnlfi=adjustl(hfipri)
218  DO j=1,jpnxlu
219  IF (cnamfi(j).EQ.yfnlfi) THEN
220  ilupri=j
221  EXIT
222  ENDIF
223  ENDDO
224  WRITE (ilupri,*) ' exit from FMREAD with IRESP:',iresp
225  !WRITE (ILUPRI,*) ' | HFILEM = ',HFILEM
226  WRITE (ilupri,*) ' | HRECFM = ',hrecfm
227  !WRITE (ILUPRI,*) ' | KLENG = ',KLENG
228  !WRITE (ILUPRI,*) ' | KGRID = ',KGRID
229  !WRITE (ILUPRI,*) ' | KLENCH = ',KLENCH
230  ! Suppression OBLIGATOIRE de l'impression suivante car pb qd IWORK non alloue
231  ! (IRESP=-47)
232  !WRITE (ILUPRI,*) ' | KLENCH = ',IWORK(23)
233 ENDIF
234 kresp=iresp
235 
236 IF(ALLOCATED(iwork)) DEALLOCATE(iwork)
237 
238 IF (lhook) CALL dr_hook('FM_READ',1,zhook_handle)
239 
240  END SUBROUTINE fm_read
integer, parameter jpfinl
integer, parameter jpnxlu
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15
integer, parameter jpxfie
integer, parameter jpxkrk
subroutine fm_read(HFILEM, HRECFM, HFIPRI, KLENG, KFIELD, KGRID, KLENCH, HCOMMENT, KRESP)
Definition: fm_read.F90:4