FLEXPART.f90 12.9 KB
Newer Older
Matthias Langer's avatar
 
Matthias Langer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
!**********************************************************************
! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
!                                                                     *
! This file is part of FLEXPART.                                      *
!                                                                     *
! FLEXPART is free software: you can redistribute it and/or modify    *
! it under the terms of the GNU General Public License as published by*
! the Free Software Foundation, either version 3 of the License, or   *
! (at your option) any later version.                                 *
!                                                                     *
! FLEXPART is distributed in the hope that it will be useful,         *
! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
! GNU General Public License for more details.                        *
!                                                                     *
! You should have received a copy of the GNU General Public License   *
! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
!**********************************************************************

program flexpart

  !*****************************************************************************
  !                                                                            *
  !     This is the Lagrangian Particle Dispersion Model FLEXPART.             *
  !     The main program manages the reading of model run specifications, etc. *
  !     All actual computing is done within subroutine timemanager.            *
  !                                                                            *
  !     Author: A. Stohl                                                       *
  !                                                                            *
  !     18 May 1996                                                            *
  !                                                                            *
  !*****************************************************************************
  !                                                                            *
  ! Variables:                                                                 *
  !                                                                            *
  ! Constants:                                                                 *
  !                                                                            *
  !*****************************************************************************

  use point_mod
  use par_mod
  use com_mod
  use conv_mod
46
47
  use netcdf_output_mod, only: writeheader_netcdf
  use random_mod, only: gasdev1
Matthias Langer's avatar
 
Matthias Langer committed
48
49
50
51
52

  implicit none

  integer :: i,j,ix,jy,inest
  integer :: idummy = -320
53
  character(len=256) :: inline_options  !pathfile, flexversion, arg2
54
55
56
57
58
59
60


  ! Initialize arrays in com_mod
  !*****************************
  call com_mod_allocate(maxpart)


Matthias Langer's avatar
 
Matthias Langer committed
61
62
63
64
65
66
67
68
69

  ! Generate a large number of random numbers
  !******************************************

  do i=1,maxrand-1,2
    call gasdev1(idummy,rannumb(i),rannumb(i+1))
  end do
  call gasdev1(idummy,rannumb(maxrand),rannumb(maxrand-1))

70
  ! FLEXPART version string
71
72
73
  flexversion='Version 10.0pre  (2015-03-01)'
  verbosity=0

74
75
76
  ! Read the pathnames where input/output files are stored
  !*******************************************************

77
  inline_options='none'
78
  select case (iargc())
79
  case (2)
80
81
82
83
    call getarg(1,arg1)
    pathfile=arg1
    call getarg(2,arg2)
    inline_options=arg2
84
  case (1)
85
86
87
    call getarg(1,arg1)
    pathfile=arg1
    if (arg1(1:1).eq.'-') then
88
89
      write(pathfile,'(a11)') './pathnames'
      inline_options=arg1 
90
    endif
91
  case (0)
92
93
94
    write(pathfile,'(a11)') './pathnames'
  end select
  
Matthias Langer's avatar
 
Matthias Langer committed
95
96
  ! Print the GPL License statement
  !*******************************************************
97
  print*,'Welcome to FLEXPART ', trim(flexversion)
98
  print*,'FLEXPART is free software released under the GNU General Public License.'
99
 
100
101
102
  if (inline_options(1:1).eq.'-') then
    if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
       print*, 'Verbose mode 1: display detailed information during run'
103
       verbosity=1
104
105
106
    endif
    if (trim(inline_options).eq.'-v2') then
       print*, 'Verbose mode 2: display more detailed information during run'
107
108
       verbosity=2
    endif
109
110
    if (trim(inline_options).eq.'-i') then
       print*, 'Info mode: provide detailed run specific information and stop'
111
112
113
       verbosity=1
       info_flag=1
    endif
114
115
116
117
    if (trim(inline_options).eq.'-i2') then
       print*, 'Info mode: provide more detailed run specific information and stop'
       verbosity=2
       info_flag=1
118
119
120
    endif
  endif
           
121
  if (verbosity.gt.0) then
122
    write(*,*) 'call readpaths'
123
124
125
  endif 
  call readpaths(pathfile)
 
126
127
  if (verbosity.gt.1) then !show clock info 
     !print*,'length(4)',length(4)
128
     !count=0,count_rate=1000
129
     CALL SYSTEM_CLOCK(count_clock0, count_rate, count_max)
130
131
132
133
     !WRITE(*,*) 'SYSTEM_CLOCK',count, count_rate, count_max
     !WRITE(*,*) 'SYSTEM_CLOCK, count_clock0', count_clock0
     !WRITE(*,*) 'SYSTEM_CLOCK, count_rate', count_rate
     !WRITE(*,*) 'SYSTEM_CLOCK, count_max', count_max
134
  endif
Matthias Langer's avatar
 
Matthias Langer committed
135
136
137
138

  ! Read the user specifications for the current model run
  !*******************************************************

