Index: trunk/src/FLEXPART.f90
===================================================================
--- trunk/src/FLEXPART.f90	(revision 20)
+++ trunk/src/FLEXPART.f90	(revision 30)
@@ -45,4 +45,9 @@
   use conv_mod
 
+#ifdef NETCDF_OUTPUT
+  use netcdf_output_mod, only: writeheader_netcdf
+#endif
+
+
   implicit none
 
@@ -60,7 +65,8 @@
   call gasdev1(idummy,rannumb(maxrand),rannumb(maxrand-1))
 
-  ! 
-  flexversion='Version 9.1.8  (2013-12-08)'
-  !verbosity=0
+  ! FLEXPART version string
+  flexversion='Version 9.2 beta (2014-07-01)'
+  verbosity=0
+
   ! Read the pathnames where input/output files are stored
   !*******************************************************
@@ -76,48 +82,42 @@
     call getarg(1,arg1)
     pathfile=arg1
-    verbosity=0
     if (arg1(1:1).eq.'-') then
-        write(pathfile,'(a11)') './pathnames'
-        inline_options=arg1 
+      write(pathfile,'(a11)') './pathnames'
+      inline_options=arg1 
     endif
   case (0)
     write(pathfile,'(a11)') './pathnames'
-    verbosity=0
   end select
   
-    if (inline_options(1:1).eq.'-') then
-      print*, 'inline options=', inline_options       
-      if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
-         print*, 'verbose mode 1: additional information will be displayed'
-         verbosity=1
-      endif
-      if (trim(inline_options).eq.'-v2') then
-         print*, 'verbose mode 2: additional information will be displayed'
-         verbosity=2
-      endif
-      if (trim(inline_options).eq.'-i') then
-         print*, 'info mode: will provide run specific information and stop'
-         verbosity=1
-         info_flag=1
-      endif
-      if (trim(inline_options).eq.'-i2') then
-         print*, 'info mode: will provide run specific information and stop'
-         verbosity=2
-         info_flag=1
-      endif
-    endif
-
-
   ! Print the GPL License statement
   !*******************************************************
-  print*,'Welcome to FLEXPART', trim(flexversion)
-  print*,'FLEXPART is free software released under the GNU Genera'// &
-       'l Public License.'
-            
-  if (verbosity.gt.0) then
-        WRITE(*,*) 'call readpaths'
+  print*,'Welcome to FLEXPART ', trim(flexversion)
+  print*,'FLEXPART is free software released under the GNU General Public License.'
+ 
+  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'
+       verbosity=1
+    endif
+    if (trim(inline_options).eq.'-v2') then
+       print*, 'Verbose mode 2: display more detailed information during run'
+       verbosity=2
+    endif
+    if (trim(inline_options).eq.'-i') then
+       print*, 'Info mode: provide detailed run specific information and stop'
+       verbosity=1
+       info_flag=1
+    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
+    write(*,*) 'call readpaths'
   endif 
   call readpaths(pathfile)
-   
  
   if (verbosity.gt.1) then !show clock info 
@@ -131,36 +131,32 @@
   endif
 
-
   ! Read the user specifications for the current model run
   !*******************************************************
 
   if (verbosity.gt.0) then
-        WRITE(*,*) 'call readcommand'
+    write(*,*) 'call readcommand'
   endif
   call readcommand
   if (verbosity.gt.0) then
-        WRITE(*,*) '    ldirect=', ldirect
-        WRITE(*,*) '    ibdate,ibtime=',ibdate,ibtime
-        WRITE(*,*) '    iedate,ietime=', iedate,ietime
-        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
-
+    write(*,*) '    ldirect=', ldirect
+    write(*,*) '    ibdate,ibtime=',ibdate,ibtime
+    write(*,*) '    iedate,ietime=', iedate,ietime
+    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(*,*) 'call readageclasses'
+    write(*,*) 'call readageclasses'
   endif
   call readageclasses
 
   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
+    CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
+    write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
   endif     
- 
-
 
   ! Read, which wind fields are available within the modelling period
@@ -168,5 +164,5 @@
 
   if (verbosity.gt.0) then
-        WRITE(*,*) 'call readavailable'
+    write(*,*) 'call readavailable'
   endif  
   call readavailable
@@ -177,5 +173,5 @@
  
   if (verbosity.gt.0) then
-     WRITE(*,*) 'call gridcheck'
+     write(*,*) 'call gridcheck'
   endif
 
@@ -183,20 +179,18 @@
 
   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
