The TELEMAC-MASCARET system  trunk
read_fic_frliq.f
Go to the documentation of this file.
1 ! *************************
2  SUBROUTINE read_fic_frliq
3 ! *************************
4 !
5  &( q , what , at , nfic , listin , found)
6 !
7 !***********************************************************************
8 ! TELEMAC2D V7P2
9 !***********************************************************************
10 !
11 !brief READS AND INTERPOLATES VALUES FROM THE LIQUID BOUNDARY FILE.
12 !
13 !history J-M HERVOUET (LNHE)
14 !+ 10/08/2009
15 !+ V6P0
16 !+
17 !
18 !history J-M HERVOUET (LNHE)
19 !+ 28/06/2010
20 !+ V6P0
21 !+ SIZE OF LIGN PARAMETERIZED (SEE SIZELIGN)
22 !
23 !history N.DURAND (HRW), S.E.BOURBAN (HRW)
24 !+ 13/07/2010
25 !+ V6P0
26 !+ Translation of French comments within the FORTRAN sources into
27 !+ English comments
28 !
29 !history N.DURAND (HRW), S.E.BOURBAN (HRW)
30 !+ 21/08/2010
31 !+ V6P0
32 !+ Creation of DOXYGEN tags for automated documentation and
33 !+ cross-referencing of the FORTRAN sources
34 !
35 !history C. COULET (ARTELIA GROUP)
36 !+ 08/11/2011
37 !+ V6P2
38 !+ Modification size WHAT and CHOIX_RFF due to modification of TRACER
39 !
40 !history U.H. Merkel (BAW)
41 !+ 17/07/2012
42 !+ V6P2
43 !+ NAG: MAXVAL intrinsic! -> MAXVALUE_RFF
44 !
45 !history J-M HERVOUET (LNHE)
46 !+ 13/12/2012
47 !+ V6P3
48 !+ Now works with tabs as well as spaces as delimiters.
49 !
50 !history J-M HERVOUET (EDF LAB, LNHE)
51 !+ 15/07/2016
52 !+ V7P2
53 !+ Now controlling that the time of a new line is greater than the
54 !+ time of the previous line.
55 !
56 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 !| AT |-->| TIME_RFF IN SECONDS
58 !| LISTIN |-->| IF YES, PRINTS INFORMATION
59 !| NFIC |-->| LOGICAL UNIT OF FILE
60 !| Q |<--| VARIABLE READ AND INTERPOLATED
61 !| FOUND |<--| IF FALSE: VARIABLE NOT FOUND
62 !| WHAT |-->| VARIABLE TO LOOK FOR IN 9 CHARACTERS
63 !| MARDAT |-->| REFERENCE DATE OF THE SIMUMATION
64 !| MARTIM |-->| REFERENCE TIME OF THE SIMULATION
65 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66 !
68  & il1_rff,il2_rff,tl1_rff,
69  & tl2_rff,nvalue_rff,
70  & lastwhat_rff,lastat_rff,
71  & nlig_rff,maxvalue_rff,deja_rff,
72  & liq_ref_date, liq_tel_offset
73  USE bief, ONLY : date_mjd2sec
75  IMPLICIT NONE
76 !
77 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 !
79  CHARACTER(LEN=9), INTENT(IN) :: WHAT
80  DOUBLE PRECISION, INTENT(IN) :: AT
81  DOUBLE PRECISION, INTENT(INOUT) :: Q
82  INTEGER , INTENT(IN) :: NFIC
83  LOGICAL , INTENT(IN) :: LISTIN
84  LOGICAL , INTENT(OUT) :: FOUND
85 !
86 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 !
88 !
89 ! MAXIMUM NUMBER OF CHARACTERS PER LIGN (MAY BE CHANGED)
90 !
91  INTEGER, PARAMETER :: SIZELIGN = 3000
92 !
93  INTEGER IVALUE,ILIG,OK,J,IWHAT,IDEB,IFIN
94  DOUBLE PRECISION TETA
95  DOUBLE PRECISION, PARAMETER :: TOL = 1.d-3
96 !
97  CHARACTER(LEN=SIZELIGN) :: LIGNE
98 
99  DOUBLE PRECISION OFFSET
100  DOUBLE PRECISION AT_DATE
101 !
102  INTRINSIC abs,char
103 !
104 !-----------------------------------------------------------------------
105 !
106 ! 1) (AT FIRST CALL)
107 ! READS THE LIQUID BOUNDARY FILE
108 ! INITIALISES CURRENT LINES AND INTERVAL OF TIME_RFF
109 !
110  IF(.NOT.deja_rff) THEN
111  rewind(nfic)
112  liq_ref_date = 0
113 ! SKIPS COMMENTS
114 1 READ(nfic,fmt='(A)',err=10) ligne
115  GO TO 20
116 10 CONTINUE
117  WRITE(lu,*) 'READ ERROR IN THE'
118  WRITE(lu,*) 'LIQUID BOUNDARIES FILE'
119  WRITE(lu,*) 'PROBABLY A PROBLEM OF FORMAT'
120  WRITE(lu,*) 'ANY WINDOWS CARRIAGE RETURNS ON UNIX OR LINUX'
121  WRITE(lu,*) 'GUILTY LINE:'
122  WRITE(lu,*) ligne
123  CALL plante(1)
124  stop
125 20 CONTINUE
126  IF(ligne(1:8).EQ.'#REFDATE') THEN
127  CALL read_ref_date(ligne, liq_ref_date)
128  IF (tel_offset.LE.1.d-16) THEN
129  WRITE(lu,*) 'REFERENCE DATE IN LIQ BND FILE'
130  WRITE(lu,*) 'MISSING ORIGINAL DATE OF TIME IN STEERING FILE'
131  CALL plante(1)
132  stop
133  ENDIF
134  ENDIF
135  IF(ligne(1:1).EQ.'#') GO TO 1
136 !
137 ! FINDS OUT WHAT AND HOW MANY VALUES ARE GIVEN IN THE FILE
138 !
139  nvalue_rff = -1
140  ifin = 1
141 40 ideb = ifin
142 !
143 ! IDENTIFIES FIRST CHARACTER OF NAME
144 !
145 ! SKIPPING SPACES AND TABS
146 50 IF((ligne(ideb:ideb).EQ.' '.OR.ligne(ideb:ideb).EQ.char(9))
147  & .AND.ideb.LT.sizelign) THEN
148  ideb=ideb+1
149  GO TO 50
150  ENDIF
151 ! IDENTIFIES LAST CHARACTER OF NAME
152  ifin = ideb
153 60 IF(ligne(ifin:ifin).NE.' '.AND.ligne(ifin:ifin).NE.char(9)
154  & .AND.ifin.LT.sizelign) THEN
155  ifin=ifin+1
156  GO TO 60
157  ENDIF
158 !
159  IF(ideb.EQ.ifin) GO TO 4
160 !
161  nvalue_rff = nvalue_rff + 1
162  IF(nvalue_rff.EQ.0) THEN
163  IF(ligne(ideb:ifin-1).NE.'T') THEN
164  WRITE(lu,*) 'FIRST VALUE MUST BE TIME_RFF, DENOTED T'
165  WRITE(lu,*) 'IN FILE OF LIQUID BOUNDARIES'
166  WRITE(lu,*) 'OTHER POSSIBLE CAUSE:'
167  WRITE(lu,*) 'THERE ARE TABS IN THE FILE'
168  WRITE(lu,*) 'CHANGE TABS INTO SPACES'
169  CALL plante(1)
170  stop
171  ENDIF
172  ELSEIF(nvalue_rff.LE.maxvalue_rff) THEN
173  choix_rff(nvalue_rff)=' '
174  choix_rff(nvalue_rff)(1:ifin-ideb+1)=ligne(ideb:ifin-1)
175  ELSE
176  WRITE(lu,*) 'INCREASE MAXVALUE_RFF IN READ_FIC_FRLIQ'
177  CALL plante(1)
178  stop
179  ENDIF
180  IF(ifin.LT.sizelign) GO TO 40
181 !
182 ! SKIPS THE LINE WITH UNITS OR NAMES
183 4 READ(nfic,fmt='(A)',err=10) ligne
184  IF(ligne(1:1).EQ.'#') GO TO 4
185 !
186 ! COUNTS LINES OF DATA
187  nlig_rff = 0
188 998 READ(nfic,*,end=1000,err=999) ligne
189  IF(ligne(1:1).NE.'#') nlig_rff=nlig_rff+1
190  GO TO 998
191 999 CONTINUE
192  WRITE(lu,*) 'READING ERROR ON THE LIQUID BOUNDARIES FILE'
193  WRITE(lu,*) 'AT LINE OF DATA : ',nlig_rff
194  WRITE(lu,*) '(COMMENTS EXCLUDED)'
195  CALL plante(1)
196  stop
197 1000 CONTINUE
198 !
199 ! DYNAMICALLY ALLOCATES TIME_RFF AND INFIC_RFF
200 !
201  ALLOCATE(time_rff(nlig_rff),stat=ok)
202  IF(ok.NE.0) WRITE(lu,*) 'MEMORY ALLOCATION ERROR FOR TIME_RFF'
203  ALLOCATE(infic_rff(nvalue_rff,nlig_rff),stat=ok)
204  IF(ok.NE.0) WRITE(lu,*) 'MEMORY ALLOCATION ERROR FOR INFIC_RFF'
205 !
206 ! FINAL READ OF TIME_RFF AND INFIC_RFF
207 !
208  rewind(nfic)
209 ! SKIPS COMMENTS AND FIRST TWO MANDATORY LINES
210 2 READ(nfic,fmt='(A)') ligne
211  IF(ligne(1:1).EQ.'#') GO TO 2
212  READ(nfic,fmt='(A)') ligne
213 !
214  DO ilig=1,nlig_rff
215 3 READ(nfic,fmt='(A)') ligne
216  IF(ligne(1:1).EQ.'#') THEN
217  GO TO 3
218  ELSE
219  backspace(nfic)
220 ! COMPILERS SKIP SPACES AS WELL AS TABS
221  READ(nfic,*) time_rff(ilig),
222  & (infic_rff(ivalue,ilig),ivalue=1,nvalue_rff)
223  ENDIF
224  ENDDO
225 !
226  CLOSE(nfic)
227  deja_rff = .true.
228 !
229  ! If reference date is available adding offset (from date in
230  ! file)
231  IF (any(liq_ref_date.NE.0)) THEN
232  offset = date_mjd2sec(liq_ref_date(1:3), liq_ref_date(4:6))
233  time_rff = time_rff + offset
234  liq_tel_offset = tel_offset
235  WRITE(lu,*) 'USING REFERENCE DATE FOR LIQUID BOUNDARIES:'
236  WRITE(lu,666) liq_ref_date
237 666 FORMAT(5x,1i4,'-',1i0.2,'-',1i0.2,' ',
238  & 1i0.2,':',1i0.2,':',1i0.2)
239  ELSE
240  liq_tel_offset = 0.d0
241  ENDIF
242  il1_rff = 1
243  il2_rff = 2
244  tl1_rff = time_rff(1)
245  tl2_rff = time_rff(2)
246 !
247  lastwhat_rff = ' '
248  lastat_rff = 0.d0
249 !
250  WRITE(lu,*) 'THE LIQUID BOUNDARIES FILE CONTAINS'
251  WRITE(lu,*) nlig_rff,' LINES WITH:'
252  WRITE(lu,*) (choix_rff(ivalue),ivalue=1,nvalue_rff)
253 !
254  ENDIF
255 !
256 !-----------------------------------------------------------------------
257 !
258 ! 2) INTERPOLATES THE DATA TO GET THE CORRECT TIME_RFF
259 !
260 ! 2.A) FINDS THE ADDRESS IN THE ARRAY OF STORED DATA
261 !
262 ! 2.B) INTERPOLATES DATA FROM THE ARRAY INFIC_RFF
263 !
264 !-----------------------------------------------------------------------
265 !
266 !
267  ! using at_date in case we have an offset from the liq reference
268  ! date
269  at_date = at + liq_tel_offset
270 ! WHICH VARIABLE ?
271  iwhat = 0
272  DO j=1,nvalue_rff
273  IF(what.EQ.choix_rff(j)) iwhat=j
274  ENDDO
275  IF(iwhat.EQ.0) THEN
276  found=.false.
277  RETURN
278  ENDIF
279 !
280 70 IF(at_date.GE.tl1_rff-tol.AND.at_date.LE.tl2_rff+tol) THEN
281  IF(tl2_rff.GT.tl1_rff) THEN
282  teta = (at_date-tl1_rff)/(tl2_rff-tl1_rff)
283  ELSE
284  WRITE(lu,*) 'ERROR, TIME ',tl2_rff
285  WRITE(lu,*) 'IS LESS OR EQUAL TO THE TIME'
286  WRITE(lu,*) 'OF THE PREVIOUS LINE: ',tl1_rff
287  WRITE(lu,*) 'IN THE FILE OF LIQUID BOUNDARIES'
288  CALL plante(1)
289  stop
290  ENDIF
291  ELSE
292  DO j=1,nlig_rff-1
293  IF(at_date.GE.time_rff(j)-tol.AND.
294  & at_date.LE.time_rff(j+1)+tol) THEN
295  tl1_rff=time_rff(j)
296  tl2_rff=time_rff(j+1)
297  il1_rff=j
298  il2_rff=j+1
299  GO TO 70
300  ENDIF
301  ENDDO
302  il1_rff=il2_rff
303  il2_rff=il2_rff+1
304  IF(il2_rff.GT.nlig_rff) THEN
305  WRITE(lu,*) 'T=',at_date,' OUT OF RANGE'
306  WRITE(lu,*) 'OF THE FILE OF LIQUID BOUNDARIES'
307  WRITE(lu,*) 'NUMBER OF LINES : ',nlig_rff
308  WRITE(lu,*) 'SOME COMPILERS REQUIRE AN'
309  WRITE(lu,*) 'EMPTY LINE AT THE END OF THE FILE'
310  CALL plante(1)
311  stop
312  ENDIF
313  tl1_rff=time_rff(il1_rff)
314  tl2_rff=time_rff(il2_rff)
315  GO TO 70
316  ENDIF
317 !
318  q = (1.d0-teta)*infic_rff(iwhat,il1_rff)
319  & + teta *infic_rff(iwhat,il2_rff)
320 !
321  found=.true.
322 !
323 ! PRINTS ONLY IF NEW TIME_RFF OR NEW VALUE IS ASKED
324 !
325  IF(listin) THEN
326  IF(abs(at_date-lastat_rff).GT.tol.OR.lastwhat_rff.NE.what) THEN
327  WRITE(lu,*) 'LIQUID BOUNDARY: ',what,'=',q
328  ENDIF
329  ENDIF
330  lastat_rff=at_date
331  lastwhat_rff=what
332 !
333 !-----------------------------------------------------------------------
334 !
335  RETURN
336  END
double precision, dimension(:), allocatable time_rff
double precision, dimension(:,:), allocatable infic_rff
character(len=9), dimension(maxvalue_rff) choix_rff
double precision tel_offset
subroutine read_fic_frliq(Q, WHAT, AT, NFIC, LISTIN, FOUND)
Definition: read_fic_frliq.f:7
double precision function date_mjd2sec(DATE, TIME)
Definition: date_mjd2sec.f:7
double precision function q(I)
Definition: q.f:7
Definition: bief.f:3