139
  if (verbosity.gt.0) then
140
    write(*,*) 'call readcommand'
141
  endif
Matthias Langer's avatar
 
Matthias Langer committed
142
  call readcommand
143
  if (verbosity.gt.0) then
144
145
    write(*,*) '    ldirect=', ldirect
    write(*,*) '    ibdate,ibtime=',ibdate,ibtime
146
    write(*,*) '    iedate,ietime=', iedate,ietime
147
    if (verbosity.gt.1) then   
148
149
150
      CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
      write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
    endif     
151
  endif
Matthias Langer's avatar
 
Matthias Langer committed
152
153
154

  ! Read the age classes to be used
  !********************************
155
  if (verbosity.gt.0) then
156
    write(*,*) 'call readageclasses'
157
  endif
Matthias Langer's avatar
 
Matthias Langer committed
158
159
  call readageclasses

160
  if (verbosity.gt.1) then   
161
162
    CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
163
  endif     
Matthias Langer's avatar
 
Matthias Langer committed
164
165
166
167

  ! Read, which wind fields are available within the modelling period
  !******************************************************************

168
  if (verbosity.gt.0) then
169
    write(*,*) 'call readavailable'
170
  endif  
Matthias Langer's avatar
 
Matthias Langer committed
171
172
173
174
175
  call readavailable

  ! Read the model grid specifications,
  ! both for the mother domain and eventual nests
  !**********************************************
176
177
 
  if (verbosity.gt.0) then
178
     write(*,*) 'call gridcheck'
179
  endif
180

Matthias Langer's avatar
 
Matthias Langer committed
181
  call gridcheck
182

183
  if (verbosity.gt.1) then   
184
185
    CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
186
187
188
  endif      

  if (verbosity.gt.0) then
189
    write(*,*) 'call gridcheck_nests'
190
  endif  
Matthias Langer's avatar
 
Matthias Langer committed
191
192
193
194
195
  call gridcheck_nests

  ! Read the output grid specifications
  !************************************

196
  if (verbosity.gt.0) then
197
    write(*,*) 'call readoutgrid'
198
199
  endif

Matthias Langer's avatar
 
Matthias Langer committed
200
201
  call readoutgrid

202
  if (nested_output.eq.1) then
203
    call readoutgrid_nest
204
    if (verbosity.gt.0) then
205
      write(*,*) '# readoutgrid_nest'
206
207
    endif
  endif
Matthias Langer's avatar
 
Matthias Langer committed
208
209
210
211

  ! Read the receptor points for which extra concentrations are to be calculated
  !*****************************************************************************

212
  if (verbosity.eq.1) then
213
     print*,'call readreceptors'
214
  endif
Matthias Langer's avatar
 
Matthias Langer committed
215
216
217
218
219
220
221
222
223
224
225
  call readreceptors

  ! Read the physico-chemical species property table
  !*************************************************
  !SEC: now only needed SPECIES are read in readreleases.f
  !call readspecies


  ! Read the landuse inventory
  !***************************

226
  if (verbosity.gt.0) then
227
    print*,'call readlanduse'
228
  endif
Matthias Langer's avatar
 
Matthias Langer committed
229
230
231
232
233
  call readlanduse

  ! Assign fractional cover of landuse classes to each ECMWF grid point
  !********************************************************************

234
  if (verbosity.gt.0) then
235
    print*,'call assignland'
236
  endif
Matthias Langer's avatar
 
Matthias Langer committed
237
238
239
240
241
  call assignland

  ! Read the coordinates of the release locations
  !**********************************************

242
  if (verbosity.gt.0) then
243
    print*,'call readreleases'
244
  endif
Matthias Langer's avatar
 
Matthias Langer committed
245
246
247
248
249
  call readreleases

  ! Read and compute surface resistances to dry deposition of gases
  !****************************************************************

250
  if (verbosity.gt.0) then
251
    print*,'call readdepo'
252
  endif
Matthias Langer's avatar
 
Matthias Langer committed
253
254
255
256
257
  call readdepo

  ! Convert the release point coordinates from geografical to grid coordinates
  !***************************************************************************

258
259
  call coordtrafo  
  if (verbosity.gt.0) then
260
    print*,'call coordtrafo'
261
  endif
Matthias Langer's avatar
 
Matthias Langer committed
262
263
264
265

  ! Initialize all particles to non-existent
  !*****************************************

266
  if (verbosity.gt.0) then
267
    print*,'Initialize all particles to non-existent'
268
  endif
Matthias Langer's avatar
 
Matthias Langer committed
269
270
271
272
273
274
275
276
  do j=1,maxpart
    itra1(j)=-999999999
  end do

  ! For continuation of previous run, read in particle positions
  !*************************************************************

  if (ipin.eq.1) then
277
    if (verbosity.gt.0) then
278
      print*,'call readpartpositions'
279
    endif
Matthias Langer's avatar
 
Matthias Langer committed
280
281
    call readpartpositions
  else
282
    if (verbosity.gt.0) then
