source: palm/trunk/SOURCE/ls_forcing.f90 @ 1249

Last change on this file since 1249 was 1249, checked in by heinze, 10 years ago

remove call of user module, reformatting

  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1 MODULE ls_forcing_mod
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! remove call of user module
23! reformatting
24!
25! Former revisions:
26! -----------------
27! $Id: ls_forcing.f90 1249 2013-11-06 10:45:47Z heinze $
28!
29! 1241 2013-10-30 11:36:58Z heinze
30! Initial revision
31!
32! Description:
33! ------------
34! Calculates large scale forcings (geostrophic wind and subsidence velocity) as
35! well as surfaces fluxes dependend on time given in an external file (LSF_DATA).
36! Code is based in parts on DALES and UCLA-LES.
37!--------------------------------------------------------------------------------!
38
39    PRIVATE
40    PUBLIC init_ls_forcing, ls_forcing_surf, ls_forcing_vert 
41    SAVE
42
43
44 CONTAINS
45
46    SUBROUTINE init_ls_forcing
47
48       USE arrays_3d
49       USE control_parameters
50       USE cpulog
51       USE indices
52       USE interfaces
53       USE pegrid
54
55       IMPLICIT NONE
56
57       INTEGER ::  finput = 90, ierrn, k, t 
58       CHARACTER (100)::  chmess
59       CHARACTER(1) ::  hash
60       REAL ::  r_dummy, fac
61       REAL ::  highheight, highug_vert, highvg_vert, highwsubs_vert
62       REAL ::  lowheight, lowug_vert, lowvg_vert, lowwsubs_vert
63
64       ALLOCATE( p_surf(0:nlsf), pt_surf(0:nlsf), q_surf(0:nlsf),         &
65                 qsws_surf(0:nlsf), shf_surf(0:nlsf), time_vert(0:nlsf),  &
66                 time_surf(0:nlsf), ug_vert(nzb:nzt+1,0:nlsf),            &
67                 vg_vert(nzb:nzt+1,0:nlsf), wsubs_vert(nzb:nzt+1,0:nlsf) )
68
69       p_surf = 0.0; pt_surf = 0.0; q_surf = 0.0; qsws_surf = 0.0
70       shf_surf = 0.0; time_vert = 0.0; time_surf = 0.0; ug_vert = 0.0
71       vg_vert = 0.0; wsubs_vert = 0.0
72
73
74       OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', &
75              FORM='FORMATTED', IOSTAT=ierrn )
76
77       IF ( ierrn /= 0 )  THEN
78          message_string = 'file LSF_DATA does not exist'
79          CALL message( 'ls_forcing', 'PA0368', 1, 2, 0, 6, 0 )
80       ENDIF
81
82       ierrn = 0
83!
84!--    First three lines of LSF_DATA contain header
85       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
86       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
87       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
88
89       IF ( ierrn /= 0 )  THEN
90          message_string = 'errors in file LSF_DATA'
91          CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
92       ENDIF
93
94!
95!--    Surface values are read in
96       t     = 0
97       ierrn = 0
98
99       DO WHILE ( time_surf(t) < end_time )
100          t = t + 1
101          READ ( finput, *, IOSTAT = ierrn ) time_surf(t), shf_surf(t), &
102                                             qsws_surf(t), pt_surf(t),  &
103                                             q_surf(t), p_surf(t)
104
105          IF ( ierrn < 0 )  THEN
106            WRITE ( message_string, * ) 'No time dependend surface variables ',&
107                              'in&LSF_DATA for end of run found'
108
109             CALL message( 'ls_forcing', 'PA0370', 1, 2, 0, 6, 0 )
110          ENDIF
111       ENDDO
112
113
114       IF ( time_surf(1) > end_time )  THEN
115          WRITE ( message_string, * ) 'No time dependend surface variables in ',&
116                                     '&LSF_DATA for end of run found - ',  &
117                                     'lsf_surf is set to FALSE'
118          CALL message( 'ls_forcing', 'PA0371', 0, 0, 0, 6, 0 )
119          lsf_surf = .FALSE.
120       ENDIF
121
122!
123!--    Go to the end of the list with surface variables
124       DO WHILE ( ierrn == 0 )
125          READ ( finput, *, IOSTAT = ierrn ) r_dummy
126       ENDDO
127
128!
129!--    Profiles of ug, vg and w_subs are read in (large scale forcing)
130
131       t = 0
132       DO WHILE ( time_vert(t) < end_time )
133          t = t + 1
134          hash = "#"
135          ierrn = 1 ! not zero
136!
137!--       Search for the next line consisting of "# time",
138!--       from there onwards the profiles will be read
139          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
140             READ ( finput, *, IOSTAT=ierrn ) hash, time_vert(t)
141             IF ( ierrn < 0 )  THEN
142                WRITE( message_string, * ) 'No time dependend vertical profiles',&
143                                 ' in&LSF_DATA for end of run found'
144                CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
145             ENDIF
146          ENDDO
147
148          IF ( t == 1 .AND. time_vert(t) > end_time ) EXIT
149
150          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowug_vert, lowvg_vert, &
151                                           lowwsubs_vert
152          IF ( ierrn /= 0 )  THEN
153             message_string = 'errors in file LSF_DATA'
154             CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
155          ENDIF
156
157          READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, highvg_vert, &
158                                           highwsubs_vert
159     
160          IF ( ierrn /= 0 )  THEN
161             message_string = 'errors in file LSF_DATA'
162             CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
163          ENDIF
164
165
166          DO  k = nzb, nzt+1
167             IF ( highheight < zu(k) )  THEN
168                lowheight     = highheight
169                lowug_vert    = highug_vert
170                lowvg_vert    = highvg_vert
171                lowwsubs_vert = highwsubs_vert
172
173                ierrn = 0
174                READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, &
175                                                 highvg_vert, highwsubs_vert
176
177                IF ( ierrn /= 0 )  THEN
178                   message_string = 'errors in file LSF_DATA'
179                   CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
180                ENDIF
181
182             ENDIF
183
184!
185!--          Interpolation of prescribed profiles in space
186             fac = (highheight-zu(k))/(highheight - lowheight)
187
188             ug_vert(k,t)    = fac*lowug_vert    + (1-fac)*highug_vert
189             vg_vert(k,t)    = fac*lowvg_vert    + (1-fac)*highvg_vert
190             wsubs_vert(k,t) = fac*lowwsubs_vert + (1-fac)*highwsubs_vert
191
192          ENDDO
193
194       ENDDO 
195
196       IF ( time_vert(1) > end_time )  THEN
197          WRITE ( message_string, * ) 'Time dependent large scale profile ',&
198                             'forcing from&LSF_DATA sets in after end of ' ,&
199                             'simulation - lsf_vert is set to FALSE'
200          CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
201          lsf_vert = .FALSE.
202       ENDIF
203
204       CLOSE( finput )
205
206
207    END SUBROUTINE init_ls_forcing 
208
209
210    SUBROUTINE ls_forcing_surf ( time )
211
212       USE arrays_3d
213       USE control_parameters
214       USE cpulog
215       USE indices
216       USE interfaces
217       USE pegrid
218
219       IMPLICIT NONE
220
221       REAL, INTENT(in)  :: time
222       REAL :: fac
223       INTEGER :: t
224
225!
226!--    Interpolation in time of LSF_DATA at the surface
227       t = 1
228       DO WHILE ( time > time_surf(t) )
229          t = t + 1
230       ENDDO
231       IF ( time /= time_surf(t) )  THEN
232         t = t - 1
233       ENDIF
234
235       fac = ( time -time_surf(t) ) / ( time_surf(t+1) - time_surf(t) )
236
237       shf              = shf_surf(t) + fac * ( shf_surf(t+1) - shf_surf(t) )
238       qsws             = qsws_surf(t) + fac * ( qsws_surf(t+1) - qsws_surf(t) )
239       pt_surface       = pt_surf(t) + fac * ( pt_surf(t+1) - pt_surf(t) )
240       surface_pressure = p_surf(t) + fac * ( p_surf(t+1) - p_surf(t) )
241
242    END SUBROUTINE ls_forcing_surf 
243
244
245    SUBROUTINE ls_forcing_vert ( time )
246
247       USE arrays_3d
248       USE control_parameters
249       USE cpulog
250       USE indices
251       USE interfaces
252       USE pegrid
253
254       IMPLICIT NONE
255
256       REAL, INTENT(in)  :: time
257       REAL :: fac
258       INTEGER :: t
259
260!
261!--    Interpolation in time of LSF_DATA for ug, vg and w_subs
262       t = 1
263       DO WHILE ( time > time_vert(t) )
264          t = t + 1
265       ENDDO
266       IF ( time /= time_vert(t) )  THEN
267         t = t - 1
268       ENDIF
269
270       fac = ( time-time_vert(t) ) / ( time_vert(t+1)-time_vert(t) )
271
272       ug     = ug_vert(:,t) + fac * ( ug_vert(:,t+1) - ug_vert(:,t) )
273       vg     = vg_vert(:,t) + fac * ( vg_vert(:,t+1) - vg_vert(:,t) )
274
275       IF ( large_scale_subsidence )  THEN
276          w_subs = wsubs_vert(:,t) + fac * ( wsubs_vert(:,t+1) - wsubs_vert(:,t) )
277       ENDIF
278
279    END SUBROUTINE ls_forcing_vert
280
281
282 END MODULE ls_forcing_mod
Note: See TracBrowser for help on using the repository browser.