source: flexpart.git/src/FLEXPART_MPI.f90 @ fb0d416

10.4.1_peseiGFS_025bugfixes+enhancementsdevrelease-10release-10.4.1scaling-bugunivie
Last change on this file since fb0d416 was fb0d416, checked in by Espen Sollum ATMOS <eso@…>, 9 years ago

OH change suggested by Xuekun

  • Property mode set to 100644
File size: 14.3 KB
Line 
1!**********************************************************************
2! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
3! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
4! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
5!                                                                     *
6! This file is part of FLEXPART.                                      *
7!                                                                     *
8! FLEXPART is free software: you can redistribute it and/or modify    *
9! it under the terms of the GNU General Public License as published by*
10! the Free Software Foundation, either version 3 of the License, or   *
11! (at your option) any later version.                                 *
12!                                                                     *
13! FLEXPART is distributed in the hope that it will be useful,         *
14! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
15! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
16! GNU General Public License for more details.                        *
17!                                                                     *
18! You should have received a copy of the GNU General Public License   *
19! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
20!**********************************************************************
21
22program flexpart
23
24  !*****************************************************************************
25  !                                                                            *
26  !     This is the Lagrangian Particle Dispersion Model FLEXPART.             *
27  !     The main program manages the reading of model run specifications, etc. *
28  !     All actual computing is done within subroutine timemanager.            *
29  !                                                                            *
30  !     Author: A. Stohl                                                       *
31  !                                                                            *
32  !     18 May 1996                                                            *
33  !                                                                            *
34  !*****************************************************************************
35  !                                                                            *
36  ! Variables:                                                                 *
37  !                                                                            *
38  ! Constants:                                                                 *
39  !                                                                            *
40  !*****************************************************************************
41
42  use point_mod
43  use par_mod
44  use com_mod
45  use conv_mod
46  use mpi_mod
47  use netcdf_output_mod, only: writeheader_netcdf
48  use random_mod, only: gasdev1
49
50  implicit none
51
52  integer :: i,j,ix,jy,inest
53  integer :: idummy = -320
54  character(len=256) :: inline_options  !pathfile, flexversion, arg2
55
56
57! Initialize mpi
58!*********************
59  call mpif_init
60
61  if (mp_measure_time) call mpif_mtime('flexpart',0)
62
63! Initialize arrays in com_mod
64!*****************************
65  call com_mod_allocate(maxpart_mpi)
66
67  ! Generate a large number of random numbers
68  !******************************************
69
70  ! eso: Different seed for each MPI process
71  idummy=idummy+mp_seed
72
73  do i=1,maxrand-1,2
74    call gasdev1(idummy,rannumb(i),rannumb(i+1))
75  end do
76  call gasdev1(idummy,rannumb(maxrand),rannumb(maxrand-1))
77
78  ! FLEXPART version string
79  flexversion='Ver. 10.0pre MPI (2015-03-01)'
80  verbosity=0
81
82  ! Read the pathnames where input/output files are stored
83  !*******************************************************
84
85  inline_options='none'
86  select case (iargc())
87  case (2)
88    call getarg(1,arg1)
89    pathfile=arg1
90    call getarg(2,arg2)
91    inline_options=arg2
92  case (1)
93    call getarg(1,arg1)
94    pathfile=arg1
95    if (arg1(1:1).eq.'-') then
96      write(pathfile,'(a11)') './pathnames'
97      inline_options=arg1
98    endif
99  case (0)
100    write(pathfile,'(a11)') './pathnames'
101  end select
102 
103  if (lroot) then
104  ! Print the GPL License statement
105  !*******************************************************
106    print*,'Welcome to FLEXPART ', trim(flexversion)
107    print*,'FLEXPART is free software released under the GNU General Public License.'
108  endif
109 
110  if (inline_options(1:1).eq.'-') then
111    if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
112      print*, 'Verbose mode 1: display detailed information during run'
113      verbosity=1
114    endif
115    if (trim(inline_options).eq.'-v2') then
116      print*, 'Verbose mode 2: display more detailed information during run'
117      verbosity=2
118    endif
119    if (trim(inline_options).eq.'-i') then
120      print*, 'Info mode: provide detailed run specific information and stop'
121      verbosity=1
122      info_flag=1
123    endif
124    if (trim(inline_options).eq.'-i2') then
125      print*, 'Info mode: provide more detailed run specific information and stop'
126      verbosity=2
127      info_flag=1
128    endif
129  endif
130           
131  if (verbosity.gt.0) then
132    write(*,*) 'call readpaths'
133  endif
134  call readpaths(pathfile)
135 
136  if (verbosity.gt.1) then !show clock info
137     !print*,'length(4)',length(4)
138     !count=0,count_rate=1000
139    call system_clock(count_clock0, count_rate, count_max)
140     !WRITE(*,*) 'SYSTEM_CLOCK',count, count_rate, count_max
141     !WRITE(*,*) 'SYSTEM_CLOCK, count_clock0', count_clock0
142     !WRITE(*,*) 'SYSTEM_CLOCK, count_rate', count_rate
143     !WRITE(*,*) 'SYSTEM_CLOCK, count_max', count_max
144  endif
145
146  ! Read the user specifications for the current model run
147  !*******************************************************
148
149  if (verbosity.gt.0) then
150    write(*,*) 'call readcommand'
151  endif
152  call readcommand
153  if (verbosity.gt.0 .and. lroot) then
154    write(*,*) '    ldirect=', ldirect
155    write(*,*) '    ibdate,ibtime=',ibdate,ibtime
156    write(*,*) '    iedate,ietime=', iedate,ietime
157    if (verbosity.gt.1) then   
158      CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
159      write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
160    endif     
161  endif
162
163
164! Read the age classes to be used
165!********************************
166  if (verbosity.gt.0 .and. lroot) then
167    write(*,*) 'call readageclasses'
168  endif
169  call readageclasses
170
171  if (verbosity.gt.1 .and. lroot) then   
172    call system_clock(count_clock, count_rate, count_max)
173    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
174  endif     
175
176  ! Read, which wind fields are available within the modelling period
177  !******************************************************************
178
179  if (verbosity.gt.0 .and. lroot) then
180    write(*,*) 'call readavailable'
181  endif 
182  call readavailable
183!end if
184
185! Read the model grid specifications,
186! both for the mother domain and eventual nests
187!**********************************************
188
189  if (verbosity.gt.0 .and. lroot) then
190    write(*,*) 'call gridcheck'
191  endif
192
193  call gridcheck
194
195  if (verbosity.gt.1 .and. lroot) then   
196    call system_clock(count_clock, count_rate, count_max)
197    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
198  endif     
199
200
201  if (verbosity.gt.0 .and. lroot) then
202    write(*,*) 'call gridcheck_nests'
203  endif 
204  call gridcheck_nests
205
206
207! Read the output grid specifications
208!************************************
209
210  if (verbosity.gt.0 .and. lroot) then
211    WRITE(*,*) 'call readoutgrid'
212  endif
213
214  call readoutgrid
215
216  if (nested_output.eq.1) then
217    call readoutgrid_nest
218    if (verbosity.gt.0.and.lroot) then
219      WRITE(*,*) '# readoutgrid_nest'
220    endif
221  endif
222
223  ! Read the receptor points for which extra concentrations are to be calculated
224  !*****************************************************************************
225
226  if (verbosity.eq.1 .and. lroot) then
227    print*,'call readreceptors'
228  endif
229  call readreceptors
230
231  ! Read the physico-chemical species property table
232  !*************************************************
233  !SEC: now only needed SPECIES are read in readreleases.f
234  !call readspecies
235
236
237  ! Read the landuse inventory
238  !***************************
239
240  if (verbosity.gt.0 .and. lroot) then
241    print*,'call readlanduse'
242  endif
243  call readlanduse
244
245
246! Assign fractional cover of landuse classes to each ECMWF grid point
247!********************************************************************
248
249  if (verbosity.gt.0 .and. lroot) then
250    print*,'call assignland'
251  endif
252  call assignland
253
254  ! Read the coordinates of the release locations
255  !**********************************************
256
257  if (verbosity.gt.0 .and. lroot) then
258    print*,'call readreleases'
259  endif
260  call readreleases
261
262
263! Read and compute surface resistances to dry deposition of gases
264!****************************************************************
265
266  if (verbosity.gt.0 .and. lroot) then
267    print*,'call readdepo'
268  endif
269  call readdepo
270
271  ! Convert the release point coordinates from geografical to grid coordinates
272  !***************************************************************************
273
274  call coordtrafo 
275  if (verbosity.gt.0 .and. lroot) then
276    print*,'call coordtrafo'
277  endif
278
279
280  ! Initialize all particles to non-existent
281  !*****************************************
282
283  if (verbosity.gt.0 .and. lroot) then
284    print*,'Initialize all particles to non-existent'
285  endif
286
287  do j=1, size(itra1) ! maxpart_mpi
288    itra1(j)=-999999999
289  end do
290
291  ! For continuation of previous run, read in particle positions
292  !*************************************************************
293
294  if (ipin.eq.1) then
295    if (verbosity.gt.0 .and. lroot) then
296      print*,'call readpartpositions'
297    endif
298    call readpartpositions
299  else
300    if (verbosity.gt.0 .and. lroot) then
301      print*,'numpart=0, numparticlecount=0'
302    endif
303    numpart=0
304    numparticlecount=0
305  endif
306
307
308  ! Calculate volume, surface area, etc., of all output grid cells
309  ! Allocate fluxes and OHfield if necessary
310  !***************************************************************
311
312
313  if (verbosity.gt.0 .and. lroot) then
314    print*,'call outgrid_init'
315  endif
316  call outgrid_init
317  if (nested_output.eq.1) call outgrid_init_nest
318
319  ! Read the OH field
320  !******************
321
322  if (OHREA.eqv..true.) then
323    if (verbosity.gt.0 .and. lroot) then
324      print*,'call readOHfield'
325    endif
326    call readOHfield
327  endif
328
329  !! testing !!
330  ! open(999,file=trim(path(1))//'OH_FIELDS/jscalar_50N.txt',action='write',status='new')
331  ! open(998,file=trim(path(1))//'OH_FIELDS/jscalar_50S.txt',action='write',status='new')
332
333
334  ! Write basic information on the simulation to a file "header"
335  ! and open files that are to be kept open throughout the simulation
336  !******************************************************************
337
338  if (mp_measure_time) call mpif_mtime('iotime',0)
339! :DEV: was a bug here (all processes writing)?
340  if (lroot) then ! MPI: this part root process only
341
342  if (lnetcdfout.eq.1) then
343    call writeheader_netcdf(lnest=.false.)
344  else
345    call writeheader
346  end if
347
348  if (nested_output.eq.1) then
349    if (lnetcdfout.eq.1) then
350      call writeheader_netcdf(lnest=.true.)
351    else
352      call writeheader_nest
353    endif
354  endif
355
356!
357    if (verbosity.gt.0) then
358      print*,'call writeheader'
359    endif
360
361    call writeheader
362! FLEXPART 9.2 ticket ?? write header in ASCII format
363    call writeheader_txt
364!if (nested_output.eq.1) call writeheader_nest
365    if (nested_output.eq.1.and.surf_only.ne.1) call writeheader_nest
366    if (nested_output.eq.1.and.surf_only.eq.1) call writeheader_nest_surf
367    if (nested_output.ne.1.and.surf_only.eq.1) call writeheader_surf
368  end if ! (mpif_pid == 0)
369
370  if (mp_measure_time) call mpif_mtime('iotime',0)
371
372  !open(unitdates,file=path(2)(1:length(2))//'dates')
373
374  if (verbosity.gt.0 .and. lroot) then
375    print*,'call openreceptors'
376  endif
377  call openreceptors
378  if ((iout.eq.4).or.(iout.eq.5)) call openouttraj
379
380  ! Releases can only start and end at discrete times (multiples of lsynctime)
381  !***************************************************************************
382
383  if (verbosity.gt.0 .and. lroot) then
384    print*,'discretize release times'
385  endif
386  do i=1,numpoint
387    ireleasestart(i)=nint(real(ireleasestart(i))/real(lsynctime))*lsynctime
388    ireleaseend(i)=nint(real(ireleaseend(i))/real(lsynctime))*lsynctime
389  end do
390
391  ! Initialize cloud-base mass fluxes for the convection scheme
392  !************************************************************
393
394  if (verbosity.gt.0 .and. lroot) then
395    print*,'Initialize cloud-base mass fluxes for the convection scheme'
396  endif
397
398  do jy=0,nymin1
399    do ix=0,nxmin1
400      cbaseflux(ix,jy)=0.
401    end do
402  end do
403  do inest=1,numbnests
404    do jy=0,nyn(inest)-1
405      do ix=0,nxn(inest)-1
406        cbasefluxn(ix,jy,inest)=0.
407      end do
408    end do
409  end do
410
411
412! Calculate particle trajectories
413!********************************
414
415  if (verbosity.gt.0.and. lroot) then
416    if (verbosity.gt.1) then   
417      CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
418      WRITE(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
419    endif
420    if (info_flag.eq.1) then
421      print*, 'info only mode (stop)'   
422      stop
423    endif
424    print*,'call timemanager'
425  endif
426
427  call timemanager
428
429! NIK 16.02.2005
430  if (lroot) then
431    call MPI_Reduce(MPI_IN_PLACE, tot_blc_count, 1, mp_pp, MPI_SUM, id_root, &
432         & mp_comm_used, mp_ierr)
433    call MPI_Reduce(MPI_IN_PLACE, tot_inc_count, 1, mp_pp, MPI_SUM, id_root, &
434         & mp_comm_used, mp_ierr)
435  else
436    if (mp_partgroup_pid.ge.0) then ! Skip for readwind process
437      call MPI_Reduce(tot_blc_count, tot_blc_count, 1, mp_pp, MPI_SUM, id_root, &
438           & mp_comm_used, mp_ierr)
439      call MPI_Reduce(tot_inc_count, tot_inc_count, 1, mp_pp, MPI_SUM, id_root, &
440           & mp_comm_used, mp_ierr)
441    end if
442  end if
443
444  if (lroot) then
445    write(*,*) '**********************************************'
446    write(*,*) 'Total number of occurences of below-cloud scavenging', tot_blc_count
447    write(*,*) 'Total number of occurences of in-cloud    scavenging', tot_inc_count
448    write(*,*) '**********************************************'
449
450    write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLE&
451         &XPART MODEL RUN!'
452  end if
453
454  if (mp_measure_time) call mpif_mtime('flexpart',1)
455
456  call mpif_finalize
457
458end program flexpart
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG