Index: trunk/src/timemanager.f90
===================================================================
--- trunk/src/timemanager.f90	(revision 20)
+++ trunk/src/timemanager.f90	(revision 30)
@@ -43,12 +43,14 @@
   !     call convection BEFORE new fields are read in BWD mode                 *
   !  Changes Caroline Forster, Feb 2005                                        *
-  !new interface between flexpart and convection scheme                        *
-  !Emanuel's latest subroutine convect43c.f is used                            *
+  !   new interface between flexpart and convection scheme                     *
+  !   Emanuel's latest subroutine convect43c.f is used                         *
+  !  Changes Stefan Henne, Harald Sodemann, 2013-2014                          *
+  !   added netcdf output code                                                 *
   !*****************************************************************************
   !                                                                            *
   ! Variables:                                                                 *
-  ! DEP                .true. if either wet or dry deposition is switched on   *
+  ! dep                .true. if either wet or dry deposition is switched on   *
   ! decay(maxspec) [1/s] decay constant for radioactive decay                  *
-  ! DRYDEP             .true. if dry deposition is switched on                 *
+  ! drydep             .true. if dry deposition is switched on                 *
   ! ideltas [s]        modelling period                                        *
   ! itime [s]          actual temporal position of calculation                 *
@@ -70,5 +72,5 @@
   ! prob               probability of absorption at ground due to dry          *
   !                    deposition                                              *
-  ! WETDEP             .true. if wet deposition is switched on                 *
+  ! wetdep             .true. if wet deposition is switched on                 *
   ! weight             weight for each concentration sample (1/2 or 1)         *
   ! uap(maxpart),ucp(maxpart),uzp(maxpart) = random velocities due to          *
@@ -92,4 +94,7 @@
   use par_mod
   use com_mod
+#ifdef NETCDF_OUTPUT
+  use netcdf_output_mod, only: concoutput_netcdf, concoutput_nest_netcdf,concoutput_surf_netcdf, concoutput_surf_nest_netcdf
+#endif 
 
   implicit none
@@ -129,4 +134,7 @@
 
 
+  itime=0
+  !write(*,45) itime,numpart,gridtotalunc,wetgridtotalunc,drygridtotalunc
+  write(*,46) float(itime)/3600,itime,numpart
   if (verbosity.gt.0) then
     write (*,*) 'timemanager> starting simulation'
@@ -138,5 +146,4 @@
 
   do itime=0,ideltas,lsynctime
-
 
   ! Computation of wet deposition, OH reaction and mass transfer
@@ -150,5 +157,5 @@
   !********************************************************************
 
-    if (WETDEP .and. itime .ne. 0 .and. numpart .gt. 0) then
+    if (wetdep .and. itime .ne. 0 .and. numpart .gt. 0) then
         if (verbosity.gt.0) then
            write (*,*) 'timemanager> call wetdepo'
@@ -157,8 +164,8 @@
     endif
 
-    if (OHREA .and. itime .ne. 0 .and. numpart .gt. 0) &
+    if (ohrea .and. itime .ne. 0 .and. numpart .gt. 0) &
          call ohreaction(itime,lsynctime,loutnext)
 
-    if (ASSSPEC .and. itime .ne. 0 .and. numpart .gt. 0) then
+    if (assspec .and. itime .ne. 0 .and. numpart .gt. 0) then
        stop 'associated species not yet implemented!'
   !     call transferspec(itime,lsynctime,loutnext)
@@ -238,5 +245,5 @@
   !***********************************************************************
 
-    if (DEP.and.(itime.eq.loutnext).and.(ldirect.gt.0)) then
+    if (dep.and.(itime.eq.loutnext).and.(ldirect.gt.0)) then
       do ks=1,nspec
       do kp=1,maxpointspec_act
@@ -348,31 +355,56 @@
         if ((iout.le.3.).or.(iout.eq.5)) then
           if (surf_only.ne.1) then 
-          call concoutput(itime,outnum,gridtotalunc, &
-               wetgridtotalunc,drygridtotalunc)
+            if (lnetcdfout.eq.1) then 
+#ifdef NETCDF_OUTPUT
+              call concoutput_netcdf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
+#endif 
+            else 
+              call concoutput(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
+            endif
           else  
-  if (verbosity.eq.1) then
-     print*,'call concoutput_surf '
-     CALL SYSTEM_CLOCK(count_clock)
-     WRITE(*,*) 'SYSTEM_CLOCK',count_clock - count_clock0   
-  endif
-          call concoutput_surf(itime,outnum,gridtotalunc, &
-               wetgridtotalunc,drygridtotalunc)
-  if (verbosity.eq.1) then
-     print*,'called concoutput_surf '
-     CALL SYSTEM_CLOCK(count_clock)
-     WRITE(*,*) 'SYSTEM_CLOCK',count_clock - count_clock0   
-  endif
+            if (verbosity.eq.1) then
+             print*,'call concoutput_surf '
+             call system_clock(count_clock)
+             write(*,*) 'system clock',count_clock - count_clock0   
+            endif
+            if (lnetcdfout.eq.1) then 
+#ifdef NETCDF_OUTPUT
+              call concoutput_surf_netcdf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
+#endif 
+            else
+              call concoutput_surf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
+              if (verbosity.eq.1) then
+                print*,'called concoutput_surf '
+                call system_clock(count_clock)
+                write(*,*) 'system clock',count_clock - count_clock0   
+              endif
+            endif
           endif
 
-          if ((nested_output.eq.1).and.(surf_only.ne.1)) call concoutput_nest(itime,outnum)
-          if ((nested_output.eq.1).and.(surf_only.eq.1)) call concoutput_surf_nest(itime,outnum)
+          if (nested_output .eq. 1) then
+            if (lnetcdfout.eq.0) then
+              if (surf_only.ne.1) then
+                call concoutput_nest(itime,outnum)
+              else 
+                call concoutput_surf_nest(itime,outnum)
+              endif
+            else
+#ifdef NETCDF_OUTPUT
+              if (surf_only.ne.1) then
+                call concoutput_nest_netcdf(itime,outnum)
+              else 
+                call concoutput_surf_nest_netcdf(itime,outnum)
+              endif
+#endif
+            endif
+          endif
           outnum=0.
         endif
         if ((iout.eq.4).or.(iout.eq.5)) call plumetraj(itime)
         if (iflux.eq.1) call fluxoutput(itime)
-        write(*,45) itime,numpart,gridtotalunc,wetgridtotalunc, &
-             drygridtotalunc
-45      format(i9,' SECONDS SIMULATED: ',i8, &
-             ' PARTICLES:    Uncertainty: ',3f7.3)
+        !write(*,45) itime,numpart,gridtotalunc,wetgridtotalunc,drygridtotalunc
+        write(*,46) float(itime)/3600,itime,numpart
+45      format(i9,' SECONDS SIMULATED: ',i8, ' PARTICLES:    Uncertainty: ',3f7.3)
+46      format(' Simulated ',f7.1,' hours (',i9,' s), ',i8, ' particles')
         if (ipout.ge.1) call partoutput(itime)    ! dump particle positions
         loutnext=loutnext+loutstep
@@ -472,6 +504,6 @@
   !****************************
 
-        xold=xtra1(j)
-        yold=ytra1(j)
+        xold=real(xtra1(j))
+        yold=real(ytra1(j))
         zold=ztra1(j)
 
@@ -513,5 +545,5 @@
             endif
 
-            if (DRYDEPSPEC(ks)) then        ! dry deposition
+            if (drydepspec(ks)) then        ! dry deposition
               drydeposit(ks)=xmass1(j,ks)*prob(ks)*decfact
               xmass1(j,ks)=xmass1(j,ks)*(1.-prob(ks))*decfact
@@ -524,5 +556,4 @@
             endif
 
-
             if (mdomainfill.eq.0) then
               if (xmass(npoint(j),ks).gt.0.) &
@@ -536,14 +567,16 @@
           if (xmassfract.lt.0.0001) then   ! terminate all particles carrying less mass
             itra1(j)=-999999999
+            if (verbosity.gt.0) then
+              print*,'terminated particle ',j,' for small mass'
+            endif
           endif
 
   !        Sabine Eckhardt, June 2008
   !        don't create depofield for backward runs
-          if (DRYDEP.AND.(ldirect.eq.1)) then
-            call drydepokernel(nclass(j),drydeposit,real(xtra1(j)), &
-                 real(ytra1(j)),nage,kp)
-            if (nested_output.eq.1) call drydepokernel_nest( &
-                 nclass(j),drydeposit,real(xtra1(j)),real(ytra1(j)), &
-                 nage,kp)
+          if (drydep.AND.(ldirect.eq.1)) then
+            call drydepokernel(nclass(j),drydeposit,real(xtra1(j)),real(ytra1(j)),nage,kp)
+            if (nested_output.eq.1) then
+              call drydepokernel_nest(nclass(j),drydeposit,real(xtra1(j)),real(ytra1(j)),nage,kp)
+            endif
           endif
 
@@ -552,7 +585,9 @@
 
           if (abs(itra1(j)-itramem(j)).ge.lage(nageclass)) then
-            if (linit_cond.ge.1) &
-                 call initial_cond_calc(itime+lsynctime,j)
+            if (linit_cond.ge.1) call initial_cond_calc(itime+lsynctime,j)
             itra1(j)=-999999999
+            if (verbosity.gt.0) then
+              print*,'terminated particle ',j,' for age'
+            endif
           endif
         endif
@@ -582,11 +617,11 @@
 
   if (iflux.eq.1) then
-      deallocate(flux)
+    deallocate(flux)
   endif
-  if (OHREA.eqv..TRUE.) then
-      deallocate(OH_field,OH_field_height)
+  if (ohrea.eqv..TRUE.) then
+    deallocate(OH_field,OH_field_height)
   endif
   if (ldirect.gt.0) then
-  deallocate(drygridunc,wetgridunc)
+    deallocate(drygridunc,wetgridunc)
   endif
   deallocate(gridunc)
@@ -595,11 +630,11 @@
   deallocate(xmasssave)
   if (nested_output.eq.1) then
-     deallocate(orooutn, arean, volumen)
-     if (ldirect.gt.0) then
-     deallocate(griduncn,drygriduncn,wetgriduncn)
-     endif
+    deallocate(orooutn, arean, volumen)
+    if (ldirect.gt.0) then
+      deallocate(griduncn,drygriduncn,wetgriduncn)
+    endif
   endif
   deallocate(outheight,outheighthalf)
-  deallocate(oroout, area, volume)
+  deallocate(oroout,area,volume)
 
 end subroutine timemanager