+    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 (verbosity.gt.0) then
-        WRITE(*,*) 'call gridcheck_nests'
+
+  if (verbosity.gt.0) then
+    write(*,*) 'call gridcheck_nests'
   endif  
   call gridcheck_nests
 
-
   ! Read the output grid specifications
   !************************************
 
   if (verbosity.gt.0) then
-        WRITE(*,*) 'call readoutgrid'
+    write(*,*) 'call readoutgrid'
   endif
 
@@ -204,7 +198,7 @@
 
   if (nested_output.eq.1) then
-          call readoutgrid_nest
+    call readoutgrid_nest
     if (verbosity.gt.0) then
-        WRITE(*,*) '# readoutgrid_nest'
+      write(*,*) '# readoutgrid_nest'
     endif
   endif
@@ -232,5 +226,4 @@
   call readlanduse
 
-
   ! Assign fractional cover of landuse classes to each ECMWF grid point
   !********************************************************************
@@ -241,6 +234,4 @@
   call assignland
 
-
-
   ! Read the coordinates of the release locations
   !**********************************************
@@ -251,5 +242,4 @@
   call readreleases
 
-
   ! Read and compute surface resistances to dry deposition of gases
   !****************************************************************
@@ -267,5 +257,4 @@
     print*,'call coordtrafo'
   endif
-
 
   ! Initialize all particles to non-existent
@@ -295,10 +284,8 @@
   endif
 
-
   ! Calculate volume, surface area, etc., of all output grid cells
   ! Allocate fluxes and OHfield if necessary
   !***************************************************************
 
-
   if (verbosity.gt.0) then
     print*,'call outgrid_init'
@@ -307,5 +294,4 @@
   if (nested_output.eq.1) call outgrid_init_nest
 
-
   ! Read the OH field
   !******************
@@ -313,7 +299,7 @@
   if (OHREA.eqv..TRUE.) then
     if (verbosity.gt.0) then
-       print*,'call readOHfield'
-    endif
-       call readOHfield
+      print*,'call readOHfield'
+    endif
+    call readOHfield
   endif
 
@@ -322,4 +308,21 @@
   !******************************************************************
 
+  if (lnetcdfout.eq.1) then 
+#ifdef NETCDF_OUTPUT
+    call writeheader_netcdf(lnest = .false.)
+#endif
+  else 
+    call writeheader
+  end if
+
+  if (nested_output.eq.1) then
+    if (lnetcdfout.eq.1) then
+#ifdef NETCDF_OUTPUT
+      call writeheader_netcdf(lnest = .true.)
+#endif
+    else
+      call writeheader_nest
+    endif
+  endif
 
   if (verbosity.gt.0) then
@@ -332,11 +335,10 @@
   !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 (lnetcdfout.ne.1) then
+    open(unitdates,file=path(2)(1:length(2))//'dates')
+  end if
 
   if (verbosity.gt.0) then
@@ -346,5 +348,4 @@
   if ((iout.eq.4).or.(iout.eq.5)) call openouttraj
 
-
   ! Releases can only start and end at discrete times (multiples of lsynctime)
   !***************************************************************************
@@ -354,10 +355,7 @@
   endif
   do i=1,numpoint
-    ireleasestart(i)=nint(real(ireleasestart(i))/ &
-         real(lsynctime))*lsynctime
-    ireleaseend(i)=nint(real(ireleaseend(i))/ &
-         real(lsynctime))*lsynctime
+    ireleasestart(i)=nint(real(ireleasestart(i))/real(lsynctime))*lsynctime
+    ireleaseend(i)=nint(real(ireleaseend(i))/real(lsynctime))*lsynctime
   end do
-
 
   ! Initialize cloud-base mass fluxes for the convection scheme
@@ -381,5 +379,4 @@
   end do
 
-
   ! Calculate particle trajectories
   !********************************
@@ -387,10 +384,10 @@
   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
+       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
+       print*, 'Info only mode (stop)'    
+       stop
      endif
      print*,'call timemanager'
@@ -399,7 +396,12 @@
   call timemanager
 
-
-  write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLE&
-       &XPART MODEL RUN!'
+  write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A FLEXPART MODEL RUN!'
+
+  ! output wall time
+  if (verbosity .gt. 0) then
+    call system_clock(count_clock,count_rate)
+    tins=(count_clock - count_clock0)/real(count_rate)
+    print*,'Wall time ',tins,'s, ',tins/60,'min, ',tins/3600,'h.'
+  endif
 
 end program flexpart