283
      print*,'numpart=0, numparticlecount=0'
284
    endif    
Matthias Langer's avatar
 
Matthias Langer committed
285
286
287
288
289
290
291
292
    numpart=0
    numparticlecount=0
  endif

  ! Calculate volume, surface area, etc., of all output grid cells
  ! Allocate fluxes and OHfield if necessary
  !***************************************************************

293
  if (verbosity.gt.0) then
294
    print*,'call outgrid_init'
295
  endif
Matthias Langer's avatar
 
Matthias Langer committed
296
297
298
299
300
301
  call outgrid_init
  if (nested_output.eq.1) call outgrid_init_nest

  ! Read the OH field
  !******************

302
303
  if (OHREA.eqv..TRUE.) then
    if (verbosity.gt.0) then
304
      print*,'call readOHfield'
305
    endif
306
    call readOHfield
307
  endif
Matthias Langer's avatar
 
Matthias Langer committed
308

309
310
311
312
313
  !! testing !!
  ! open(999,file=trim(path(1))//'OH_FIELDS/jscalar_50N.txt',action='write',status='new')
  ! open(998,file=trim(path(1))//'OH_FIELDS/jscalar_50S.txt',action='write',status='new')


Matthias Langer's avatar
 
Matthias Langer committed
314
315
316
317
  ! Write basic information on the simulation to a file "header"
  ! and open files that are to be kept open throughout the simulation
  !******************************************************************

318
319
320
321
322
323
324
325
326
327
328
329
330
331
  if (lnetcdfout.eq.1) then 
    call writeheader_netcdf(lnest=.false.)
  else 
    call writeheader
  end if

  if (nested_output.eq.1) then
    if (lnetcdfout.eq.1) then
      call writeheader_netcdf(lnest=.true.)
    else
      call writeheader_nest
    endif
  endif

332
  if (verbosity.gt.0) then
333
    print*,'call writeheader'
334
335
  endif

Matthias Langer's avatar
 
Matthias Langer committed
336
  call writeheader
337
  ! FLEXPART 9.2 ticket ?? write header in ASCII format 
338
339
340
341
342
343
344
345
346
  call writeheader_txt
  !if (nested_output.eq.1) call writeheader_nest
  if (nested_output.eq.1.and.surf_only.ne.1) call writeheader_nest
  if (nested_output.eq.1.and.surf_only.eq.1) call writeheader_nest_surf
  if (nested_output.ne.1.and.surf_only.eq.1) call writeheader_surf

  !open(unitdates,file=path(2)(1:length(2))//'dates')

  if (verbosity.gt.0) then
347
    print*,'call openreceptors'
348
  endif
Matthias Langer's avatar
 
Matthias Langer committed
349
350
351
352
353
354
  call openreceptors
  if ((iout.eq.4).or.(iout.eq.5)) call openouttraj

  ! Releases can only start and end at discrete times (multiples of lsynctime)
  !***************************************************************************

355
  if (verbosity.gt.0) then
356
    print*,'discretize release times'
357
  endif
Matthias Langer's avatar
 
Matthias Langer committed
358
  do i=1,numpoint
359
360
    ireleasestart(i)=nint(real(ireleasestart(i))/real(lsynctime))*lsynctime
    ireleaseend(i)=nint(real(ireleaseend(i))/real(lsynctime))*lsynctime
Matthias Langer's avatar
 
Matthias Langer committed
361
362
363
364
365
  end do

  ! Initialize cloud-base mass fluxes for the convection scheme
  !************************************************************

366
  if (verbosity.gt.0) then
367
    print*,'Initialize cloud-base mass fluxes for the convection scheme'
368
369
  endif

Matthias Langer's avatar
 
Matthias Langer committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  do jy=0,nymin1
    do ix=0,nxmin1
      cbaseflux(ix,jy)=0.
    end do
  end do
  do inest=1,numbnests
    do jy=0,nyn(inest)-1
      do ix=0,nxn(inest)-1
        cbasefluxn(ix,jy,inest)=0.
      end do
    end do
  end do

  ! Calculate particle trajectories
  !********************************

386
  if (verbosity.gt.0) then
387
388
389
390
391
392
393
394
395
     if (verbosity.gt.1) then   
       CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
       write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
     endif
     if (info_flag.eq.1) then
       print*, 'info only mode (stop)'    
       stop
     endif
     print*,'call timemanager'
396
397
  endif

Matthias Langer's avatar
 
Matthias Langer committed
398
399
  call timemanager

400
401
402
403
404
405
406
407
! NIK 16.02.2005 
  write(*,*) '**********************************************'
  write(*,*) 'Total number of occurences of below-cloud scavenging', tot_blc_count
  write(*,*) 'Total number of occurences of in-cloud    scavenging', tot_inc_count
  write(*,*) '**********************************************'

  write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLE&
       &XPART MODEL RUN!'
Matthias Langer's avatar
 
Matthias Langer committed
408
409

end program flexpart