source: flexpart.git/src/FLEXPART.f90

bugfixes+enhancements
Last change on this file was 8ad70c7, checked in by Pirmin Kaufmann <pirmin.kaufmann@…>, 17 months ago

Bumped bugfix version.

  • Property mode set to 100644
File size: 14.2 KB
Line 
1! SPDX-FileCopyrightText: FLEXPART 1998-2019, see flexpart_license.txt
2! SPDX-License-Identifier: GPL-3.0-or-later
3
4program flexpart
5
6  !*****************************************************************************
7  !                                                                            *
8  !     This is the Lagrangian Particle Dispersion Model FLEXPART.             *
9  !     The main program manages the reading of model run specifications, etc. *
10  !     All actual computing is done within subroutine timemanager.            *
11  !                                                                            *
12  !     Author: A. Stohl                                                       *
13  !                                                                            *
14  !     18 May 1996                                                            *
15  !                                                                            *
16  !*****************************************************************************
17  ! Changes:                                                                   *
18  !   Unified ECMWF and GFS builds                                             *
19  !   Marian Harustak, 12.5.2017                                               *
20  !     - Added detection of metdata format using gributils routines           *
21  !     - Distinguished calls to ecmwf/gfs gridcheck versions based on         *
22  !       detected metdata format                                              *
23  !     - Passed metdata format down to timemanager                            *
24  !*****************************************************************************
25  !                                                                            *
26  ! Variables:                                                                 *
27  !                                                                            *
28  ! Constants:                                                                 *
29  !                                                                            *
30  !*****************************************************************************
31
32  use point_mod
33  use par_mod
34  use com_mod
35  use conv_mod
36
37  use random_mod, only: gasdev1
38  use class_gribfile
39
40#ifdef USE_NCF
41  use netcdf_output_mod, only: writeheader_netcdf
42#endif
43
44  implicit none
45
46  integer :: i, j, ix, jy, inest, iopt
47  integer :: idummy = -320
48  character(len=256) :: inline_options  !pathfile, flexversion, arg2
49  integer :: metdata_format = GRIBFILE_CENTRE_UNKNOWN
50  integer :: detectformat
51
52 
53  ! Generate a large number of random numbers
54  !******************************************
55
56  do i=1,maxrand-1,2
57    call gasdev1(idummy,rannumb(i),rannumb(i+1))
58  end do
59  call gasdev1(idummy,rannumb(maxrand),rannumb(maxrand-1))
60
61
62  ! FLEXPART version string
63  flexversion_major = '10' ! Major version number, also used for species file names
64  flexversion='Version '//trim(flexversion_major)//'.4.2 (2022-11-24)'
65  verbosity=0
66
67  ! Read the pathnames where input/output files are stored
68  !*******************************************************
69
70  inline_options='none'
71  select case (command_argument_count())  ! Portable standard Fortran intrinsic procedure
72  case (2)
73    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
74    pathfile=arg1
75    call get_command_argument(2,arg2)     ! Portable standard Fortran intrinsic procedure
76    inline_options=arg2
77  case (1)
78    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
79    pathfile=arg1
80    if (arg1(1:1).eq.'-') then
81      write(pathfile,'(a11)') './pathnames'
82      inline_options=arg1
83    endif
84  case (0)
85    write(pathfile,'(a11)') './pathnames'
86  end select
87 
88  ! Print the GPL License statement
89  !*******************************************************
90  print*,'Welcome to FLEXPART ', trim(flexversion)
91  print*,'FLEXPART is free software released under the GNU General Public License.'
92
93
94  ! Ingest inline options
95  !*******************************************************
96  if (inline_options(1:1).eq.'-') then
97    print*,'inline_options:',inline_options
98    !verbose mode
99    iopt=index(inline_options,'v')
100    if (iopt.gt.0) then
101      verbosity=1
102      !print*, iopt, inline_options(iopt+1:iopt+1)
103      if  (trim(inline_options(iopt+1:iopt+1)).eq.'2') then
104        print*, 'Verbose mode 2: display more detailed information during run'
105        verbosity=2
106      endif
107    endif
108    !debug mode
109    iopt=index(inline_options,'d')
110    if (iopt.gt.0) then
111      debug_mode=.true.
112    endif
113    if (trim(inline_options).eq.'-i') then
114      print*, 'Info mode: provide detailed run specific information and stop'
115      verbosity=1
116      info_flag=1
117    endif
118    if (trim(inline_options).eq.'-i2') then
119      print*, 'Info mode: provide more detailed run specific information and stop'
120      verbosity=2
121      info_flag=1
122    endif
123  endif
124           
125  if (verbosity.gt.0) then
126    print*, 'nxmax=',nxmax
127    print*, 'nymax=',nymax
128    print*, 'nzmax=',nzmax
129    print*,'nxshift=',nxshift
130  endif
131 
132  if (verbosity.gt.0) then
133    write(*,*) 'call readpaths'
134  endif
135  call readpaths
136 
137  if (verbosity.gt.1) then !show clock info
138     !print*,'length(4)',length(4)
139     !count=0,count_rate=1000
140     call system_clock(count_clock0, count_rate, count_max)
141     !WRITE(*,*) 'SYSTEM_CLOCK',count, count_rate, count_max
142     !WRITE(*,*) 'SYSTEM_CLOCK, count_clock0', count_clock0
143     !WRITE(*,*) 'SYSTEM_CLOCK, count_rate', count_rate
144     !WRITE(*,*) 'SYSTEM_CLOCK, count_max', count_max
145  endif
146
147  ! Read the user specifications for the current model run
148  !*******************************************************
149
150  if (verbosity.gt.0) then
151    write(*,*) 'call readcommand'
152  endif
153  call readcommand
154  if (verbosity.gt.0) then
155    write(*,*) '    ldirect=', ldirect
156    write(*,*) '    ibdate,ibtime=',ibdate,ibtime
157    write(*,*) '    iedate,ietime=', iedate,ietime
158    if (verbosity.gt.1) then   
159      CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
160      write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
161    endif
162  endif
163
164  ! Initialize arrays in com_mod
165  !*****************************
166  call com_mod_allocate_part(maxpart)
167
168
169  ! Read the age classes to be used
170  !********************************
171  if (verbosity.gt.0) then
172    write(*,*) 'call readageclasses'
173  endif
174  call readageclasses
175
176  if (verbosity.gt.1) then   
177    CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
178    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
179  endif     
180
181  ! Read, which wind fields are available within the modelling period
182  !******************************************************************
183
184  if (verbosity.gt.0) then
185    write(*,*) 'call readavailable'
186  endif 
187  call readavailable
188
189  ! Detect metdata format
190  !**********************
191  if (verbosity.gt.0) then
192    write(*,*) 'call detectformat'
193  endif
194
195  metdata_format = detectformat()
196
197  if (metdata_format.eq.GRIBFILE_CENTRE_ECMWF) then
198    print *,'ECMWF metdata detected'
199  elseif (metdata_format.eq.GRIBFILE_CENTRE_NCEP) then
200    print *,'NCEP metdata detected'
201  else
202    print *,'Unknown metdata format'
203    stop
204  endif
205
206
207
208  ! If nested wind fields are used, allocate arrays
209  !************************************************
210
211  if (verbosity.gt.0) then
212    write(*,*) 'call com_mod_allocate_nests'
213  endif
214  call com_mod_allocate_nests
215
216  ! Read the model grid specifications,
217  ! both for the mother domain and eventual nests
218  !**********************************************
219
220  if (verbosity.gt.0) then
221    write(*,*) 'call gridcheck'
222  endif
223
224  if (metdata_format.eq.GRIBFILE_CENTRE_ECMWF) then
225    call gridcheck_ecmwf
226  else
227    call gridcheck_gfs
228  end if
229
230  if (verbosity.gt.1) then   
231    CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
232    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
233  endif     
234
235  if (verbosity.gt.0) then
236    write(*,*) 'call gridcheck_nests'
237  endif 
238  call gridcheck_nests
239
240  ! Read the output grid specifications
241  !************************************
242
243  if (verbosity.gt.0) then
244    write(*,*) 'call readoutgrid'
245  endif
246
247  call readoutgrid
248
249  if (nested_output.eq.1) then
250    call readoutgrid_nest
251    if (verbosity.gt.0) then
252      write(*,*) '# readoutgrid_nest'
253    endif
254  endif
255
256  ! Read the receptor points for which extra concentrations are to be calculated
257  !*****************************************************************************
258
259  if (verbosity.eq.1) then
260    print*,'call readreceptors'
261  endif
262  call readreceptors
263
264  ! Read the physico-chemical species property table
265  !*************************************************
266  !SEC: now only needed SPECIES are read in readreleases.f
267  !call readspecies
268
269  ! Read the landuse inventory
270  !***************************
271
272  if (verbosity.gt.0) then
273    print*,'call readlanduse'
274  endif
275  call readlanduse
276
277  ! Assign fractional cover of landuse classes to each ECMWF grid point
278  !********************************************************************
279
280  if (verbosity.gt.0) then
281    print*,'call assignland'
282  endif
283  call assignland
284
285  ! Read the coordinates of the release locations
286  !**********************************************
287
288  if (verbosity.gt.0) then
289    print*,'call readreleases'
290  endif
291  call readreleases
292
293  ! Read and compute surface resistances to dry deposition of gases
294  !****************************************************************
295
296  if (verbosity.gt.0) then
297    print*,'call readdepo'
298  endif
299  call readdepo
300
301  ! Convert the release point coordinates from geografical to grid coordinates
302  !***************************************************************************
303
304  call coordtrafo 
305  if (verbosity.gt.0) then
306    print*,'call coordtrafo'
307  endif
308
309  ! Initialize all particles to non-existent
310  !*****************************************
311
312  if (verbosity.gt.0) then
313    print*,'Initialize all particles to non-existent'
314  endif
315  do j=1,maxpart
316    itra1(j)=-999999999
317  end do
318
319  ! For continuation of previous run, read in particle positions
320  !*************************************************************
321
322  if (ipin.eq.1) then
323    if (verbosity.gt.0) then
324      print*,'call readpartpositions'
325    endif
326    call readpartpositions
327  else
328    if (verbosity.gt.0) then
329      print*,'numpart=0, numparticlecount=0'
330    endif
331    numpart=0
332    numparticlecount=0
333  endif
334
335  ! Calculate volume, surface area, etc., of all output grid cells
336  ! Allocate fluxes and OHfield if necessary
337  !***************************************************************
338
339  if (verbosity.gt.0) then
340    print*,'call outgrid_init'
341  endif
342  call outgrid_init
343  if (nested_output.eq.1) call outgrid_init_nest
344
345  ! Read the OH field
346  !******************
347
348  if (OHREA.eqv..TRUE.) then
349    if (verbosity.gt.0) then
350      print*,'call readOHfield'
351    endif
352    call readOHfield
353  endif
354
355  ! Write basic information on the simulation to a file "header"
356  ! and open files that are to be kept open throughout the simulation
357  !******************************************************************
358
359#ifdef USE_NCF
360  if (lnetcdfout.eq.1) then
361    call writeheader_netcdf(lnest=.false.)
362  else
363    call writeheader
364  end if
365
366  if (nested_output.eq.1) then
367    if (lnetcdfout.eq.1) then
368      call writeheader_netcdf(lnest=.true.)
369    else
370      call writeheader_nest
371    endif
372  endif
373#endif
374
375  if (verbosity.gt.0) then
376    print*,'call writeheader'
377  endif
378
379  call writeheader
380  ! FLEXPART 9.2 ticket ?? write header in ASCII format
381  call writeheader_txt
382  !if (nested_output.eq.1) call writeheader_nest
383  if (nested_output.eq.1.and.surf_only.ne.1) call writeheader_nest
384  if (nested_output.eq.1.and.surf_only.eq.1) call writeheader_nest_surf
385  if (nested_output.ne.1.and.surf_only.eq.1) call writeheader_surf
386
387  !open(unitdates,file=path(2)(1:length(2))//'dates')
388
389  if (verbosity.gt.0) then
390    print*,'call openreceptors'
391  endif
392  call openreceptors
393  if ((iout.eq.4).or.(iout.eq.5)) call openouttraj
394
395  ! Releases can only start and end at discrete times (multiples of lsynctime)
396  !***************************************************************************
397
398  if (verbosity.gt.0) then
399    print*,'discretize release times'
400  endif
401  do i=1,numpoint
402    ireleasestart(i)=nint(real(ireleasestart(i))/real(lsynctime))*lsynctime
403    ireleaseend(i)=nint(real(ireleaseend(i))/real(lsynctime))*lsynctime
404  end do
405
406  ! Initialize cloud-base mass fluxes for the convection scheme
407  !************************************************************
408
409  if (verbosity.gt.0) then
410    print*,'Initialize cloud-base mass fluxes for the convection scheme'
411  endif
412
413  do jy=0,nymin1
414    do ix=0,nxmin1
415      cbaseflux(ix,jy)=0.
416    end do
417  end do
418  do inest=1,numbnests
419    do jy=0,nyn(inest)-1
420      do ix=0,nxn(inest)-1
421        cbasefluxn(ix,jy,inest)=0.
422      end do
423    end do
424  end do
425
426  ! Inform whether output kernel is used or not
427  !*********************************************
428  if (lroot) then
429    if (.not.lusekerneloutput) then
430      write(*,*) "Concentrations are calculated without using kernel"
431    else
432      write(*,*) "Concentrations are calculated using kernel"
433    end if
434  end if
435
436
437  ! Calculate particle trajectories
438  !********************************
439
440  if (verbosity.gt.0) then
441     if (verbosity.gt.1) then   
442       CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
443       write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
444     endif
445     if (info_flag.eq.1) then
446       print*, 'info only mode (stop)'   
447       stop
448     endif
449     print*,'call timemanager'
450  endif
451
452  if (verbosity.gt.0) write (*,*) 'timemanager> call wetdepo'
453  call timemanager(metdata_format)
454 
455
456  if (verbosity.gt.0) then
457! NIK 16.02.2005
458    do i=1,nspec
459      if (tot_inc_count(i).gt.0) then
460         write(*,*) '**********************************************'
461         write(*,*) 'Scavenging statistics for species ', species(i), ':'
462         write(*,*) 'Total number of occurences of below-cloud scavenging', &
463           & tot_blc_count(i)
464         write(*,*) 'Total number of occurences of in-cloud    scavenging', &
465           & tot_inc_count(i)
466         write(*,*) '**********************************************'
467      endif
468    end do
469  endif
470 
471  write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLE&
472       &XPART MODEL RUN!'
473
474end program flexpart
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG