Index: src/FLEXPART.f90
===================================================================
--- src/FLEXPART.f90	(revision b7ae015d9987e02b895735f00b6858ce5318800a)
+++ src/FLEXPART.f90	(revision 8a65cb0801b09eb0ae933a1afabbe10361a9021b)
@@ -44,4 +44,6 @@
   use com_mod
   use conv_mod
+  use netcdf_output_mod, only: writeheader_netcdf
+  use random_mod, only: gasdev1
 
   implicit none
@@ -50,5 +52,11 @@
   integer :: idummy = -320
   character(len=256) :: inline_options  !pathfile, flexversion, arg2
-  integer :: index_v
+
+
+  ! Initialize arrays in com_mod
+  !*****************************
+  call com_mod_allocate(maxpart)
+
+
 
   ! Generate a large number of random numbers
@@ -61,21 +69,18 @@
 
   ! FLEXPART version string
-  ! flexversion='Version 9.2 beta (2014-07-01)'
-  !flexversion='Version 9.2.0.1 (2015-01-27)'
-  flexversion='Version 9.2.0.2 (2015-03-01)'
-  ! default inlide options
-  inline_options='none'
-  !verbosity flags  defined in com_mod.f90
- 
+  flexversion='Version 10.0pre  (2015-03-01)'
+  verbosity=0
+
   ! Read the pathnames where input/output files are stored
   !*******************************************************
 
+  inline_options='none'
   select case (iargc())
-  case (2) !2 parameters: pathfile and inline options
+  case (2)
     call getarg(1,arg1)
     pathfile=arg1
     call getarg(2,arg2)
     inline_options=arg2
-  case (1) !1 parameter pathfiel or inline options
+  case (1)
     call getarg(1,arg1)
     pathfile=arg1
@@ -84,5 +89,5 @@
       inline_options=arg1 
     endif
-  case (0) !default behavior
+  case (0)
     write(pathfile,'(a11)') './pathnames'
   end select
@@ -92,84 +97,40 @@
   print*,'Welcome to FLEXPART ', trim(flexversion)
   print*,'FLEXPART is free software released under the GNU General Public License.'
-
-  ! inline options allow to fine tune the verbosity during run time
-  ! e.g.: show compilation parameters or input variables, time execution     
+ 
   if (inline_options(1:1).eq.'-') then
-   ! if (index(inline_options,'v').gt.0) then
-   !    print*, 'verbose mode'
-   !    verbosity=1
-   !    index_v=index(inline_options,'v')
-   !    if (inline_options(index_v+1:index_v+1).eq.'2') then
-   !    verbosity=2
-   !    endif         
-   ! endif   
- 
-    !if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
-    if (index(inline_options,'v').gt.0) then
-       index_v=index(inline_options,'v')
-       print*, 'Verbose mode: display  additional information during run'
+    if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
+       print*, 'Verbose mode 1: display detailed information during run'
        verbosity=1
-       if (inline_options(index_v+1:index_v+1).eq.'2') then
+    endif
+    if (trim(inline_options).eq.'-v2') then
+       print*, 'Verbose mode 2: display more detailed information during run'
        verbosity=2
-       endif
-       print*, 'verbosity level=', verbosity !inline_options(index_v+1:index_v+1)
-    endif
-    !iif (trim(inline_options).eq.'-v2') then
-    !   print*, 'Verbose mode 2: display more detailed information during run'
-    !   verbosity=2
-    !endif
-
-    if (index(inline_options,'i').gt.0) then   
-       index_v=index(inline_options,'i')
-       print*, 'Info mode: provide compile and run specific information, then stop'
+    endif
+    if (trim(inline_options).eq.'-i') then
+       print*, 'Info mode: provide detailed run specific information and stop'
        verbosity=1
        info_flag=1
-       if (inline_options(index_v+1:index_v+1).eq.'2') then
-       info_flag=2
-       endif
-    endif
-    if (index(inline_options,'t').gt.0) then
-       time_flag=1
-       print*, 'timing execution activated'
-       !stop
-    endif
-    if (index(inline_options,'d').gt.0) then
-       debug_flag=1
-       print*, 'debug messages activated'
-       print*, 'debug_flag=', debug_flag
-       !these messages give additional info on top on verbose mode
-    endif 
+    endif
+    if (trim(inline_options).eq.'-i2') then
+       print*, 'Info mode: provide more detailed run specific information and stop'
+       verbosity=2
+       info_flag=1
+    endif
   endif
            
   if (verbosity.gt.0) then
-    print*, 'FLEXPART>******************************'
-    print*, 'FLEXPART>* verbosity level:', verbosity
-    print*, 'FLEXPART>* info only:      ', info_flag
-    print*, 'FLEXPART>* time execution: ', time_flag
-    print*, 'FLEXPART>******************************'
-    
-    print*, 'FLEXPART> parameters from par_mod'    
-    print*, 'FLEXPART> nxmax=  ', nxmax
-    print*, 'FLEXPART> nymax=  ', nymax
-    print*, 'FLEXPART> nuvzmax=', nuvzmax
-    print*, 'FLEXPART> nwzmax= ', nwzmax
-    print*, 'FLEXPART> nzmax=  ', nzmax
-    print*, 'FLEXPART> nxshift=', nxshift
-    print*, 'FLEXPART> maxpart=', maxpart
-    print*, 'FLEXPART> maxspec=', maxspec 
-
-    if (info_flag.eq.1) stop
     write(*,*) 'call readpaths'
   endif 
   call readpaths(pathfile)
  
-  !if (time_flag.gt.1) then !show clock info 
+  if (verbosity.gt.1) then !show clock info 
+     !print*,'length(4)',length(4)
      !count=0,count_rate=1000
-  CALL SYSTEM_CLOCK(count_clock0, count_rate, count_max)
+     CALL SYSTEM_CLOCK(count_clock0, count_rate, count_max)
      !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
-  !endif
+  endif
 
   ! Read the user specifications for the current model run
@@ -177,25 +138,25 @@
 
   if (verbosity.gt.0) then
-    write(*,*) 'FLEXPART> call readcommand'
+    write(*,*) 'call readcommand'
   endif
   call readcommand
   if (verbosity.gt.0) then
-    write(*,*) '    ldirect      =', ldirect
-    write(*,*) '    ibdate,ibtime=', ibdate,ibtime
+    write(*,*) '    ldirect=', ldirect
+    write(*,*) '    ibdate,ibtime=',ibdate,ibtime
     write(*,*) '    iedate,ietime=', iedate,ietime
-  endif
-    if (time_flag.gt.0) then   
+    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     
+  endif
 
   ! Read the age classes to be used
   !********************************
   if (verbosity.gt.0) then
-    write(*,*) 'FLEXPART> call readageclasses'
+    write(*,*) 'call readageclasses'
   endif
   call readageclasses
 
-  if (time_flag.gt.1) then   
+  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
@@ -206,5 +167,5 @@
 
   if (verbosity.gt.0) then
-    write(*,*) 'FLEXPART> call readavailable'
+    write(*,*) 'call readavailable'
   endif  
   call readavailable
@@ -215,9 +176,10 @@
  
   if (verbosity.gt.0) then
-     write(*,*) 'FLEXPART> call gridcheck'
-  endif
+     write(*,*) 'call gridcheck'
+  endif
+
   call gridcheck
 
-  if (time_flag.gt.0) then   
+  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
@@ -225,5 +187,5 @@
 
   if (verbosity.gt.0) then
-    write(*,*) 'FLEXPART> call gridcheck_nests'
+    write(*,*) 'call gridcheck_nests'
   endif  
   call gridcheck_nests
@@ -233,5 +195,5 @@
 
   if (verbosity.gt.0) then
-    write(*,*) 'FLEXPART> call readoutgrid'
+    write(*,*) 'call readoutgrid'
   endif
 
@@ -241,5 +203,5 @@
     call readoutgrid_nest
     if (verbosity.gt.0) then
-      write(*,*) 'FLEXPART>  readoutgrid_nest'
+      write(*,*) '# readoutgrid_nest'
     endif
   endif
@@ -249,5 +211,5 @@
 
   if (verbosity.eq.1) then
-     print*,'FLEXPART> call readreceptors'
+     print*,'call readreceptors'
   endif
   call readreceptors
@@ -263,5 +225,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call readlanduse'
+    print*,'call readlanduse'
   endif
   call readlanduse
@@ -271,5 +233,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call assignland'
+    print*,'call assignland'
   endif
   call assignland
@@ -279,5 +241,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call readreleases'
+    print*,'call readreleases'
   endif
   call readreleases
@@ -287,5 +249,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call readdepo'
+    print*,'call readdepo'
   endif
   call readdepo
@@ -296,5 +258,5 @@
   call coordtrafo  
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call coordtrafo'
+    print*,'call coordtrafo'
   endif
 
@@ -303,5 +265,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> Initialize all particles to non-existent'
+    print*,'Initialize all particles to non-existent'
   endif
   do j=1,maxpart
@@ -314,10 +276,10 @@
   if (ipin.eq.1) then
     if (verbosity.gt.0) then
-      print*,'FLEXPART> call readpartpositions'
+      print*,'call readpartpositions'
     endif
     call readpartpositions
   else
     if (verbosity.gt.0) then
-      print*,'FLEXPART> set numpart=0, numparticlecount=0'
+      print*,'numpart=0, numparticlecount=0'
     endif    
     numpart=0
@@ -330,5 +292,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call outgrid_init'
+    print*,'call outgrid_init'
   endif
   call outgrid_init
@@ -340,8 +302,13 @@
   if (OHREA.eqv..TRUE.) then
     if (verbosity.gt.0) then
-      print*,'FLEXPART> call readOHfield'
+      print*,'call readOHfield'
     endif
     call readOHfield
   endif
+
+  !! 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')
+
 
   ! Write basic information on the simulation to a file "header"
@@ -349,10 +316,24 @@
   !******************************************************************
 
-  if (verbosity.gt.0) then
-    print*,'FLEXPART> call variuos writeheader routines'
+  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
+
+  if (verbosity.gt.0) then
+    print*,'call writeheader'
   endif
 
   call writeheader
-  ! write header in ASCII format 
+  ! FLEXPART 9.2 ticket ?? write header in ASCII format 
   call writeheader_txt
   !if (nested_output.eq.1) call writeheader_nest
@@ -364,5 +345,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> call openreceptors'
+    print*,'call openreceptors'
   endif
   call openreceptors
@@ -373,5 +354,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> discretize release times'
+    print*,'discretize release times'
   endif
   do i=1,numpoint
@@ -384,5 +365,5 @@
 
   if (verbosity.gt.0) then
-    print*,'FLEXPART> Initialize cloud-base mass fluxes for the convection scheme'
+    print*,'Initialize cloud-base mass fluxes for the convection scheme'
   endif
 
@@ -403,19 +384,26 @@
   !********************************
 
-  if (time_flag.gt.0) 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.2) then
-    print*, 'FLEXPART> info only mode (stop before call timemanager)'
-    stop
-  endif
-  if (verbosity.gt.0) then
-     print*,'FLEXPART> call timemanager'
+  if (verbosity.gt.0) then
+     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'
   endif
 
   call timemanager
 
-  write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLEXPART MODEL RUN!'
+! 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!'
 
 end program flexpart
