Index: branches/FLEXPART_9.1.3/src/FLEXPART.f90
===================================================================
--- trunk/src/FLEXPART.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/FLEXPART.f90	(revision 14)
@@ -49,4 +49,5 @@
   integer :: i,j,ix,jy,inest
   integer :: idummy = -320
+  character(len=256) :: pathfile
 
   ! Generate a large number of random numbers
@@ -60,5 +61,6 @@
   ! Print the GPL License statement
   !*******************************************************
-  print*,'Welcome to FLEXPART Version 9.0'
+  ! print*,'Welcome to FLEXPART Version 9.1 (Build 20121029)'
+  print*,'Welcome to FLEXPART Version 9.1.3 (Build 2013158)'
   print*,'FLEXPART is free software released under the GNU Genera'// &
        'l Public License.'
@@ -67,5 +69,17 @@
   !*******************************************************
 
-  call readpaths
+  select case (iargc())
+  case (1)
+    call getarg(1,pathfile)
+    if (trim(pathfile).eq.'-v') then
+        !write(*,*) 'FLEXPART Version 9.1.3 (Build 2013158)'
+        stop
+    endif  
+  case (0)
+    write(pathfile,'(a11)') './pathnames'
+  end select
+
+  call readpaths(pathfile)
+  print*,length(4)
 
   ! Read the user specifications for the current model run
Index: branches/FLEXPART_9.1.3/src/Makefile.ecmwf
===================================================================
--- branches/FLEXPART_9.1.3/src/Makefile.ecmwf	(revision 14)
+++ branches/FLEXPART_9.1.3/src/Makefile.ecmwf	(revision 14)
@@ -0,0 +1,104 @@
+SHELL = /bin/bash
+MAIN = FLEXPART_GFORTRAN
+#
+
+FC       = gfortran
+#INCPATH  = /usr/local/ecmwf_tools/reloc/include
+#LIBPATH1 = /usr/local/ecmwf_tools/reloc/lib
+#LIBPATH2 = /usr/local/lib
+#FFLAGS   = -O3 -g -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+FFLAGS   = -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+#LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -lopenjpeg
+
+# options for nordre
+INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
+LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
+LIBPATH2 =   /usr/lib/x86_64-linux-gnu/
+#FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
+
+#options for Lion
+libs_dir=/Users/ignacio_in_EBCRPA/flexpart/libs/
+INCPATH  = $(libs_dir)/grib_api-1.9.9_dir/include
+LIBPATH1 = $(libs_dir)/grib_api-1.9.9_dir/lib
+LIBPATH2 = $(libs_dir)/jasper_dir/lib
+
+
+
+MODOBJS = \
+par_mod.o               com_mod.o \
+conv_mod.o              hanna_mod.o \
+interpol_mod.o          cmapf_mod.o \
+unc_mod.o               oh_mod.o \
+xmass_mod.o             flux_mod.o \
+point_mod.o             outg_mod.o
+
+OBJECTS = \
+writeheader.o           assignland.o\
+calcpar.o               part0.o \
+caldate.o               partdep.o \
+coordtrafo.o            psih.o \
+raerod.o \
+drydepokernel.o         random.o \
+readavailable.o \
+ew.o                    readcommand.o \
+advance.o               readdepo.o \
+releaseparticles.o      psim.o     \
+FLEXPART.o              readlanduse.o \
+getfields.o             init_domainfill.o\
+interpol_wind.o         readoutgrid.o \
+interpol_all.o          readpaths.o \
+getrb.o                 readreceptors.o \
+getrc.o                 readreleases.o \
+getvdep.o               readspecies.o \
+interpol_misslev.o      readwind.o \
+conccalc.o              richardson.o \
+concoutput.o            scalev.o \
+pbl_profile.o           readOHfield.o\
+juldate.o               timemanager.o \
+interpol_vdep.o         interpol_rain.o \
+verttransform.o         partoutput.o \
+hanna.o                 wetdepokernel.o \
+mean.o                  wetdepo.o \
+hanna_short.o           windalign.o \
+obukhov.o               gridcheck.o \
+hanna1.o                initialize.o \
+                        gridcheck_nests.o \
+readwind_nests.o        calcpar_nests.o \
+verttransform_nests.o   interpol_all_nests.o \
+interpol_wind_nests.o   interpol_misslev_nests.o \
+interpol_vdep_nests.o   interpol_rain_nests.o \
+getvdep_nests.o \
+readageclasses.o        readpartpositions.o \
+calcfluxes.o            fluxoutput.o \
+qvsat.o                 skplin.o \
+convmix.o               calcmatrix.o \
+convect43c.o               redist.o \
+sort2.o                 distance.o \
+centerofmass.o          plumetraj.o \
+openouttraj.o           calcpv.o \
+calcpv_nests.o          distance2.o \
+clustering.o            interpol_wind_short.o \
+interpol_wind_short_nests.o shift_field_0.o \
+shift_field.o           outgrid_init.o \
+openreceptors.o         boundcond_domainfill.o\
+partoutput_short.o      readoutgrid_nest.o \
+outgrid_init_nest.o     writeheader_nest.o \
+concoutput_nest.o       wetdepokernel_nest.o \
+drydepokernel_nest.o    zenithangle.o \
+ohreaction.o            getvdep_nests.o \
+initial_cond_calc.o     initial_cond_output.o \
+dynamic_viscosity.o     get_settling.o
+
+
+$(MAIN): $(MODOBJS) $(OBJECTS)
+	$(FC) *.o -o $(MAIN) $(LDFLAGS)
+
+$(OBJECTS): $(MODOBJS)
+
+%.o: %.f90
+	$(FC) -c $(FFLAGS) $<
+
+clean:
+	rm *.o *.mod
+
Index: branches/FLEXPART_9.1.3/src/Makefile.ecmwf.lion
===================================================================
--- branches/FLEXPART_9.1.3/src/Makefile.ecmwf.lion	(revision 14)
+++ branches/FLEXPART_9.1.3/src/Makefile.ecmwf.lion	(revision 14)
@@ -0,0 +1,104 @@
+SHELL = /bin/bash
+MAIN = FLEXPART_GFORTRAN
+#
+
+FC       = gfortran
+#INCPATH  = /usr/local/ecmwf_tools/reloc/include
+#LIBPATH1 = /usr/local/ecmwf_tools/reloc/lib
+#LIBPATH2 = /usr/local/lib
+#FFLAGS   = -O3 -g -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+FFLAGS   = -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+#LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -lopenjpeg
+
+# options for nordre
+INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
+LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
+LIBPATH2 =   /usr/lib/x86_64-linux-gnu/
+#FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
+
+#options for Lion
+libs_dir=/Users/ignacio_in_EBCRPA/flexpart/libs/
+INCPATH  = $(libs_dir)/grib_api-1.9.9_dir/include
+LIBPATH1 = $(libs_dir)/grib_api-1.9.9_dir/lib
+LIBPATH2 = $(libs_dir)/jasper_dir/lib
+
+
+
+MODOBJS = \
+par_mod.o               com_mod.o \
+conv_mod.o              hanna_mod.o \
+interpol_mod.o          cmapf_mod.o \
+unc_mod.o               oh_mod.o \
+xmass_mod.o             flux_mod.o \
+point_mod.o             outg_mod.o
+
+OBJECTS = \
+writeheader.o           assignland.o\
+calcpar.o               part0.o \
+caldate.o               partdep.o \
+coordtrafo.o            psih.o \
+raerod.o \
+drydepokernel.o         random.o \
+readavailable.o \
+ew.o                    readcommand.o \
+advance.o               readdepo.o \
+releaseparticles.o      psim.o     \
+FLEXPART.o              readlanduse.o \
+getfields.o             init_domainfill.o\
+interpol_wind.o         readoutgrid.o \
+interpol_all.o          readpaths.o \
+getrb.o                 readreceptors.o \
+getrc.o                 readreleases.o \
+getvdep.o               readspecies.o \
+interpol_misslev.o      readwind.o \
+conccalc.o              richardson.o \
+concoutput.o            scalev.o \
+pbl_profile.o           readOHfield.o\
+juldate.o               timemanager.o \
+interpol_vdep.o         interpol_rain.o \
+verttransform.o         partoutput.o \
+hanna.o                 wetdepokernel.o \
+mean.o                  wetdepo.o \
+hanna_short.o           windalign.o \
+obukhov.o               gridcheck.o \
+hanna1.o                initialize.o \
+                        gridcheck_nests.o \
+readwind_nests.o        calcpar_nests.o \
+verttransform_nests.o   interpol_all_nests.o \
+interpol_wind_nests.o   interpol_misslev_nests.o \
+interpol_vdep_nests.o   interpol_rain_nests.o \
+getvdep_nests.o \
+readageclasses.o        readpartpositions.o \
+calcfluxes.o            fluxoutput.o \
+qvsat.o                 skplin.o \
+convmix.o               calcmatrix.o \
+convect43c.o               redist.o \
+sort2.o                 distance.o \
+centerofmass.o          plumetraj.o \
+openouttraj.o           calcpv.o \
+calcpv_nests.o          distance2.o \
+clustering.o            interpol_wind_short.o \
+interpol_wind_short_nests.o shift_field_0.o \
+shift_field.o           outgrid_init.o \
+openreceptors.o         boundcond_domainfill.o\
+partoutput_short.o      readoutgrid_nest.o \
+outgrid_init_nest.o     writeheader_nest.o \
+concoutput_nest.o       wetdepokernel_nest.o \
+drydepokernel_nest.o    zenithangle.o \
+ohreaction.o            getvdep_nests.o \
+initial_cond_calc.o     initial_cond_output.o \
+dynamic_viscosity.o     get_settling.o
+
+
+$(MAIN): $(MODOBJS) $(OBJECTS)
+	$(FC) *.o -o $(MAIN) $(LDFLAGS)
+
+$(OBJECTS): $(MODOBJS)
+
+%.o: %.f90
+	$(FC) -c $(FFLAGS) $<
+
+clean:
+	rm *.o *.mod
+
Index: branches/FLEXPART_9.1.3/src/Makefile.gfs
===================================================================
--- branches/FLEXPART_9.1.3/src/Makefile.gfs	(revision 14)
+++ branches/FLEXPART_9.1.3/src/Makefile.gfs	(revision 14)
@@ -0,0 +1,90 @@
+SHELL = /bin/bash
+MAIN = FLEXPART_GFS_GFORTRAN
+#
+
+FC       = gfortran
+INCPATH  = /usr/local/ecmwf_tools/reloc/include
+LIBPATH1 = /usr/local/ecmwf_tools/reloc/lib
+LIBPATH2 = /usr/local/lib
+#FFLAGS   = -O3 -g -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+FFLAGS   = -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -lopenjpeg
+#
+
+MODOBJS = \
+par_mod.o               com_mod.o \
+conv_mod.o              hanna_mod.o \
+interpol_mod.o          cmapf_mod.o \
+unc_mod.o               oh_mod.o \
+xmass_mod.o             flux_mod.o \
+point_mod.o             outg_mod.o
+
+OBJECTS = \
+writeheader.o           assignland.o\
+calcpar_gfs.o           part0.o \
+caldate.o               partdep.o \
+coordtrafo.o            psih.o \
+raerod.o \
+drydepokernel.o         random.o \
+erf.o			readavailable.o \
+ew.o                    readcommand.o \
+advance.o               readdepo.o \
+releaseparticles.o      psim.o     \
+FLEXPART.o              readlanduse.o \
+getfields.o             init_domainfill.o\
+interpol_wind.o         readoutgrid.o \
+interpol_all.o          readpaths.o \
+getrb.o                 readreceptors.o \
+getrc.o                 readreleases.o \
+getvdep.o               readspecies.o \
+interpol_misslev.o      readwind_gfs.o \
+conccalc.o              richardson_gfs.o \
+concoutput.o            scalev.o \
+pbl_profile.o           readOHfield.o\
+juldate.o               timemanager.o \
+interpol_vdep.o         interpol_rain.o \
+verttransform_gfs.o         partoutput.o \
+hanna.o                 wetdepokernel.o \
+mean.o                  wetdepo.o \
+hanna_short.o           windalign.o \
+obukhov_gfs.o           gridcheck_gfs.o \
+hanna1.o                initialize.o \
+                        gridcheck_nests.o \
+readwind_nests.o        calcpar_nests.o \
+verttransform_nests.o   interpol_all_nests.o \
+interpol_wind_nests.o   interpol_misslev_nests.o \
+interpol_vdep_nests.o   interpol_rain_nests.o \
+getvdep_nests.o \
+readageclasses.o        readpartpositions.o \
+calcfluxes.o            fluxoutput.o \
+qvsat.o                 skplin.o \
+convmix_gfs.o               calcmatrix_gfs.o \
+convect43c.o            redist.o \
+sort2.o                 distance.o \
+centerofmass.o          plumetraj.o \
+openouttraj.o           calcpv.o \
+calcpv_nests.o          distance2.o \
+clustering.o            interpol_wind_short.o \
+interpol_wind_short_nests.o shift_field_0.o \
+shift_field.o           outgrid_init.o \
+openreceptors.o         boundcond_domainfill.o\
+partoutput_short.o      readoutgrid_nest.o \
+outgrid_init_nest.o     writeheader_nest.o \
+concoutput_nest.o       wetdepokernel_nest.o \
+drydepokernel_nest.o    zenithangle.o \
+ohreaction.o            getvdep_nests.o \
+initial_cond_calc.o     initial_cond_output.o \
+dynamic_viscosity.o     get_settling.o
+
+
+$(MAIN): $(MODOBJS) $(OBJECTS)
+	$(FC) *.o -o $(MAIN) $(LDFLAGS)
+
+$(OBJECTS): $(MODOBJS)
+
+%.o: %.f90
+	$(FC) -c $(FFLAGS) $<
+
+clean:
+	rm *.o *.mod
+
Index: branches/FLEXPART_9.1.3/src/com_mod.f90
===================================================================
--- trunk/src/com_mod.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/com_mod.f90	(revision 14)
@@ -7,5 +7,5 @@
 !        June 1996                                                             *
 !                                                                              *
-!        Last update: 9 August 2000                                            *
+!        Last update:15 August 2013 IP                                         *
 !                                                                              *
 !*******************************************************************************
@@ -139,4 +139,6 @@
   real :: decay(maxspec)
   real :: weta(maxspec),wetb(maxspec)
+! NIK: 31.01.2013- parameters for in-cloud scavening
+  real :: weta_in(maxspec), wetb_in(maxspec), wetc_in(maxspec), wetd_in(maxspec)
   real :: reldiff(maxspec),henry(maxspec),f0(maxspec)
   real :: density(maxspec),dquer(maxspec),dsigma(maxspec)
@@ -172,5 +174,7 @@
 
   ! WET DEPOSITION
-  ! weta, wetb              parameters for determining wet scavenging coefficients
+  ! weta, wetb              parameters for determining below-cloud wet scavenging coefficients
+  ! weta_in, wetb_in       parameters for determining in-cloud wet scavenging coefficients
+  ! wetc_in, wetd_in       parameters for determining in-cloud wet scavenging coefficients
 
   ! GAS DEPOSITION
@@ -331,6 +335,10 @@
   real :: qvh(0:nxmax-1,0:nymax-1,nuvzmax,2)
   real :: pplev(0:nxmax-1,0:nymax-1,nuvzmax,2)
+  !scavenging NIK, PS
   integer(kind=1) :: clouds(0:nxmax-1,0:nymax-1,nzmax,2)
   integer :: cloudsh(0:nxmax-1,0:nymax-1,2)
+      integer icloudbot(0:nxmax-1,0:nymax-1,2)
+      integer icloudthck(0:nxmax-1,0:nymax-1,2)
+
 
   ! uu,vv,ww [m/2]       wind components in x,y and z direction
@@ -346,4 +354,8 @@
   !      rainout  conv/lsp dominated  2/3
   !      washout  conv/lsp dominated  4/5
+! PS 2013
+!c icloudbot (m)        cloud bottom height
+!c icloudthck (m)       cloud thickness     
+
   ! pplev for the GFS version
 
Index: branches/FLEXPART_9.1.3/src/com_mod.f90-9.1.1
===================================================================
--- branches/FLEXPART_9.1.3/src/com_mod.f90-9.1.1	(revision 14)
+++ branches/FLEXPART_9.1.3/src/com_mod.f90-9.1.1	(revision 14)
@@ -0,0 +1,674 @@
+!*******************************************************************************
+!        Include file for particle diffusion model FLEXPART                    *
+!        This file contains a global common block used by FLEXPART             *
+!                                                                              *
+!        Author: A. Stohl                                                      *
+!                                                                              *
+!        June 1996                                                             *
+!                                                                              *
+!        Last update: 9 August 2000                                            *
+!                                                                              *
+!*******************************************************************************
+
+module com_mod
+
+  use par_mod, only: dp, numpath, maxnests, maxageclass, maxspec, ni, &
+       numclass, nymax, nxmax, maxcolumn, maxwf, nzmax, nxmaxn, nymaxn, &
+       maxreceptor, maxpart, maxrand, nwzmax, nuvzmax
+
+  implicit none
+
+  !****************************************************************
+  ! Variables defining where FLEXPART input/output files are stored
+  !****************************************************************
+
+  character :: path(numpath+2*maxnests)*120
+  integer :: length(numpath+2*maxnests)
+
+  ! path                    path names needed for trajectory model
+  ! length                  length of path names needed for trajectory model
+
+
+  !********************************************************
+  ! Variables defining the general model run specifications
+  !********************************************************
+
+  integer :: ibdate,ibtime,iedate,ietime
+  real(kind=dp) :: bdate,edate
+
+
+  ! ibdate                  beginning date (YYYYMMDD)
+  ! ibtime                  beginning time (HHMISS)
+  ! iedate                  ending date (YYYYMMDD)
+  ! ietime                  ending time (HHMISS)
+  ! bdate                   beginning date of simulation (julian date)
+  ! edate                   ending date of simulation (julian date)
+
+
+  integer :: ldirect,ideltas
+
+  ! ldirect                 1 for forward, -1 for backward simulation
+  ! ideltas                 length of trajectory loop from beginning to
+  !                    ending date (s)
+
+  integer :: loutstep,loutaver,loutsample,method,lsynctime
+  real :: outstep
+
+  ! loutstep [s]            gridded concentration output every loutstep seconds
+  ! loutaver [s]            concentration output is an average over [s] seconds
+  ! loutsample [s]          sampling interval of gridded concentration output
+  ! lsynctime [s]           synchronisation time of all particles
+  ! method                  indicator which dispersion method is to be used
+  ! outstep = real(abs(loutstep))
+
+  real :: ctl,fine
+  integer :: ifine,iout,ipout,ipin,iflux,mdomainfill
+  integer :: mquasilag,nested_output,ind_source,ind_receptor
+  integer :: ind_rel,ind_samp,ioutputforeachrelease,linit_cond
+  logical :: turbswitch
+
+  ! ctl      factor, by which time step must be smaller than Lagrangian time scale
+  ! ifine    reduction factor for time step used for vertical wind
+  !     Langevin equation for the vertical wind component
+  ! ioutputforeachrelease Should each release be a seperate output field?
+  ! iflux    flux calculation options: 1 calculation of fluxes, 2 no fluxes
+  ! iout     output options: 1 conc. output (ng/m3), 2 mixing ratio (pptv), 3 both
+  ! ipout    particle dump options: 0 no, 1 every output interval, 2 only at end
+  ! ipin     read in particle positions from dumped file from a previous run
+  ! fine     real(ifine)
+  ! mdomainfill 0: normal run
+  !        1: particles are initialized according to atmospheric mass distribution
+  ! ind_source switches between different units for concentrations at the source
+  !  NOTE that in backward simulations the release of computational particles
+  !  takes place at the "receptor" and the sampling of particles at the "source".
+  !     1= mass units
+  !     2= mass mixing ratio units
+  ! ind_receptor switches between different units for FLEXPART concentration at the receptor
+  !     1= mass units
+  !     2= mass mixing ratio units
+  ! linit_cond  switch on the output of sensitivity to initial conditions for backward runs
+  !     0=no, 1=mass unit, 2=mass mixing ratio unit
+  ! mquasilag 0: normal run
+  !      1: Particle position output is produced in a condensed format and particles are numbered
+  ! nested_output: 0 no, 1 yes
+  ! turbswitch              determines how the Markov chain is formulated
+
+  ! ind_rel and ind_samp  are used within the code to change between mass and mass-mix (see readcommand.f)
+
+
+  integer :: mintime,itsplit
+
+  ! mintime                 minimum time step to be used by FLEXPART
+  ! itsplit                 time constant for splitting particles
+
+  integer :: lsubgrid,lconvection,lagespectra
+
+  ! lsubgrid     1 if subgrid topography parameterization switched on, 2 if not
+  ! lconvection  1 if convection parameterization switched on, 0 if not
+  ! lagespectra  1 if age spectra calculation switched on, 2 if not
+
+
+  integer :: nageclass,lage(maxageclass)
+
+  ! nageclass               number of ageclasses for the age spectra calculation
+  ! lage [s]                ageclasses for the age spectra calculation
+
+
+  logical :: gdomainfill
+
+  ! gdomainfill             .T., if domain-filling is global, .F. if not
+
+
+
+  !*********************************************************************
+  ! Variables defining the release locations, released species and their
+  ! properties, etc.
+  !*********************************************************************
+
+  !change Sabine Eckhardt, only save the first 1000 identifier for releasepoints
+  character :: compoint(1001)*45
+  integer :: numpoint
+  !sec, now dynamically allocated:
+  ! ireleasestart(maxpoint),ireleaseend(maxpoint)
+  !      real xpoint1(maxpoint),ypoint1(maxpoint)
+  !real xpoint2(maxpoint),ypoint2(maxpoint)
+  !real zpoint1(maxpoint),zpoint2(maxpoint)
+  !integer*2 kindz(maxpoint)
+  integer :: specnum(maxspec)
+  !real xmass(maxpoint,maxspec)
+  real :: decay(maxspec)
+  real :: weta(maxspec),wetb(maxspec)
+  real :: reldiff(maxspec),henry(maxspec),f0(maxspec)
+  real :: density(maxspec),dquer(maxspec),dsigma(maxspec)
+  real :: vsetaver(maxspec),cunningham(maxspec),weightmolar(maxspec)
+  real :: vset(maxspec,ni),schmi(maxspec,ni),fract(maxspec,ni)
+  real :: ri(5,numclass),rac(5,numclass),rcl(maxspec,5,numclass)
+  real :: rgs(maxspec,5,numclass),rlu(maxspec,5,numclass)
+  real :: rm(maxspec),dryvel(maxspec),kao(maxspec),ohreact(maxspec)
+  ! se  it is possible to associate a species with a second one to make transfer from gas to aerosol
+  integer :: spec_ass(maxspec)
+
+  real :: area_hour(maxspec,24),point_hour(maxspec,24)
+  real :: area_dow(maxspec,7),point_dow(maxspec,7)
+
+  !integer npart(maxpoint)
+  integer :: nspec,maxpointspec_act
+  character(len=10) :: species(maxspec)
+
+
+  ! compoint                comment, also "name" of each starting point
+  ! numpoint                actual number of trajectory starting/ending points
+  ! ireleasestart,ireleaseend [s] starting and ending time of each release
+  ! xmass                   total mass emitted
+  ! xpoint1,ypoint1         lower left coordinates of release area
+  ! xpoint2,ypoint2         upper right coordinates of release area
+  ! zpoint1,zpoint2         min./max. z-coordinates of release points
+  ! kindz                   1: zpoint is in m agl, 2: zpoint is in m asl
+  ! npart                   number of particles per release point
+  ! nspec                   number of different species allowed for one release
+  ! maxpointspec_act        number of releaspoints for which a different output shall be created
+  ! species                 name of species
+  ! decay                   decay constant of radionuclide
+
+  ! WET DEPOSITION
+  ! weta, wetb              parameters for determining wet scavenging coefficients
+
+  ! GAS DEPOSITION
+  ! reldiff                 diffusivitiy of species relative to diff. of H2O
+  ! henry [M/atm]           Henry constant
+  ! f0                      reactivity relative to that of O3
+  ! ri [s/m]                stomatal resistance
+  ! rcl [s/m]               lower canopy resistance
+  ! rgs [s/m]               ground resistance
+  ! rlu [s/m]               leaf cuticular resistance
+  ! rm [s/m]                mesophyll resistance
+  ! dryvel [m/s]            constant dry deposition velocity
+
+  ! PARTICLE DEPOSITION
+  ! density [kg/m3]         density of particles
+  ! dquer [m]               mean diameter of particles
+  ! dsigma                  dsigma=10 or dsigma=0.1 means that 68% of the
+  !                    mass are between 0.1*dquer and 10*dquer
+
+  ! fract                   mass fraction of each diameter interval
+  ! vset [m/s]              gravitational settling velocity in ni intervals
+  ! cunningham              Cunningham slip correction (strictly valid only near surface)
+  ! vsetaver [m/s]          average gravitational settling velocity
+  ! schmi                   Schmidt number**2/3 of each diameter interval
+  ! weightmolar [g/mol]     molecular weight
+
+  ! TIME VARIATION OF EMISSION
+  ! area_hour, point_hour   daily variation of emission strengths for area and point sources
+  ! area_dow, point_dow     day-of-week variation of emission strengths for area and point sources
+
+
+
+  !**********************************************************
+  ! Variables used for domain-filling trajectory calculations
+  !**********************************************************
+
+  integer :: nx_we(2),ny_sn(2)
+  integer :: numcolumn
+  integer :: numcolumn_we(2,0:nymax-1),numcolumn_sn(2,0:nxmax-1)
+  real :: zcolumn_we(2,0:nymax-1,maxcolumn)
+  real :: zcolumn_sn(2,0:nxmax-1,maxcolumn)
+  real :: xmassperparticle
+  real :: acc_mass_we(2,0:nymax-1,maxcolumn)
+  real :: acc_mass_sn(2,0:nxmax-1,maxcolumn)
+
+  ! nx_we(2)                x indices of western and eastern boundary of domain-filling
+  ! ny_sn(2)                y indices of southern and northern boundary of domain-filling
+  ! numcolumn_we            number of particles to be released within one column
+  !                    at the western and eastern boundary surfaces
+  ! numcolumn_sn            same as numcolumn_we, but for southern and northern domain boundary
+  ! numcolumn               maximum number of particles to be released within a single
+  !                    column
+  ! zcolumn_we              altitudes where particles are to be released
+  !                    at the western and eastern boundary surfaces
+  ! zcolumn_sn              same as zcolumn_we, but for southern and northern domain boundary
+  ! xmassperparticle        air mass per particle in the domain-filling traj. option
+  ! acc_mass_we             mass that has accumulated at the western and eastern boundary;
+  !                    if it exceeds xmassperparticle, a particle is released and
+  !                    acc_mass_we is reduced accordingly
+  ! acc_mass_sn             same as acc_mass_we, but for southern and northern domain boundary
+
+
+
+  !******************************************************************************
+  ! Variables associated with the ECMWF meteorological input data ("wind fields")
+  !******************************************************************************
+
+  integer :: numbwf,wftime(maxwf),lwindinterv
+  character(len=255) :: wfname(maxwf),wfspec(maxwf)
+
+  ! lwindinterv [s]         Interval between wind fields currently in memory
+  ! numbwf                  actual number of wind fields
+  ! wftime(maxwf) [s]       times relative to beginning time of wind fields
+  ! wfname(maxwf)           file names of wind fields
+  ! wfspec(maxwf)           specifications of wind field file, e.g. if on hard
+  !                    disc or on tape
+
+  integer :: memtime(2),memind(2)
+
+  ! memtime [s]             validation times of wind fields in memory
+  ! memind                  pointer to wind field, in order to avoid shuffling
+  !                    of wind fields
+
+
+
+  !****************************************************************************
+  ! Variables defining actual size and geographical location of the wind fields
+  !****************************************************************************
+
+  integer :: nx,ny,nxmin1,nymin1,nxfield,nuvz,nwz,nz,nmixz,nlev_ec
+  real :: dx,dy,xlon0,ylat0,dxconst,dyconst,height(nzmax)
+
+  ! nx,ny,nz                actual dimensions of wind fields in x,y and z
+  !                    direction, respectively
+  ! nxmin1,nymin1           nx-1, ny-1, respectively
+  ! nuvz,nwz                vertical dimension of original ECMWF data
+  ! nxfield                 same as nx for limited area fields,
+  !                    but for global fields nx=nxfield+1
+  ! nmixz                   number of levels up to maximum PBL height (3500 m)
+
+  ! nuvz is used for u,v components
+  ! nwz is used for w components (staggered grid)
+  ! nz is used for the levels in transformed coordinates (terrain-following Cartesian
+  ! coordinates)
+
+  ! nlev_ec  number of levels ECMWF model
+  ! dx                      grid distance in x direction
+  ! dy                      grid distance in y direction
+  ! dxconst,dyconst         auxiliary variables for utransform,vtransform
+  ! height                  heights of all levels
+  ! xlon0                   geographical longitude and
+  ! ylat0                   geographical latitude of lower left grid point
+
+
+
+  !*************************************************
+  ! Variables used for vertical model discretization
+  !*************************************************
+
+  real :: akm(nwzmax),bkm(nwzmax)
+  real :: akz(nuvzmax),bkz(nuvzmax)
+  real :: aknew(nzmax),bknew(nzmax)
+
+  ! akm,bkm: coeffizients which regulate vertical discretization of ecmwf model
+  !     (at the border of model layers)
+  ! akz,bkz: model discretization coeffizients at the centre of the layers
+  ! aknew,bknew model discretization coeffizients at the interpolated levels
+
+
+
+  ! Fixed fields, unchangeable with time
+  !*************************************
+
+  real :: oro(0:nxmax-1,0:nymax-1)
+  real :: excessoro(0:nxmax-1,0:nymax-1)
+  real :: lsm(0:nxmax-1,0:nymax-1)
+  real :: xlanduse(0:nxmax-1,0:nymax-1,numclass)
+
+  ! oro [m]              orography of the ECMWF model
+  ! excessoro            excess orography mother domain
+  ! lsm                  land sea mask of the ECMWF model
+  ! xlanduse [0-1]       area fractions in percent
+
+  ! 3d fields
+  !**********
+
+  real :: uu(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: vv(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: uupol(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: vvpol(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: ww(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: tt(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: qv(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: pv(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: rho(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: drhodz(0:nxmax-1,0:nymax-1,nzmax,2)
+  real :: tth(0:nxmax-1,0:nymax-1,nuvzmax,2)
+  real :: qvh(0:nxmax-1,0:nymax-1,nuvzmax,2)
+  real :: pplev(0:nxmax-1,0:nymax-1,nuvzmax,2)
+  integer(kind=1) :: clouds(0:nxmax-1,0:nymax-1,nzmax,2)
+  integer :: cloudsh(0:nxmax-1,0:nymax-1,2)
+
+  ! uu,vv,ww [m/2]       wind components in x,y and z direction
+  ! uupol,vvpol [m/s]    wind components in polar stereographic projection
+  ! tt [K]               temperature data
+  ! qv                   specific humidity data
+  ! pv (pvu)             potential vorticity
+  ! rho [kg/m3]          air density
+  ! drhodz [kg/m2]       vertical air density gradient
+  ! tth,qvh              tth,qvh on original eta levels
+  ! clouds:   no cloud, no precipitation   0
+  !      cloud, no precipitation      1
+  !      rainout  conv/lsp dominated  2/3
+  !      washout  conv/lsp dominated  4/5
+  ! pplev for the GFS version
+
+  ! 2d fields
+  !**********
+
+  real :: ps(0:nxmax-1,0:nymax-1,1,2)
+  real :: sd(0:nxmax-1,0:nymax-1,1,2)
+  real :: msl(0:nxmax-1,0:nymax-1,1,2)
+  real :: tcc(0:nxmax-1,0:nymax-1,1,2)
+  real :: u10(0:nxmax-1,0:nymax-1,1,2)
+  real :: v10(0:nxmax-1,0:nymax-1,1,2)
+  real :: tt2(0:nxmax-1,0:nymax-1,1,2)
+  real :: td2(0:nxmax-1,0:nymax-1,1,2)
+  real :: lsprec(0:nxmax-1,0:nymax-1,1,2)
+  real :: convprec(0:nxmax-1,0:nymax-1,1,2)
+  real :: sshf(0:nxmax-1,0:nymax-1,1,2)
+  real :: ssr(0:nxmax-1,0:nymax-1,1,2)
+  real :: surfstr(0:nxmax-1,0:nymax-1,1,2)
+  real :: ustar(0:nxmax-1,0:nymax-1,1,2)
+  real :: wstar(0:nxmax-1,0:nymax-1,1,2)
+  real :: hmix(0:nxmax-1,0:nymax-1,1,2)
+  real :: tropopause(0:nxmax-1,0:nymax-1,1,2)
+  real :: oli(0:nxmax-1,0:nymax-1,1,2)
+  real :: diffk(0:nxmax-1,0:nymax-1,1,2)
+
+  ! ps                   surface pressure
+  ! sd                   snow depth
+  ! msl                  mean sea level pressure
+  ! tcc                  total cloud cover
+  ! u10                  10 meter u
+  ! v10                  10 meter v
+  ! tt2                  2 meter temperature
+  ! td2                  2 meter dew point
+  ! lsprec [mm/h]        large scale total precipitation
+  ! convprec [mm/h]      convective precipitation
+  ! sshf                 surface sensible heat flux
+  ! ssr                  surface solar radiation
+  ! surfstr              surface stress
+  ! ustar [m/s]          friction velocity
+  ! wstar [m/s]          convective velocity scale
+  ! hmix  [m]            mixing height
+  ! tropopause [m]       altitude of thermal tropopause
+  ! oli [m]              inverse Obukhov length (1/L)
+  ! diffk [m2/s]         diffusion coefficient at reference height
+
+
+  real :: vdep(0:nxmax-1,0:nymax-1,maxspec,2)
+
+  ! vdep [m/s]           deposition velocities
+
+
+  !********************************************************************
+  ! Variables associated with the ECMWF input data (nested wind fields)
+  !********************************************************************
+
+  ! NOTE: all nested variables have the same name as the variables used
+  ! for the mother domain, except with a 'n' appended at the end
+  !********************************************************************
+
+  integer :: numbnests
+
+  ! numbnests    number of nested grids
+
+  character(len=255) :: wfnamen(maxnests,maxwf)
+  character(len=18) :: wfspecn(maxnests,maxwf)
+
+  ! wfnamen      nested wind field names
+  ! wfspecn      specifications of wind field file, e.g. if on hard
+  !         disc or on tape
+
+
+  !*********************************************************************
+  ! Variables characterizing size and location of the nested wind fields
+  !*********************************************************************
+
+  integer :: nxn(maxnests),nyn(maxnests)
+  real :: dxn(maxnests),dyn(maxnests),xlon0n(maxnests),ylat0n(maxnests)
+
+  ! nxn,nyn      actual dimensions of nested wind fields in x and y direction
+  ! dxn,dyn      grid distances in x,y direction for the nested grids
+  ! xlon0n       geographical longitude of lower left grid point of nested wind fields
+  ! ylat0n       geographical latitude of lower left grid point of nested wind fields
+
+
+  ! Nested fields, unchangeable with time
+  !**************************************
+
+  real :: oron(0:nxmaxn-1,0:nymaxn-1,maxnests)
+  real :: excessoron(0:nxmaxn-1,0:nymaxn-1,maxnests)
+  real :: lsmn(0:nxmaxn-1,0:nymaxn-1,maxnests)
+  real :: xlandusen(0:nxmaxn-1,0:nymaxn-1,numclass,maxnests)
+
+
+  ! 3d nested fields
+  !*****************
+
+  real :: uun(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: vvn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: wwn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: ttn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: qvn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: pvn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  integer(kind=1) :: cloudsn(0:nxmaxn-1,0:nymaxn-1,0:nzmax,2,maxnests)
+  integer :: cloudsnh(0:nxmaxn-1,0:nymaxn-1,2,maxnests)
+  real :: rhon(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: drhodzn(0:nxmaxn-1,0:nymaxn-1,nzmax,2,maxnests)
+  real :: tthn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,2,maxnests)
+  real :: qvhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,2,maxnests)
+
+  ! 2d nested fields
+  !*****************
+
+  real :: psn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: sdn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: msln(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: tccn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: u10n(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: v10n(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: tt2n(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: td2n(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: lsprecn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: convprecn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: sshfn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: ssrn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: surfstrn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: ustarn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: wstarn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: hmixn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: tropopausen(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: olin(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: diffkn(0:nxmaxn-1,0:nymaxn-1,1,2,maxnests)
+  real :: vdepn(0:nxmaxn-1,0:nymaxn-1,maxspec,2,maxnests)
+
+
+  !*************************************************
+  ! Certain auxiliary variables needed for the nests
+  !*************************************************
+
+  real :: xresoln(0:maxnests),yresoln(0:maxnests)
+
+  ! xresoln, yresoln   Factors by which the resolutions in the nests
+  !               are enhanced compared to mother grid
+
+  real :: xln(maxnests),yln(maxnests),xrn(maxnests),yrn(maxnests)
+
+  ! xln,yln,xrn,yrn    Corner points of nested grids in grid coordinates
+  !               of mother grid
+
+
+  !******************************************************
+  ! Variables defining the polar stereographic projection
+  !******************************************************
+
+  logical :: xglobal,sglobal,nglobal
+  real :: switchnorthg,switchsouthg
+
+  !xglobal             T for global fields, F for limited area fields
+  !sglobal             T if domain extends towards south pole
+  !nglobal             T if domain extends towards north pole
+  !switchnorthg,switchsouthg   same as parameters switchnorth,
+  !                    switchsouth, but in grid units
+
+  real :: southpolemap(9),northpolemap(9)
+
+  !southpolemap,northpolemap   define stereographic projections
+  !                    at the two poles
+
+
+  !******************
+  ! Landuse inventory
+  ! Sabine Eckhardt Dec 06: change to new landuse inventary - 11 classes, 1200 x 600 global
+  !******************
+
+  integer(kind=1) :: landinvent(1200,600,6)
+  real :: z0(numclass)
+
+  ! landinvent         landuse inventory (numclass=11 classes)
+  ! z0                  roughness length for the landuse classes
+
+
+
+  !**************************************************************************
+  ! Variables characterizing the output grid and containing the model results
+  !**************************************************************************
+
+  integer :: numxgrid,numygrid,numzgrid
+  real :: dxout,dyout,outlon0,outlat0,xoutshift,youtshift
+  integer :: numxgridn,numygridn
+  real :: dxoutn,dyoutn,outlon0n,outlat0n,xoutshiftn,youtshiftn
+  !real outheight(maxzgrid),outheighthalf(maxzgrid)
+  logical :: DEP,DRYDEP,DRYDEPSPEC(maxspec),WETDEP,OHREA,ASSSPEC
+
+  ! numxgrid,numygrid       number of grid points in x,y-direction
+  ! numxgridn,numygridn     number of grid points in x,y-direction for nested output grid
+  ! numzgrid                number of vertical levels of output grid
+  ! dxout,dyout             grid distance of output grid
+  ! dxoutn,dyoutn           grid distance of nested output grid
+  ! outlon0,outlat0         lower left corner of output grid
+  ! outlon0n,outlat0n       lower left corner of nested output grid
+  ! xoutshift,youtshift     xlon0-outlon0, ylat0-outlat0
+  ! xoutshiftn,youtshiftn   xlon0-outlon0n, ylat0-outlat0n
+  ! outheight [m]           upper levels of the output grid
+  ! outheighthalf [m]       half (middle) levels of the output grid cells
+  ! DEP                     .true., if either dry or wet depos. is switched on
+  ! DRYDEP                  .true., if dry deposition is switched on
+  ! DRYDEPSPEC              .true., if dry deposition is switched on for that species
+  ! WETDEP                  .true., if wet deposition is switched on
+  ! OHREA                   .true., if OH reaction is switched on
+  ! ASSSPEC                 .true., if there are two species asscoiated
+  !                    (i.e. transfer of mass between these two occurs
+
+
+
+  !  if output for each releasepoint shall be created maxpointspec=number of releasepoints
+  !  else maxpointspec is 1 -> moved to unc_mod
+  !  the OUTGRID is moved to the module outg_mod
+  !******************************************************************************
+
+  !real gridunc(0:maxxgrid-1,0:maxygrid-1,maxzgrid,maxspec,
+  !    +             maxpointspec_act,nclassunc,maxageclass)
+  !real griduncn(0:maxxgridn-1,0:maxygridn-1,maxzgrid,maxspec,
+  !    +              maxpointspec_act,nclassunc,maxageclass)
+  !real wetgridunc(0:maxxgrid-1,0:maxygrid-1,maxspec,
+  !    +                maxpointspec_act,nclassunc,maxageclass)
+  !real wetgriduncn(0:maxxgridn-1,0:maxygridn-1,maxspec,
+  !    +ct                 maxpointspec,nclassunc,maxageclass)
+  !real drygridunc(0:maxxgrid-1,0:maxygrid-1,maxspec,maxpointspec,
+  !    +                nclassunc,maxageclass)
+  !real drygriduncn(0:maxxgridn-1,0:maxygridn-1,maxspec,
+  !    +                 maxpointspec,nclassunc,maxageclass)
+
+  !real oroout(0:maxxgrid-1,0:maxygrid-1)
+  !real orooutn(0:maxxgridn-1,0:maxygridn-1)
+  !     real area(0:maxxgrid-1,0:maxygrid-1)
+  !real arean(0:maxxgridn-1,0:maxygridn-1)
+  !real volume(0:maxxgrid-1,0:maxygrid-1,maxzgrid)
+  !real volumen(0:maxxgridn-1,0:maxygridn-1,maxzgrid)
+
+  !real areaeast(0:maxxgrid-1,0:maxygrid-1,maxzgrid)
+  !real areanorth(0:maxxgrid-1,0:maxygrid-1,maxzgrid)
+
+
+  ! gridunc,griduncn        uncertainty of outputted concentrations
+  ! wetgridunc,wetgriduncn  uncertainty of accumulated wet deposited mass on output grid
+  ! drygridunc,drygriduncn  uncertainty of accumulated dry deposited mass on output grid
+  ! oroout,orooutn [m]      height of model topography at output grid
+  ! area,arean [m2]         area of each grid cell
+  ! volume,volumen [m3]     volume of each grid cell
+  ! ... field names with n at the end indicate a nested output grid
+
+
+  !***********************************
+  ! Variables defining receptor points
+  !***********************************
+
+  real :: xreceptor(maxreceptor),yreceptor(maxreceptor)
+  real :: receptorarea(maxreceptor)
+  real :: creceptor(maxreceptor,maxspec)
+  character(len=16) :: receptorname(maxreceptor)
+  integer :: numreceptor
+
+  ! xreceptor,yreceptor     receptor position
+  ! creceptor               concentrations at receptor points
+  ! receptorarea            area of 1*1 grid cell at receptor point
+
+
+
+  !***************************************
+  ! Variables characterizing each particle
+  !***************************************
+
+  integer :: numpart,itra1(maxpart)
+  integer :: npoint(maxpart),nclass(maxpart)
+  integer :: idt(maxpart),itramem(maxpart),itrasplit(maxpart)
+  integer :: numparticlecount
+
+  real(kind=dp) :: xtra1(maxpart),ytra1(maxpart)
+  real :: ztra1(maxpart),xmass1(maxpart,maxspec)
+
+  ! numpart                 actual number of particles in memory
+  ! itra1 (maxpart) [s]     temporal positions of the particles
+  ! npoint(maxpart)         indicates the release point of each particle
+  ! nclass (maxpart)        one of nclassunc classes to which the particle is attributed
+  ! itramem (maxpart) [s]   memorized release times of the particles
+  ! itrasplit (maxpart) [s] next time when particle is to be split into two
+  ! idt(maxpart) [s]        time step to be used for next integration
+  ! numparticlecount        counts the total number of particles that have been released
+  ! xtra1,ytra1,ztra1       spatial positions of the particles
+  ! xmass1 [kg]             particle masses
+
+
+
+  !*******************************************************
+  ! Info table on available chemical species/radionuclides
+  !*******************************************************
+
+  !character*10 specname(maxtable)
+  !real decaytime(maxtable),wetscava(maxtable),wetscavb(maxtable)
+  !real drydiff(maxtable),dryhenry(maxtable),dryactiv(maxtable)
+  !real partrho(maxtable),partmean(maxtable),partsig(maxtable)
+  !real dryvelo(maxtable),weightmol(maxtable),ohreact(maxtable)
+
+  ! specname            Name of chemical species/radionuclide
+  ! decaytime           Half time of radionuclides
+  ! wetscava, wetscavb  Parameters for calculating scavenging coefficients
+  ! drydiff             diffusivitiy of species relative to diff. of H2O
+  ! dryhenry [M/atm]    Henry constant
+  ! dryactiv            reactivity relative to that of O3
+  ! partrho [kg/m3]     density of particles
+  ! partmean [m]        mean diameter of particles
+  ! partsig [m]         mean stand. deviation of particle diameter
+  ! dryvelo [cm/s]      constant dry deposition velocity
+  ! weightmol [g/mol]   molecular weight
+  ! ohreact             OH reaction rate
+
+
+
+  !********************
+  ! Random number field
+  !********************
+
+  real :: rannumb(maxrand)
+
+  ! rannumb                 field of normally distributed random numbers
+
+
+end module com_mod
Index: branches/FLEXPART_9.1.3/src/concoutput.f90
===================================================================
--- trunk/src/concoutput.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/concoutput.f90	(revision 14)
@@ -158,5 +158,5 @@
         yl=outlat0+real(jy)*dyout
         xl=(xl-xlon0)/dx
-        yl=(yl-ylat0)/dx
+        yl=(yl-ylat0)/dy !v9.1.1 
         iix=max(min(nint(xl),nxmin1),0)
         jjy=max(min(nint(yl),nymin1),0)
Index: branches/FLEXPART_9.1.3/src/erf.f90
===================================================================
--- trunk/src/erf.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/erf.f90	(revision 14)
@@ -42,10 +42,10 @@
 
   integer :: j
-  real :: x,tmp,ser,xx,gammln
-  real :: cof(6) = (/ &
+  real(kind=dp) :: x,tmp,ser,xx,gammln
+  real(KIND=dp) :: cof(6) = (/ &
        76.18009173_dp, -86.50532033_dp, 24.01409822_dp, &
        -1.231739516_dp, .120858003e-2_dp, -.536382e-5_dp    /)
-  real :: stp = 2.50662827465_dp
-  real :: half = 0.5_dp, one = 1.0_dp, fpf = 5.5_dp
+  real(KIND=dp) :: stp = 2.50662827465_dp
+  real(KIND=dp) :: half = 0.5_dp, one = 1.0_dp, fpf = 5.5_dp
 
   x=xx-one
@@ -62,7 +62,9 @@
 function gammp(a,x)
 
-  implicit none
-
-  real :: a, x, gln, gamser, gammp, gammcf
+  use par_mod, only: dp
+
+  implicit none
+
+  real(KIND=dp) :: a, x, gln, gamser, gammp, gammcf
 
   if(x .lt. 0. .or. a .le. 0.) then
@@ -81,7 +83,9 @@
 function gammq(a,x)
 
-  implicit none
-
-  real :: a, x, gln, gamser, gammq, gammcf
+  use par_mod, only: dp
+
+  implicit none
+
+  real(KIND=dp) :: a, x, gln, gamser, gammq, gammcf
 
   if(x.lt.0..or.a.le.0.) then
@@ -100,9 +104,11 @@
 subroutine gser(gamser,a,x,gln)
 
+  use par_mod, only: dp
+
   implicit none
 
   integer :: n
-  real :: gamser, a, x, gln, ap, summ, del
-  real, external :: gammln
+  real(KIND=dp) :: gamser, a, x, gln, ap, summ, del
+  real(KIND=dp), external :: gammln
 
   integer,parameter :: itmax=100
@@ -134,9 +140,11 @@
 subroutine gcf(gammcf,a,x,gln)
 
+  use par_mod, only: dp
+
   implicit none
 
   integer :: n
-  real :: gammcf, a, x, gln, gold, a0, a1, b0, b1, fac, an, anf, ana, g
-  real, external :: gammln
+  real(KIND=4) :: gammcf, x, a, gln, gold, a0, a1, b0, b1, fac, an, anf, ana, g
+  real(KIND=dp), external :: gammln
 
   integer,parameter :: itmax=100
@@ -172,8 +180,10 @@
 function erf(x)
 
-  implicit none
-
-  real :: x, erf
-  real, external :: gammp
+  use par_mod, only: dp
+
+  implicit none
+
+  real(KIND=dp) :: x, erf
+  real(KIND=dp), external :: gammp
 
   if(x.lt.0.)then
@@ -186,8 +196,10 @@
 function erfc(x)
 
-  implicit none
-
-  real :: x, erfc
-  real, external :: gammp, gammq
+  use par_mod, only: dp
+
+  implicit none
+
+  real(KIND=dp) :: x, erfc
+  real(KIND=dp), external :: gammp, gammq
 
   if(x.lt.0.)then
@@ -200,7 +212,9 @@
 function erfcc(x)
 
-  implicit none
-
-  real :: x, z, t, erfcc
+  use par_mod, only: dp
+
+  implicit none
+
+  real(KIND=dp) :: x, z, t, erfcc
 
   z=abs(x)
Index: branches/FLEXPART_9.1.3/src/gridcheck.f90
===================================================================
--- trunk/src/gridcheck.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/gridcheck.f90	(revision 14)
@@ -98,5 +98,6 @@
 
   integer :: isec1(56),isec2(22+nxmax+nymax)
-  real(kind=4) :: zsec2(60+2*nuvzmax),zsec4(jpunp)
+  !real(kind=4) :: zsec2(60+2*nuvzmax),zsec4(jpunp)
+  real(kind=4) :: zsec2(184),zsec4(jpunp)
   character(len=1) :: opt
 
@@ -466,5 +467,4 @@
     k=nlev_ec+1+numskip+i
     akm(nwz-i+1)=zsec2(j)
-  !   write (*,*) 'ifield:',ifield,k,j,zsec2(10+j)
     bkm(nwz-i+1)=zsec2(k)
   end do
Index: branches/FLEXPART_9.1.3/src/gridcheck_emos.f90
===================================================================
--- trunk/src/gridcheck_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,396 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine gridcheck
-
-  !**********************************************************************
-  !                                                                     *
-  !             FLEXPART MODEL SUBROUTINE GRIDCHECK                     *
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  !             AUTHOR:      G. WOTAWA                                  *
-  !             DATE:        1997-08-06                                 *
-  !             LAST UPDATE: 1997-10-10                                 *
-  !                                                                     *
-  !             Update:      1999-02-08, global fields allowed, A. Stohl*
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  ! DESCRIPTION:                                                        *
-  !                                                                     *
-  ! THIS SUBROUTINE DETERMINES THE GRID SPECIFICATIONS (LOWER LEFT      *
-  ! LONGITUDE, LOWER LEFT LATITUDE, NUMBER OF GRID POINTS, GRID DIST-   *
-  ! ANCE AND VERTICAL DISCRETIZATION OF THE ECMWF MODEL) FROM THE       *
-  ! GRIB HEADER OF THE FIRST INPUT FILE. THE CONSISTANCY (NO CHANGES    *
-  ! WITHIN ONE FLEXPART RUN) IS CHECKED IN THE ROUTINE "READWIND" AT    *
-  ! ANY CALL.                                                           *
-  !                                                                     *
-  ! XLON0                geographical longitude of lower left gridpoint *
-  ! YLAT0                geographical latitude of lower left gridpoint  *
-  ! NX                   number of grid points x-direction              *
-  ! NY                   number of grid points y-direction              *
-  ! DX                   grid distance x-direction                      *
-  ! DY                   grid distance y-direction                      *
-  ! NUVZ                 number of grid points for horizontal wind      *
-  !                      components in z direction                      *
-  ! NWZ                  number of grid points for vertical wind        *
-  !                      component in z direction                       *
-  ! sizesouth, sizenorth give the map scale (i.e. number of virtual grid*
-  !                      points of the polar stereographic grid):       *
-  !                      used to check the CFL criterion                *
-  ! UVHEIGHT(1)-         heights of gridpoints where u and v are        *
-  ! UVHEIGHT(NUVZ)       given                                          *
-  ! WHEIGHT(1)-          heights of gridpoints where w is given         *
-  ! WHEIGHT(NWZ)                                                        *
-  !                                                                     *
-  !**********************************************************************
-  
-  use par_mod
-  use com_mod
-  use conv_mod
-
-  implicit none
-
-  integer :: ix,jy,i,ifn,ifield,j,k,iumax,iwmax,numskip
-  real :: xaux1,xaux2,yaux1,yaux2,sizesouth,sizenorth,xauxa,pint
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmax+nymax),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,ierr,iword,lunit
-  !integer iswap
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  character(len=1) :: opt, yoper = 'D'
-
-
-  iumax=0
-  iwmax=0
-
-  if(ideltas.gt.0) then
-    ifn=1
-  else
-    ifn=numbwf
-  endif
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(3)(1:length(3))//wfname(ifn),'r',ierr)
-  if(ierr.lt.0) goto 999
-
-  ifield=0
-10   ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-  call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-  if(ierr.eq.-1) goto 30    ! EOF DETECTED
-  if(ierr.lt.-1) goto 999   ! ERROR DETECTED
-
-  ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !  iswap=1+ilen/4
-  !  call swap32(inbuff,iswap)
-  !else if (inbuff(1).ne.1196575042) then    ! big endian
-  !  stop 'subroutine gridcheck: corrupt GRIB data'
-  !endif
-
-  call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-       zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-  if (ierr.ne.0) goto 999   ! ERROR DETECTED
-
-  if(ifield.eq.1) then
-    nxfield=isec2(2)
-    ny=isec2(3)
-    xaux1=real(isec2(5))/1000.
-    xaux2=real(isec2(8))/1000.
-    if (xaux1.gt.180) xaux1=xaux1-360.0
-    if (xaux2.gt.180) xaux2=xaux2-360.0
-    if (xaux1.lt.-180) xaux1=xaux1+360.0
-    if (xaux2.lt.-180) xaux2=xaux2+360.0
-    if (xaux2.lt.xaux1) xaux2=xaux2+360.
-    yaux1=real(isec2(7))/1000.
-    yaux2=real(isec2(4))/1000.
-    xlon0=xaux1
-    ylat0=yaux1
-    dx=(xaux2-xaux1)/real(nxfield-1)
-    dy=(yaux2-yaux1)/real(ny-1)
-    dxconst=180./(dx*r_earth*pi)
-    dyconst=180./(dy*r_earth*pi)
-    nlev_ec=isec2(12)/2-1
-
-
-  ! Check whether fields are global
-  ! If they contain the poles, specify polar stereographic map
-  ! projections using the stlmbr- and stcm2p-calls
-  !***********************************************************
-
-    xauxa=abs(xaux2+dx-360.-xaux1)
-    if (xauxa.lt.0.001) then
-      nx=nxfield+1                 ! field is cyclic
-      xglobal=.true.
-      if (abs(nxshift).ge.nx) &
-           stop 'nxshift in file par_mod is too large'
-      xlon0=xlon0+real(nxshift)*dx
-    else
-      nx=nxfield
-      xglobal=.false.
-      if (nxshift.ne.0) &
-           stop 'nxshift (par_mod) must be zero for non-global domain'
-    endif
-    nxmin1=nx-1
-    nymin1=ny-1
-    if (xlon0.gt.180.) xlon0=xlon0-360.
-    xauxa=abs(yaux1+90.)
-    if (xglobal.and.xauxa.lt.0.001) then
-      sglobal=.true.               ! field contains south pole
-  ! Enhance the map scale by factor 3 (*2=6) compared to north-south
-  ! map scale
-      sizesouth=6.*(switchsouth+90.)/dy
-      call stlmbr(southpolemap,-90.,0.)
-      call stcm2p(southpolemap,0.,0.,switchsouth,0.,sizesouth, &
-           sizesouth,switchsouth,180.)
-      switchsouthg=(switchsouth-ylat0)/dy
-    else
-      sglobal=.false.
-      switchsouthg=999999.
-    endif
-    xauxa=abs(yaux2-90.)
-    if (xglobal.and.xauxa.lt.0.001) then
-      nglobal=.true.               ! field contains north pole
-  ! Enhance the map scale by factor 3 (*2=6) compared to north-south
-  ! map scale
-      sizenorth=6.*(90.-switchnorth)/dy
-      call stlmbr(northpolemap,90.,0.)
-      call stcm2p(northpolemap,0.,0.,switchnorth,0.,sizenorth, &
-           sizenorth,switchnorth,180.)
-      switchnorthg=(switchnorth-ylat0)/dy
-    else
-      nglobal=.false.
-      switchnorthg=999999.
-    endif
-  endif
-
-  if (nxshift.lt.0) stop 'nxshift (par_mod) must not be negative'
-  if (nxshift.ge.nxfield) stop 'nxshift (par_mod) too large'
-
-  k=isec1(8)
-  if(isec1(6).eq.131) iumax=max(iumax,nlev_ec-k+1)
-  if(isec1(6).eq.135) iwmax=max(iwmax,nlev_ec-k+1)
-
-  if(isec1(6).eq.129) then
-    do jy=0,ny-1
-      do ix=0,nxfield-1
-  !       write (*,*) 'ich stop!',nxfield,ny,jy,ix,ga
-  !       stop
-        oro(ix,jy)=zsec4(nxfield*(ny-jy-1)+ix+1)/ga
-      end do
-    end do
-  endif
-  if(isec1(6).eq.172) then
-    do jy=0,ny-1
-      do ix=0,nxfield-1
-        lsm(ix,jy)=zsec4(nxfield*(ny-jy-1)+ix+1)
-      end do
-    end do
-  endif
-  if(isec1(6).eq.160) then
-    do jy=0,ny-1
-      do ix=0,nxfield-1
-        excessoro(ix,jy)=zsec4(nxfield*(ny-jy-1)+ix+1)
-      end do
-    end do
-  endif
-
-  goto 10                      !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-30   call pbclose(lunit,ierr)     !! FINISHED READING / CLOSING GRIB FILE
-
-  nuvz=iumax
-  nwz =iwmax
-  if(nuvz.eq.nlev_ec) nwz=nlev_ec+1
-
-  if (nx.gt.nxmax) then
-   write(*,*) 'FLEXPART error: Too many grid points in x direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nx,nxmax
-    stop
-  endif
-
-  if (ny.gt.nymax) then
-   write(*,*) 'FLEXPART error: Too many grid points in y direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) ny,nymax
-    stop
-  endif
-
-  if (nuvz+1.gt.nuvzmax) then
-    write(*,*) 'FLEXPART error: Too many u,v grid points in z '// &
-         'direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nuvz+1,nuvzmax
-    stop
-  endif
-
-  if (nwz.gt.nwzmax) then
-    write(*,*) 'FLEXPART error: Too many w grid points in z '// &
-         'direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nwz,nwzmax
-    stop
-  endif
-
-  ! If desired, shift all grids by nxshift grid cells
-  !**************************************************
-
-  if (xglobal) then
-    call shift_field_0(oro,nxfield,ny)
-    call shift_field_0(lsm,nxfield,ny)
-    call shift_field_0(excessoro,nxfield,ny)
-  endif
-
-  ! Output of grid info
-  !********************
-
-  write(*,*)
-  write(*,*)
-  write(*,'(a,2i7)') '# of vertical levels in ECMWF data: ', &
-       nuvz+1,nwz
-  write(*,*)
-  write(*,'(a)') 'Mother domain:'
-  write(*,'(a,f10.2,a1,f10.2,a,f10.2)') '  Longitude range: ', &
-       xlon0,' to ',xlon0+(nx-1)*dx,'   Grid distance: ',dx
-  write(*,'(a,f10.2,a1,f10.2,a,f10.2)') '  Latitude range: ', &
-       ylat0,' to ',ylat0+(ny-1)*dy,'   Grid distance: ',dy
-  write(*,*)
-
-
-  ! CALCULATE VERTICAL DISCRETIZATION OF ECMWF MODEL
-  ! PARAMETER akm,bkm DESCRIBE THE HYBRID "ETA" COORDINATE SYSTEM
-
-  numskip=nlev_ec-nuvz  ! number of ecmwf model layers not used
-                        ! by trajectory model
-  do i=1,nwz
-    j=numskip+i
-    k=nlev_ec+1+numskip+i
-    akm(nwz-i+1)=zsec2(10+j)
-    bkm(nwz-i+1)=zsec2(10+k)
-  end do
-
-  !
-  ! CALCULATION OF AKZ, BKZ
-  ! AKZ,BKZ: model discretization parameters at the center of each model
-  !     layer
-  !
-  ! Assign the 10 m winds to an artificial model level with akz=0 and bkz=1.0,
-  ! i.e. ground level
-  !*****************************************************************************
-
-  akz(1)=0.
-  bkz(1)=1.0
-  do i=1,nuvz
-     akz(i+1)=0.5*(akm(i+1)+akm(i))
-     bkz(i+1)=0.5*(bkm(i+1)+bkm(i))
-  end do
-  nuvz=nuvz+1
-
-  ! NOTE: In FLEXPART versions up to 4.0, the number of model levels was doubled
-  ! upon the transformation to z levels. In order to save computer memory, this is
-  ! not done anymore in the standard version. However, this option can still be
-  ! switched on by replacing the following lines with those below, that are
-  ! currently commented out. For this, similar changes are necessary in
-  ! verttransform.f and verttranform_nests.f
-  !*****************************************************************************
-
-  nz=nuvz
-  if (nz.gt.nzmax) stop 'nzmax too small'
-  do i=1,nuvz
-    aknew(i)=akz(i)
-    bknew(i)=bkz(i)
-  end do
-
-  ! Switch on following lines to use doubled vertical resolution
-  !*************************************************************
-  !nz=nuvz+nwz-1
-  !if (nz.gt.nzmax) stop 'nzmax too small'
-  !do 100 i=1,nwz
-  !  aknew(2*(i-1)+1)=akm(i)
-  !00     bknew(2*(i-1)+1)=bkm(i)
-  !do 110 i=2,nuvz
-  !  aknew(2*(i-1))=akz(i)
-  !10     bknew(2*(i-1))=bkz(i)
-  ! End doubled vertical resolution
-
-
-  ! Determine the uppermost level for which the convection scheme shall be applied
-  ! by assuming that there is no convection above 50 hPa (for standard SLP)
-  !*****************************************************************************
-
-  do i=1,nuvz-2
-    pint=akz(i)+bkz(i)*101325.
-    if (pint.lt.5000.) goto 96
-  end do
-96   nconvlev=i
-  if (nconvlev.gt.nconvlevmax-1) then
-    nconvlev=nconvlevmax-1
-    write(*,*) 'Attention, convection only calculated up to ', &
-         akz(nconvlev)+bkz(nconvlev)*1013.25,' hPa'
-  endif
-
-  return
-
-999   write(*,*)
-  write(*,*) ' ###########################################'// &
-       '###### '
-  write(*,*) '       TRAJECTORY MODEL SUBROUTINE GRIDCHECK:'
-  write(*,*) ' CAN NOT OPEN INPUT DATA FILE '//wfname(ifn)
-  write(*,*) ' ###########################################'// &
-       '###### '
-  write(*,*)
-  write(*,'(a)') '!!! PLEASE INSERT A NEW CD-ROM AND   !!!'
-  write(*,'(a)') '!!! PRESS ANY KEY TO CONTINUE...     !!!'
-  write(*,'(a)') '!!! ...OR TERMINATE FLEXPART PRESSING!!!'
-  write(*,'(a)') '!!! THE "X" KEY...                   !!!'
-  write(*,*)
-  read(*,'(a)') opt
-  if(opt.eq.'X') then
-    stop
-  else
-    goto 5
-  endif
-
-end subroutine gridcheck
Index: branches/FLEXPART_9.1.3/src/gridcheck_gfs_emos.f90
===================================================================
--- trunk/src/gridcheck_gfs_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,425 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine gridcheck
-
-  !**********************************************************************
-  !                                                                     *
-  !             FLEXPART MODEL SUBROUTINE GRIDCHECK                     *
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  !             AUTHOR:      G. WOTAWA                                  *
-  !             DATE:        1997-08-06                                 *
-  !             LAST UPDATE: 1997-10-10                                 *
-  !                                                                     *
-  !             Update:      1999-02-08, global fields allowed, A. Stohl*
-  !             CHANGE: 17/11/2005, Caroline Forster, GFS data          *
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  ! DESCRIPTION:                                                        *
-  !                                                                     *
-  ! THIS SUBROUTINE DETERMINES THE GRID SPECIFICATIONS (LOWER LEFT      *
-  ! LONGITUDE, LOWER LEFT LATITUDE, NUMBER OF GRID POINTS, GRID DIST-   *
-  ! ANCE AND VERTICAL DISCRETIZATION OF THE ECMWF MODEL) FROM THE       *
-  ! GRIB HEADER OF THE FIRST INPUT FILE. THE CONSISTANCY (NO CHANGES    *
-  ! WITHIN ONE FLEXPART RUN) IS CHECKED IN THE ROUTINE "READWIND" AT    *
-  ! ANY CALL.                                                           *
-  !                                                                     *
-  ! XLON0                geographical longitude of lower left gridpoint *
-  ! YLAT0                geographical latitude of lower left gridpoint  *
-  ! NX                   number of grid points x-direction              *
-  ! NY                   number of grid points y-direction              *
-  ! DX                   grid distance x-direction                      *
-  ! DY                   grid distance y-direction                      *
-  ! NUVZ                 number of grid points for horizontal wind      *
-  !                      components in z direction                      *
-  ! NWZ                  number of grid points for vertical wind        *
-  !                      component in z direction                       *
-  ! sizesouth, sizenorth give the map scale (i.e. number of virtual grid*
-  !                      points of the polar stereographic grid):       *
-  !                      used to check the CFL criterion                *
-  ! UVHEIGHT(1)-         heights of gridpoints where u and v are        *
-  ! UVHEIGHT(NUVZ)       given                                          *
-  ! WHEIGHT(1)-          heights of gridpoints where w is given         *
-  ! WHEIGHT(NWZ)                                                        *
-  !                                                                     *
-  !**********************************************************************
-  
-  use par_mod
-  use com_mod
-  use conv_mod
-
-  implicit none
-
-  integer :: ix,jy,i,ifn,ifield,j,k,iumax,iwmax,numskip
-  real :: xaux1,xaux2,yaux1,yaux2,sizesouth,sizenorth,xauxa,pint
-  real :: akm_usort(nwzmax)
-
-  ! NCEP GFS
-  real :: pres(nwzmax), help
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmax+nymax),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,iswap,ierr,iword,lunit
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  character(len=1) :: opt, yoper = 'D'
-
-
-  iumax=0
-  iwmax=0
-
-  if(ideltas.gt.0) then
-    ifn=1
-  else
-    ifn=numbwf
-  endif
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(3)(1:length(3))//wfname(ifn),'r',ierr)
-  if(ierr.lt.0) goto 999
-
-  ifield=0
-10   ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-  call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-  if(ierr.eq.-1) goto 30    ! EOF DETECTED
-  if(ierr.lt.-1) goto 999   ! ERROR DETECTED
-
-  ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !  iswap=1+ilen/4
-  !  call swap32(inbuff,iswap)
-  !else if (inbuff(1).ne.1196575042) then    ! big endian
-  !  stop 'subroutine gridcheck: corrupt GRIB data'
-  !endif
-
-  call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-       zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-  if (ierr.ne.0) goto 10   ! ERROR DETECTED
-
-  if(ifield.eq.1) then
-    nxfield=isec2(2)
-    ny=isec2(3)
-    xaux1=real(isec2(5))/1000.
-    xaux2=real(isec2(8))/1000.
-    if((xaux1.eq.0.).and.(xaux2.eq.-1.0)) then ! NCEP DATA FROM 0 TO
-      xaux1=-179.0                             ! 359 DEG EAST ->
-      xaux2=180.0                              ! TRANSFORMED TO -179
-    endif                                      ! TO 180 DEG EAST
-    if (xaux1.gt.180) xaux1=xaux1-360.0
-    if (xaux2.gt.180) xaux2=xaux2-360.0
-    if (xaux1.lt.-180) xaux1=xaux1+360.0
-    if (xaux2.lt.-180) xaux2=xaux2+360.0
-    if (xaux2.lt.xaux1) xaux2=xaux2+360.
-    yaux1=real(isec2(7))/1000.
-    yaux2=real(isec2(4))/1000.
-    xlon0=xaux1
-    ylat0=yaux1
-    dx=(xaux2-xaux1)/real(nxfield-1)
-    dy=(yaux2-yaux1)/real(ny-1)
-    dxconst=180./(dx*r_earth*pi)
-    dyconst=180./(dy*r_earth*pi)
-
-
-  ! Check whether fields are global
-  ! If they contain the poles, specify polar stereographic map
-  ! projections using the stlmbr- and stcm2p-calls
-  !***********************************************************
-
-    xauxa=abs(xaux2+dx-360.-xaux1)
-    if (xauxa.lt.0.001) then
-      nx=nxfield+1                 ! field is cyclic
-      xglobal=.true.
-      if (abs(nxshift).ge.nx) &
-           stop 'nxshift in file par_mod is too large'
-      xlon0=xlon0+real(nxshift)*dx
-    else
-      nx=nxfield
-      xglobal=.false.
-      if (nxshift.ne.0) &
-           stop 'nxshift (par_mod) must be zero for non-global domain'
-    endif
-    nxmin1=nx-1
-    nymin1=ny-1
-    if (xlon0.gt.180.) xlon0=xlon0-360.
-    xauxa=abs(yaux1+90.)
-    if (xglobal.and.xauxa.lt.0.001) then
-      sglobal=.true.               ! field contains south pole
-  ! Enhance the map scale by factor 3 (*2=6) compared to north-south
-  ! map scale
-      sizesouth=6.*(switchsouth+90.)/dy
-      call stlmbr(southpolemap,-90.,0.)
-      call stcm2p(southpolemap,0.,0.,switchsouth,0.,sizesouth, &
-           sizesouth,switchsouth,180.)
-      switchsouthg=(switchsouth-ylat0)/dy
-    else
-      sglobal=.false.
-      switchsouthg=999999.
-    endif
-    xauxa=abs(yaux2-90.)
-    if (xglobal.and.xauxa.lt.0.001) then
-      nglobal=.true.               ! field contains north pole
-  ! Enhance the map scale by factor 3 (*2=6) compared to north-south
-  ! map scale
-      sizenorth=6.*(90.-switchnorth)/dy
-      call stlmbr(northpolemap,90.,0.)
-      call stcm2p(northpolemap,0.,0.,switchnorth,0.,sizenorth, &
-           sizenorth,switchnorth,180.)
-      switchnorthg=(switchnorth-ylat0)/dy
-    else
-      nglobal=.false.
-      switchnorthg=999999.
-    endif
-  endif
-
-  if (nxshift.lt.0) stop 'nxshift (par_mod) must not be negative'
-  if (nxshift.ge.nxfield) stop 'nxshift (par_mod) too large'
-
-  ! NCEP ISOBARIC LEVELS
-  !*********************
-
-  if((isec1(6).eq.33).and.(isec1(7).eq.100)) then
-    iumax=iumax+1
-    pres(iumax)=real(isec1(8))*100.0
-  endif
-
-  ! NCEP TERRAIN
-  !*************
-
-  if((isec1(6).eq.007).and.(isec1(7).eq.001)) then
-    do jy=0,ny-1
-      do ix=0,nxfield-1
-        help=zsec4(nxfield*(ny-jy-1)+ix+1)
-        if(ix.le.180) then
-          oro(179+ix,jy)=help
-          excessoro(179+ix,jy)=0.0 ! ISOBARIC SURFACES: SUBGRID TERRAIN DISREGARDED
-        else
-          oro(ix-181,jy)=help
-          excessoro(ix-181,jy)=0.0 ! ISOBARIC SURFACES: SUBGRID TERRAIN DISREGARDED
-        endif
-      end do
-    end do
-  endif
-
-  ! NCEP LAND SEA MASK
-  !*******************
-
-  if((isec1(6).eq.081).and.(isec1(7).eq.001)) then
-    do jy=0,ny-1
-      do ix=0,nxfield-1
-        help=zsec4(nxfield*(ny-jy-1)+ix+1)
-        if(ix.le.180) then
-          lsm(179+ix,jy)=help
-        else
-          lsm(ix-181,jy)=help
-        endif
-      end do
-    end do
-  endif
-
-  goto 10                      !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-30   call pbclose(lunit,ierr)     !! FINISHED READING / CLOSING GRIB FILE
-
-  nuvz=iumax
-  nwz =iumax
-  nlev_ec=iumax
-
-  if (nx.gt.nxmax) then
-   write(*,*) 'FLEXPART error: Too many grid points in x direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nx,nxmax
-    stop
-  endif
-
-  if (ny.gt.nymax) then
-   write(*,*) 'FLEXPART error: Too many grid points in y direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) ny,nymax
-    stop
-  endif
-
-  if (nuvz.gt.nuvzmax) then
-    write(*,*) 'FLEXPART error: Too many u,v grid points in z '// &
-         'direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nuvz,nuvzmax
-    stop
-  endif
-
-  if (nwz.gt.nwzmax) then
-    write(*,*) 'FLEXPART error: Too many w grid points in z '// &
-         'direction.'
-    write(*,*) 'Reduce resolution of wind fields.'
-    write(*,*) 'Or change parameter settings in file par_mod.'
-    write(*,*) nwz,nwzmax
-    stop
-  endif
-
-  ! If desired, shift all grids by nxshift grid cells
-  !**************************************************
-
-  if (xglobal) then
-    call shift_field_0(oro,nxfield,ny)
-    call shift_field_0(lsm,nxfield,ny)
-    call shift_field_0(excessoro,nxfield,ny)
-  endif
-
-  ! Output of grid info
-  !********************
-
-  write(*,*)
-  write(*,*)
-  write(*,'(a,2i7)') '# of vertical levels in ECMWF data: ', &
-       nuvz,nwz
-  write(*,*)
-  write(*,'(a)') 'Mother domain:'
-  write(*,'(a,f10.1,a1,f10.1,a,f10.1)') '  Longitude range: ', &
-       xlon0,' to ',xlon0+(nx-1)*dx,'   Grid distance: ',dx
-  write(*,'(a,f10.1,a1,f10.1,a,f10.1)') '  Latitude range: ', &
-       ylat0,' to ',ylat0+(ny-1)*dy,'   Grid distance: ',dy
-  write(*,*)
-
-
-  ! CALCULATE VERTICAL DISCRETIZATION OF ECMWF MODEL
-  ! PARAMETER akm,bkm DESCRIBE THE HYBRID "ETA" COORDINATE SYSTEM
-
-  numskip=nlev_ec-nuvz  ! number of ecmwf model layers not used
-                        ! by trajectory model
-  do i=1,nwz
-    j=numskip+i
-    k=nlev_ec+1+numskip+i
-    akm_usort(nwz-i+1)=pres(nwz-i+1)
-    bkm(nwz-i+1)=0.0
-  end do
-
-  !******************************
-  ! change Sabine Eckhardt: akm should always be in descending order ... readwind adapted!
-  !******************************
-      do i=1,nwz
-         if (akm_usort(1).gt.akm_usort(2)) then
-            akm(i)=akm_usort(i)
-         else
-            akm(i)=akm_usort(nwz-i+1)
-         endif
-      end do
-
-  !
-  ! CALCULATION OF AKZ, BKZ
-  ! AKZ,BKZ: model discretization parameters at the center of each model
-  !     layer
-  !
-  ! Assign the 10 m winds to an artificial model level with akz=0 and bkz=1.0,
-  ! i.e. ground level
-  !*****************************************************************************
-
-  do i=1,nuvz
-     akz(i)=akm(i)
-     bkz(i)=bkm(i)
-  end do
-
-  ! NOTE: In FLEXPART versions up to 4.0, the number of model levels was doubled
-  ! upon the transformation to z levels. In order to save computer memory, this is
-  ! not done anymore in the standard version. However, this option can still be
-  ! switched on by replacing the following lines with those below, that are
-  ! currently commented out. For this, similar changes are necessary in
-  ! verttransform.f and verttranform_nests.f
-  !*****************************************************************************
-
-  nz=nuvz
-  if (nz.gt.nzmax) stop 'nzmax too small'
-  do i=1,nuvz
-    aknew(i)=akz(i)
-    bknew(i)=bkz(i)
-  end do
-
-  ! Switch on following lines to use doubled vertical resolution
-  !*************************************************************
-  !nz=nuvz+nwz-1
-  !if (nz.gt.nzmax) stop 'nzmax too small'
-  !do 100 i=1,nwz
-  !  aknew(2*(i-1)+1)=akm(i)
-  !00     bknew(2*(i-1)+1)=bkm(i)
-  !do 110 i=2,nuvz
-  !  aknew(2*(i-1))=akz(i)
-  !10     bknew(2*(i-1))=bkz(i)
-  ! End doubled vertical resolution
-
-
-  ! Determine the uppermost level for which the convection scheme shall be applied
-  ! by assuming that there is no convection above 50 hPa (for standard SLP)
-  !*****************************************************************************
-
-  do i=1,nuvz-2
-    pint=akz(i)+bkz(i)*101325.
-    if (pint.lt.5000.) goto 96
-  end do
-96   nconvlev=i
-  if (nconvlev.gt.nconvlevmax-1) then
-    nconvlev=nconvlevmax-1
-    write(*,*) 'Attention, convection only calculated up to ', &
-         akz(nconvlev)+bkz(nconvlev)*1013.25,' hPa'
-  endif
-
-  return
-
-999   write(*,*)
-  write(*,*) ' ###########################################'// &
-       '###### '
-  write(*,*) '       TRAJECTORY MODEL SUBROUTINE GRIDCHECK:'
-  write(*,*) ' CAN NOT OPEN INPUT DATA FILE '//wfname(ifn)
-  write(*,*) ' ###########################################'// &
-       '###### '
-  write(*,*)
-  write(*,'(a)') '!!! PLEASE INSERT A NEW CD-ROM AND   !!!'
-  write(*,'(a)') '!!! PRESS ANY KEY TO CONTINUE...     !!!'
-  write(*,'(a)') '!!! ...OR TERMINATE FLEXPART PRESSING!!!'
-  write(*,'(a)') '!!! THE "X" KEY...                   !!!'
-  write(*,*)
-  read(*,'(a)') opt
-  if(opt.eq.'X') then
-    stop
-  else
-    goto 5
-  endif
-
-end subroutine gridcheck
Index: branches/FLEXPART_9.1.3/src/gridcheck_nests_emos.f90
===================================================================
--- trunk/src/gridcheck_nests_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,301 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine gridcheck_nests
-
-  !*****************************************************************************
-  !                                                                            *
-  !     This routine checks the grid specification for the nested model        *
-  !     domains. It is similar to subroutine gridcheck, which checks the       *
-  !     mother domain.                                                         *
-  !                                                                            *
-  !     Authors: A. Stohl, G. Wotawa                                           *
-  !                                                                            *
-  !     8 February 1999                                                        *
-  !                                                                            *
-  !*****************************************************************************
-
-  use par_mod
-  use com_mod
-
-  implicit none
-
-  integer :: i,j,k,l,ifn,ifield,iumax,iwmax,numskip,nlev_ecn
-  integer :: nuvzn,nwzn
-  real :: akmn(nwzmax),bkmn(nwzmax),akzn(nuvzmax),bkzn(nuvzmax)
-  real :: xaux1,xaux2,yaux1,yaux2
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmaxn+nymaxn),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,ierr,iword,lunit
-  !integer iswap
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  character(len=1) :: yoper = 'D'
-
-  xresoln(0)=1.       ! resolution enhancement for mother grid
-  yresoln(0)=1.       ! resolution enhancement for mother grid
-
-  ! Loop about all nesting levels
-  !******************************
-
-  do l=1,numbnests
-
-    iumax=0
-    iwmax=0
-
-    if(ideltas.gt.0) then
-      ifn=1
-    else
-      ifn=numbwf
-    endif
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(numpath+2*(l-1)+1) &
-         (1:length(numpath+2*(l-1)+1))//wfnamen(l,ifn),'r',ierr)
-    if(ierr.lt.0) goto 999
-
-    ifield=0
-10    ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-      call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-      if(ierr.eq.-1) goto 30    ! EOF DETECTED
-      if(ierr.lt.-1) goto 999   ! ERROR DETECTED
-
-      ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !    if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !      iswap=1+ilen/4
-  !      call swap32(inbuff,iswap)
-  !    else if (inbuff(1).ne.1196575042) then    ! big endian
-  !      stop 'subroutine gridcheck: corrupt GRIB data'
-  !    endif
-
-      call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-           zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-      if (ierr.ne.0) goto 999   ! ERROR DETECTED
-
-      if(ifield.eq.1) then
-        nxn(l)=isec2(2)
-        nyn(l)=isec2(3)
-        xaux1=real(isec2(5))/1000.
-        xaux2=real(isec2(8))/1000.
-        if(xaux1.gt.180) xaux1=xaux1-360.0
-        if(xaux2.gt.180) xaux2=xaux2-360.0
-        if(xaux1.lt.-180) xaux1=xaux1+360.0
-        if(xaux2.lt.-180) xaux2=xaux2+360.0
-        if (xaux2.lt.xaux1) xaux2=xaux2+360.
-        yaux1=real(isec2(7))/1000.
-        yaux2=real(isec2(4))/1000.
-        xlon0n(l)=xaux1
-        ylat0n(l)=yaux1
-        dxn(l)=(xaux2-xaux1)/real(nxn(l)-1)
-        dyn(l)=(yaux2-yaux1)/real(nyn(l)-1)
-        nlev_ecn=isec2(12)/2-1
-      endif
-
-
-      k=isec1(8)
-      if(isec1(6).eq.131) iumax=max(iumax,nlev_ec-k+1)
-      if(isec1(6).eq.135) iwmax=max(iwmax,nlev_ec-k+1)
-
-      if(isec1(6).eq.129) then
-      do j=0,nyn(l)-1
-        do i=0,nxn(l)-1
-          oron(i,j,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)/ga
-        end do
-      end do
-      endif
-      if(isec1(6).eq.172) then
-      do j=0,nyn(l)-1
-        do i=0,nxn(l)-1
-          lsmn(i,j,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)/ga
-        end do
-      end do
-      endif
-      if(isec1(6).eq.160) then
-      do j=0,nyn(l)-1
-        do i=0,nxn(l)-1
-          excessoron(i,j,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)/ga
-        end do
-      end do
-      endif
-
-      goto 10                 !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-30   call pbclose(lunit,ierr)     !! FINISHED READING / CLOSING GRIB FILE
-
-    nuvzn=iumax
-    nwzn=iwmax
-    if(nuvzn.eq.nlev_ec) nwzn=nlev_ecn+1
-
-    if (nxn(l).gt.nxmaxn) then
-  write(*,*) 'FLEXPART error: Too many grid points in x direction.'
-  write(*,*) 'Reduce resolution of wind fields (file GRIDSPEC)'
-  write(*,*) 'for nesting level ',l
-  write(*,*) 'Or change parameter settings in file par_mod.'
-  write(*,*) nxn(l),nxmaxn
-      stop
-    endif
-
-    if (nyn(l).gt.nymaxn) then
-  write(*,*) 'FLEXPART error: Too many grid points in y direction.'
-  write(*,*) 'Reduce resolution of wind fields (file GRIDSPEC)'
-  write(*,*) 'for nesting level ',l
-  write(*,*) 'Or change parameter settings in file par_mod.'
-  write(*,*) nyn(l),nymaxn
-      stop
-    endif
-
-    if ((nuvzn.gt.nuvzmax).or.(nwzn.gt.nwzmax)) then
-  write(*,*) 'FLEXPART error: Nested wind fields have too many'// &
-       'vertical levels.'
-  write(*,*) 'Problem was encountered for nesting level ',l
-      stop
-    endif
-
-
-  ! Output of grid info
-  !********************
-
-  write(*,'(a,i2)') 'Nested domain #: ',l
-  write(*,'(a,f10.2,a1,f10.2,a,f10.2)') '  Longitude range: ', &
-       xlon0n(l),' to ',xlon0n(l)+(nxn(l)-1)*dxn(l), &
-       '   Grid distance: ',dxn(l)
-  write(*,'(a,f10.2,a1,f10.2,a,f10.2)') '  Latitude range: ', &
-       ylat0n(l),' to ',ylat0n(l)+(nyn(l)-1)*dyn(l), &
-       '   Grid distance: ',dyn(l)
-  write(*,*)
-
-  ! Determine, how much the resolutions in the nests are enhanced as
-  ! compared to the mother grid
-  !*****************************************************************
-
-    xresoln(l)=dx/dxn(l)
-    yresoln(l)=dy/dyn(l)
-
-  ! Determine the mother grid coordinates of the corner points of the
-  ! nested grids
-  ! Convert first to geographical coordinates, then to grid coordinates
-  !********************************************************************
-
-    xaux1=xlon0n(l)
-    xaux2=xlon0n(l)+real(nxn(l)-1)*dxn(l)
-    yaux1=ylat0n(l)
-    yaux2=ylat0n(l)+real(nyn(l)-1)*dyn(l)
-
-    xln(l)=(xaux1-xlon0)/dx
-    xrn(l)=(xaux2-xlon0)/dx
-    yln(l)=(yaux1-ylat0)/dy
-    yrn(l)=(yaux2-ylat0)/dy
-
-
-    if ((xln(l).lt.0.).or.(yln(l).lt.0.).or. &
-         (xrn(l).gt.real(nxmin1)).or.(yrn(l).gt.real(nymin1))) then
-      write(*,*) 'Nested domain does not fit into mother domain'
-      write(*,*) 'For global mother domain fields, you can shift'
-      write(*,*) 'shift the mother domain into x-direction'
-      write(*,*) 'by setting nxshift (file par_mod) to a'
-      write(*,*) 'positive value. Execution is terminated.'
-      stop
-    endif
-
-
-  ! CALCULATE VERTICAL DISCRETIZATION OF ECMWF MODEL
-  ! PARAMETER akm,bkm DESCRIBE THE HYBRID "ETA" COORDINATE SYSTEM
-
-    numskip=nlev_ecn-nuvzn ! number of ecmwf model layers not used by FLEXPART
-    do i=1,nwzn
-      j=numskip+i
-      k=nlev_ecn+1+numskip+i
-      akmn(nwzn-i+1)=zsec2(10+j)
-      bkmn(nwzn-i+1)=zsec2(10+k)
-    end do
-
-  !
-  ! CALCULATION OF AKZ, BKZ
-  ! AKZ,BKZ: model discretization parameters at the center of each model
-  !     layer
-  !
-  ! Assign the 10 m winds to an artificial model level with akz=0 and bkz=1.0,
-  ! i.e. ground level
-  !*****************************************************************************
-
-    akzn(1)=0.
-    bkzn(1)=1.0
-    do i=1,nuvzn
-      akzn(i+1)=0.5*(akmn(i+1)+akmn(i))
-      bkzn(i+1)=0.5*(bkmn(i+1)+bkmn(i))
-    end do
-    nuvzn=nuvzn+1
-
-  ! Check, whether the heights of the model levels of the nested
-  ! wind fields are consistent with those of the mother domain.
-  ! If not, terminate model run.
-  !*************************************************************
-
-    do i=1,nuvz
-      if ((akzn(i).ne.akz(i)).or.(bkzn(i).ne.bkz(i))) then
-  write(*,*) 'FLEXPART error: The wind fields of nesting level',l
-  write(*,*) 'are not consistent with the mother domain:'
-  write(*,*) 'Differences in vertical levels detected.'
-        stop
-      endif
-    end do
-
-    do i=1,nwz
-      if ((akmn(i).ne.akm(i)).or.(bkmn(i).ne.bkm(i))) then
-  write(*,*) 'FLEXPART error: The wind fields of nesting level',l
-  write(*,*) 'are not consistent with the mother domain:'
-  write(*,*) 'Differences in vertical levels detected.'
-        stop
-      endif
-    end do
-
-  end do
-
-  return
-
-999   write(*,*)
-  write(*,*) ' ###########################################'// &
-       '###### '
-  write(*,*) '                FLEXPART SUBROUTINE GRIDCHECK:'
-  write(*,*) ' CAN NOT OPEN INPUT DATA FILE '//wfnamen(l,ifn)
-  write(*,*) ' FOR NESTING LEVEL ',k
-  write(*,*) ' ###########################################'// &
-       '###### '
-  stop
-
-end subroutine gridcheck_nests
Index: branches/FLEXPART_9.1.3/src/interpol_rain.f90
===================================================================
--- trunk/src/interpol_rain.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/interpol_rain.f90	(revision 14)
@@ -20,8 +20,15 @@
 !**********************************************************************
 
-subroutine interpol_rain(yy1,yy2,yy3,nxmax,nymax,nzmax,nx, &
-       ny,memind,xt,yt,level,itime1,itime2,itime,yint1,yint2,yint3)
-  !                          i   i   i    i    i     i   i
-  !i    i    i  i    i     i      i      i     o     o     o
+!subroutine interpol_rain(yy1,yy2,yy3,nxmax,nymax,nzmax,nx, &
+!       ny,memind,xt,yt,level,itime1,itime2,itime,yint1,yint2,yint3)
+!  !                          i   i   i    i    i     i   i
+!  !i    i    i  i    i     i      i      i     o     o     o
+
+      subroutine interpol_rain(yy1,yy2,yy3,iy1,iy2,nxmax,nymax,nzmax,nx, &
+     ny,memind,xt,yt,level,itime1,itime2,itime,yint1,yint2,yint3, &
+     intiy1,intiy2,icmv)
+!                               i   i   i    i    i     i   i 
+!     i    i    i  i    i     i      i      i     o     o     o
+
   !****************************************************************************
   !                                                                           *
@@ -40,5 +47,8 @@
   !                                                                           *
   !     30 August 1996                                                        *
-  !                                                                           *
+  !
+  !*  Petra Seibert, 2011/2012:
+  !*  Add interpolation of cloud bottom and cloud thickness
+  !*  for fix to SE's new wet scavenging scheme  *
   !****************************************************************************
   !                                                                           *
@@ -70,10 +80,15 @@
 
   integer :: nx,ny,nxmax,nymax,nzmax,memind(2),m,ix,jy,ixp,jyp
-  integer :: itime,itime1,itime2,level,indexh
+  !integer :: itime,itime1,itime2,level,indexh
+  integer :: itime,itime1,itime2,level,indexh,ip1,ip2,ip3,ip4 
+  integer :: intiy1,intiy2,ipsum,icmv  
   real :: yy1(0:nxmax-1,0:nymax-1,nzmax,2)
   real :: yy2(0:nxmax-1,0:nymax-1,nzmax,2)
   real :: yy3(0:nxmax-1,0:nymax-1,nzmax,2)
-  real :: ddx,ddy,rddx,rddy,dt1,dt2,dt,y1(2),y2(2),y3(2)
-  real :: xt,yt,yint1,yint2,yint3,p1,p2,p3,p4
+  integer iy1(0:nxmax-1,0:nymax-1,2),iy2(0:nxmax-1,0:nymax-1,2)
+  real :: ddx,ddy,rddx,rddy,dt1,dt2,dt,y1(2),y2(2),y3(2),yi1(2),yi2(2)
+  !real :: ddx,ddy,rddx,rddy,dt1,dt2,dt,y1(2),y2(2),y3(2)
+  real :: xt,yt,yint1,yint2,yint3,yint4,p1,p2,p3,p4  
+  !real :: xt,yt,yint1,yint2,yint3,p1,p2,p3,p4
 
 
@@ -127,4 +142,43 @@
          + p3*yy3(ix ,jyp,level,indexh) &
          + p4*yy3(ixp,jyp,level,indexh)
+
+!CPS clouds:
+        ip1=1
+        ip2=1
+        ip3=1
+        ip4=1
+        if (iy1(ix ,jy ,indexh) .eq. icmv) ip1=0
+        if (iy1(ixp,jy ,indexh) .eq. icmv) ip2=0
+        if (iy1(ix ,jyp,indexh) .eq. icmv) ip3=0
+        if (iy1(ixp,jyp,indexh) .eq. icmv) ip4=0
+        ipsum= ip1+ip2+ip3+ip4
+        if (ipsum .eq. 0) then
+          yi1(m)=icmv
+        else
+          yi1(m)=(ip1*p1*iy1(ix ,jy ,indexh)    &
+             + ip2*p2*iy1(ixp,jy ,indexh)       &
+             + ip3*p3*iy1(ix ,jyp,indexh)       &
+             + ip4*p4*iy1(ixp,jyp,indexh))/ipsum
+        endif
+        
+        ip1=1
+        ip2=1
+        ip3=1
+        ip4=1
+        if (iy2(ix ,jy ,indexh) .eq. icmv) ip1=0
+        if (iy2(ixp,jy ,indexh) .eq. icmv) ip2=0
+        if (iy2(ix ,jyp,indexh) .eq. icmv) ip3=0
+        if (iy2(ixp,jyp,indexh) .eq. icmv) ip4=0
+        ipsum= ip1+ip2+ip3+ip4
+        if (ipsum .eq. 0) then
+          yi2(m)=icmv
+        else
+          yi2(m)=(ip1*p1*iy2(ix ,jy ,indexh)  &
+             + ip2*p2*iy2(ixp,jy ,indexh)     &
+             + ip3*p3*iy2(ix ,jyp,indexh)     &
+             + ip4*p4*iy2(ixp,jyp,indexh))/ipsum
+        endif
+!CPS end clouds
+
   end do
 
@@ -134,4 +188,11 @@
   !************************************
 
+      if (itime .lt. itime1) then
+        print*,'interpol_rain.f90'
+        print*,itime,itime1,itime2
+        stop 'ITIME PROBLEM'
+      endif
+
+
   dt1=real(itime-itime1)
   dt2=real(itime2-itime)
@@ -143,3 +204,20 @@
 
 
+!PS clouds:
+      intiy1=(yi1(1)*dt2 + yi1(2)*dt1)/dt
+      if (yi1(1) .eq. float(icmv)) intiy1=yi1(2) 
+      if (yi1(2) .eq. float(icmv)) intiy1=yi1(1) 
+
+      intiy2=(yi2(1)*dt2 + yi2(2)*dt1)/dt
+      if (yi2(1) .eq. float(icmv)) intiy2=yi2(2)  
+      if (yi2(2) .eq. float(icmv)) intiy2=yi2(1) 
+      
+      if (intiy1 .ne. icmv .and. intiy2 .ne. icmv) then
+        intiy2 = intiy1 + intiy2 ! convert cloud thickness to cloud top
+      else
+        intiy1=icmv
+        intiy2=icmv
+      endif
+!PS end clouds
+
 end subroutine interpol_rain
Index: branches/FLEXPART_9.1.3/src/logfile
===================================================================
--- branches/FLEXPART_9.1.3/src/logfile	(revision 14)
+++ branches/FLEXPART_9.1.3/src/logfile	(revision 14)
@@ -0,0 +1,10 @@
+FLEXPART 9.1 from 
+svn/FlexPart90/branches/flexpart91_hasod/src 
+Assume that HS started from the trunk version (9.02)
+
+
+FLEXPART 9.1.1 (build 1) add changes in SE's version (trunk)
+
+FLEXPART 9.1.2 add NIK's additions
+
+FLEXPART 9.1.3 add PS  
Index: branches/FLEXPART_9.1.3/src/makefile
===================================================================
--- branches/FLEXPART_9.1.3/src/makefile	(revision 14)
+++ branches/FLEXPART_9.1.3/src/makefile	(revision 14)
@@ -0,0 +1,104 @@
+SHELL = /bin/bash
+MAIN = FLEXPART_GFORTRAN
+#
+
+FC       = gfortran
+#INCPATH  = /usr/local/ecmwf_tools/reloc/include
+#LIBPATH1 = /usr/local/ecmwf_tools/reloc/lib
+#LIBPATH2 = /usr/local/lib
+#FFLAGS   = -O3 -g -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+FFLAGS   = -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+#LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -lopenjpeg
+
+# options for nordre
+INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
+LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
+LIBPATH2 =   /usr/lib/x86_64-linux-gnu/
+#FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
+LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
+
+#options for Lion
+libs_dir=/Users/ignacio_in_EBCRPA/flexpart/libs/
+INCPATH  = $(libs_dir)/grib_api-1.9.9_dir/include
+LIBPATH1 = $(libs_dir)/grib_api-1.9.9_dir/lib
+LIBPATH2 = $(libs_dir)/jasper_dir/lib
+
+
+
+MODOBJS = \
+par_mod.o               com_mod.o \
+conv_mod.o              hanna_mod.o \
+interpol_mod.o          cmapf_mod.o \
+unc_mod.o               oh_mod.o \
+xmass_mod.o             flux_mod.o \
+point_mod.o             outg_mod.o
+
+OBJECTS = \
+writeheader.o           assignland.o\
+calcpar.o               part0.o \
+caldate.o               partdep.o \
+coordtrafo.o            psih.o \
+raerod.o \
+drydepokernel.o         random.o \
+readavailable.o \
+ew.o                    readcommand.o \
+advance.o               readdepo.o \
+releaseparticles.o      psim.o     \
+FLEXPART.o              readlanduse.o \
+getfields.o             init_domainfill.o\
+interpol_wind.o         readoutgrid.o \
+interpol_all.o          readpaths.o \
+getrb.o                 readreceptors.o \
+getrc.o                 readreleases.o \
+getvdep.o               readspecies.o \
+interpol_misslev.o      readwind.o \
+conccalc.o              richardson.o \
+concoutput.o            scalev.o \
+pbl_profile.o           readOHfield.o\
+juldate.o               timemanager.o \
+interpol_vdep.o         interpol_rain.o \
+verttransform.o         partoutput.o \
+hanna.o                 wetdepokernel.o \
+mean.o                  wetdepo.o \
+hanna_short.o           windalign.o \
+obukhov.o               gridcheck.o \
+hanna1.o                initialize.o \
+                        gridcheck_nests.o \
+readwind_nests.o        calcpar_nests.o \
+verttransform_nests.o   interpol_all_nests.o \
+interpol_wind_nests.o   interpol_misslev_nests.o \
+interpol_vdep_nests.o   interpol_rain_nests.o \
+getvdep_nests.o \
+readageclasses.o        readpartpositions.o \
+calcfluxes.o            fluxoutput.o \
+qvsat.o                 skplin.o \
+convmix.o               calcmatrix.o \
+convect43c.o               redist.o \
+sort2.o                 distance.o \
+centerofmass.o          plumetraj.o \
+openouttraj.o           calcpv.o \
+calcpv_nests.o          distance2.o \
+clustering.o            interpol_wind_short.o \
+interpol_wind_short_nests.o shift_field_0.o \
+shift_field.o           outgrid_init.o \
+openreceptors.o         boundcond_domainfill.o\
+partoutput_short.o      readoutgrid_nest.o \
+outgrid_init_nest.o     writeheader_nest.o \
+concoutput_nest.o       wetdepokernel_nest.o \
+drydepokernel_nest.o    zenithangle.o \
+ohreaction.o            getvdep_nests.o \
+initial_cond_calc.o     initial_cond_output.o \
+dynamic_viscosity.o     get_settling.o
+
+
+$(MAIN): $(MODOBJS) $(OBJECTS)
+	$(FC) *.o -o $(MAIN) $(LDFLAGS)
+
+$(OBJECTS): $(MODOBJS)
+
+%.o: %.f90
+	$(FC) -c $(FFLAGS) $<
+
+clean:
+	rm *.o *.mod
+
Index: branches/FLEXPART_9.1.3/src/makefile.ecmwf_absoft
===================================================================
--- trunk/src/makefile.ecmwf_absoft	(revision 14)
+++ 	(revision )
@@ -1,92 +1,0 @@
-SHELL = /bin/bash
-MAIN = FLEXPART
-INCF	= incl* 
-#
-
-FC       = /opt/absoft10.1/bin/f90
-#FC       = /opt/absoft11.5/bin/f95
-INCPATH  = /nilu2/home/flexpart/lib64/absoft/include
-LIBPATH1 = /nilu2/home/flexpart/lib64/absoft/lib
-LIBPATH2 = /nilu2/home/flexpart/lib64/absoft/lib
-FFLAGS   =   -O2 -I$(INCPATH) -p$(INCPATH) -m64 -mcmodel=medium
-#FFLAGS   =  -g -Rb -Rc -Rs  -s -I$(INCPATH) -p$(INCPATH) -m64 -mcmodel=medium
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar.o               part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-                        raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind.o \
-conccalc.o              richardson.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov.o               gridcheck.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix.o               calcmatrix.o \
-convect43c.o               redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-%.o: %.f90
-	$(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
-
Index: branches/FLEXPART_9.1.3/src/makefile.ecmwf_gfortran
===================================================================
--- trunk/src/makefile.ecmwf_gfortran	(revision 14)
+++ branches/FLEXPART_9.1.3/src/makefile.ecmwf_gfortran	(revision 14)
@@ -9,5 +9,4 @@
 LIBPATH2 =   /usr/lib/x86_64-linux-gnu/
 #LIBPATH2 =   /flex_wrk/flexpart/lib64/gfortran/lib/
-#FFLAGS   =   -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
 FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
 #FFLAGS   =   -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
Index: branches/FLEXPART_9.1.3/src/makefile.ecmwf_gfortran_jfb
===================================================================
--- trunk/src/makefile.ecmwf_gfortran_jfb	(revision 14)
+++ 	(revision )
@@ -1,91 +1,0 @@
-SHELL = /bin/bash
-MAIN = FP_ecmwf_gfortran
-#
-
-FC       = gfortran
-INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
-LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
-LIBPATH2 = /xnilu_wrk/flex_wrk/lib64/jasper/lib
-#FFLAGS   =   -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-#FFLAGS   =   -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar.o               part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind.o \
-conccalc.o              richardson.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov.o               gridcheck.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix.o               calcmatrix.o \
-convect43c.o               redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-%.o: %.f90
-	$(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
Index: branches/FLEXPART_9.1.3/src/makefile.gfs_absoft
===================================================================
--- trunk/src/makefile.gfs_absoft	(revision 14)
+++ 	(revision )
@@ -1,93 +1,0 @@
-SHELL = /bin/bash
-MAIN = FLEXPART_GFS
-INCF	= incl* 
-#
-
-
-FC       = /opt/absoft10.1/bin/f95
-INCPATH  = /nilu2/home/flexpart/lib64/absoft/include
-LIBPATH1 = /nilu2/home/flexpart/lib64/absoft/lib
-LIBPATH2 = /nilu2/home/flexpart/lib64/absoft/lib
-FFLAGS   =  -s -O2 -I$(INCPATH) -p$(INCPATH) -m64 -mcmodel=medium
-#FFLAGS   =  -g  -Rb -Rc -Rs  -s  -B108  -YEXT_NAMES=LCS -I$(INCPATH)
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar.o               part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind.o \
-conccalc.o              richardson.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov.o               gridcheck.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix.o               calcmatrix.o \
-convect43c.o               redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-
-%.o: %.f90
-        $(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
Index: branches/FLEXPART_9.1.3/src/makefile.gfs_gfortran
===================================================================
--- trunk/src/makefile.gfs_gfortran	(revision 14)
+++ 	(revision )
@@ -1,90 +1,0 @@
-SHELL = /bin/bash
-MAIN = FLEXPART_GFS_GFORTRAN
-INCF	= incl* 
-#
-
-FC       = gfortran
-INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
-LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
-LIBPATH2 = /flex_wrk/flexpart/lib64/gfortran/lib/
-FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar_gfs.o           part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind_gfs.o \
-conccalc.o              richardson_gfs.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform_gfs.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov_gfs.o           gridcheck_gfs.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix_gfs.o               calcmatrix_gfs.o \
-convect43c.o            redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-%.o: %.f90
-	$(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
Index: branches/FLEXPART_9.1.3/src/makefile.henrik
===================================================================
--- trunk/src/makefile.henrik	(revision 14)
+++ 	(revision )
@@ -1,100 +1,0 @@
-SHELL = /bin/bash
-MAIN = FLEXPART_ICEALOT
-#
-
-FC       = gfortran
-## OUTSIDE TEST PATH
-#INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api_test/include
-#LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api_test/lib
-#LIBPATH2 = /xnilu_wrk/flex_wrk/bin64/jasper/lib
-# OUTSIDE PATH
-INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
-LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
-LIBPATH2 = /xnilu_wrk/flex_wrk/bin64/jasper/lib
-# INSIDE PATH
-#INCPATH  = /nilu2/home/flexpart/lib64/gfortran/include
-#LIBPATH1 = /nilu2/home/flexpart/lib64/gfortran/lib
-#LIBPATH2 = /nilu2/home/flexpart/lib64/gfortran/lib
-#FFLAGS   =   -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-#FFLAGS   =   -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar.o               part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind.o \
-conccalc.o              richardson.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov.o               gridcheck.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix.o               calcmatrix.o \
-convect43c.o               redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-%.o: %.f90
-	$(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
Index: branches/FLEXPART_9.1.3/src/makefile.test
===================================================================
--- trunk/src/makefile.test	(revision 14)
+++ 	(revision )
@@ -1,96 +1,0 @@
-SHELL = /bin/bash
-MAIN = FP_ecmwf_gfortran
-#
-
-FC       = gfortran
-#INCPATH  = /xnilu_wrk/flex_wrk/bin64/grib_api/include
-#LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
-#LIBPATH2 = /flex_wrk/flexpart/lib64/gfortran/lib/
-INCPATH =   /usr/lib/
-LIBPATH1 =   /usr/lib/
-LIBPATH2 =   /usr/lib/x86_64-linux-gnu/
-#LIBPATH2 =   /flex_wrk/flexpart/lib64/gfortran/lib/
-#FFLAGS   =   -O3 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-FFLAGS   =   -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-#FFLAGS   =   -fbounds-check -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -I$(INCPATH)
-LDFLAGS  = $(FFLAGS) -L$(LIBPATH2) -L$(LIBPATH1) -lgrib_api_f90 -lgrib_api -lm -ljasper
-#
-
-
-MODOBJS = \
-par_mod.o               com_mod.o \
-conv_mod.o              hanna_mod.o \
-interpol_mod.o          cmapf_mod.o \
-unc_mod.o               oh_mod.o \
-xmass_mod.o             flux_mod.o \
-point_mod.o             outg_mod.o
-
-OBJECTS = \
-writeheader.o           assignland.o\
-calcpar.o               part0.o \
-caldate.o               partdep.o \
-coordtrafo.o            psih.o \
-raerod.o \
-drydepokernel.o         random.o \
-erf.o                   readavailable.o \
-ew.o                    readcommand.o \
-advance.o               readdepo.o \
-releaseparticles.o      psim.o     \
-FLEXPART.o              readlanduse.o \
-getfields.o             init_domainfill.o\
-interpol_wind.o         readoutgrid.o \
-interpol_all.o          readpaths.o \
-getrb.o                 readreceptors.o \
-getrc.o                 readreleases.o \
-getvdep.o               readspecies.o \
-interpol_misslev.o      readwind.o \
-conccalc.o              richardson.o \
-concoutput.o            scalev.o \
-pbl_profile.o           readOHfield.o\
-juldate.o               timemanager.o \
-interpol_vdep.o         interpol_rain.o \
-verttransform.o         partoutput.o \
-hanna.o                 wetdepokernel.o \
-mean.o                  wetdepo.o \
-hanna_short.o           windalign.o \
-obukhov.o               gridcheck.o \
-hanna1.o                initialize.o \
-                        gridcheck_nests.o \
-readwind_nests.o        calcpar_nests.o \
-verttransform_nests.o   interpol_all_nests.o \
-interpol_wind_nests.o   interpol_misslev_nests.o \
-interpol_vdep_nests.o   interpol_rain_nests.o \
-getvdep_nests.o \
-readageclasses.o        readpartpositions.o \
-calcfluxes.o            fluxoutput.o \
-qvsat.o                 skplin.o \
-convmix.o               calcmatrix.o \
-convect43c.o               redist.o \
-sort2.o                 distance.o \
-centerofmass.o          plumetraj.o \
-openouttraj.o           calcpv.o \
-calcpv_nests.o          distance2.o \
-clustering.o            interpol_wind_short.o \
-interpol_wind_short_nests.o shift_field_0.o \
-shift_field.o           outgrid_init.o \
-openreceptors.o         boundcond_domainfill.o\
-partoutput_short.o      readoutgrid_nest.o \
-outgrid_init_nest.o     writeheader_nest.o \
-concoutput_nest.o       wetdepokernel_nest.o \
-drydepokernel_nest.o    zenithangle.o \
-ohreaction.o            getvdep_nests.o \
-initial_cond_calc.o     initial_cond_output.o \
-dynamic_viscosity.o     get_settling.o
-
-
-$(MAIN): $(MODOBJS) $(OBJECTS)
-	$(FC) *.o -o $(MAIN) $(LDFLAGS)
-
-$(OBJECTS): $(MODOBJS)
-
-%.o: %.f90
-	$(FC) -c $(FFLAGS) $<
-
-clean:
-	rm *.o *.mod
-
Index: branches/FLEXPART_9.1.3/src/par_mod.f90
===================================================================
--- trunk/src/par_mod.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/par_mod.f90	(revision 14)
@@ -28,5 +28,5 @@
 !        1997                                                                  *
 !                                                                              *
-!        Last update 10 August 2000                                            *
+!        Last update 15 August 2013 IP                                         *
 !                                                                              *
 !*******************************************************************************
@@ -122,7 +122,8 @@
 
   integer,parameter :: nxmax=361,nymax=181,nuvzmax=92,nwzmax=92,nzmax=92
-  !integer,parameter :: nxmax=361,nymax=181,nuvzmax=61,nwzmax=61,nzmax=61
+  !integer,parameter :: nxmax=361,nymax=181,nuvzmax=26,nwzmax=26,nzmax=26
   !integer,parameter :: nxmax=721,nymax=361,nuvzmax=64,nwzmax=64,nzmax=64
-  integer,parameter :: nxshift=359  ! for ECMWF
+  !integer,parameter :: nxmax=1201,nymax=235,nuvzmax=58,nwzmax=58,nzmax=58
+  integer,parameter :: nxshift=359 ! for ECMWF
   !integer,parameter :: nxshift=0     ! for GFS
 
@@ -150,6 +151,6 @@
   !*********************************************
 
-  integer,parameter :: maxnests=0, nxmaxn=0, nymaxn=0
-  !integer,parameter :: maxnests=1,nxmaxn=251,nymaxn=151
+  !integer,parameter :: maxnests=0, nxmaxn=0, nymaxn=0
+  integer,parameter :: maxnests=1,nxmaxn=251,nymaxn=151
 
   ! maxnests                maximum number of nested grids
@@ -194,6 +195,6 @@
   !**************************************************
 
-  integer,parameter :: maxpart=2000000
-  integer,parameter :: maxspec=4
+  integer,parameter :: maxpart=150000
+  integer,parameter :: maxspec=1
 
 
@@ -258,3 +259,10 @@
   integer,parameter :: unitboundcond=89
 
+!******************************************************
+! integer code for missing values, used in wet scavenging (PS, 2012)
+!******************************************************
+
+      integer icmv
+      parameter(icmv=-9999)
+
 end module par_mod
Index: branches/FLEXPART_9.1.3/src/readavailable.f90
===================================================================
--- trunk/src/readavailable.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readavailable.f90	(revision 14)
@@ -123,4 +123,6 @@
 
   do k=1,numbnests
+  print*,length(numpath+2*(k-1)+1),length(numpath+2*(k-1)+2),length(4),length(3)
+  print*,path(numpath+2*(k-1)+2)(1:length(numpath+2*(k-1)+2))
     open(unitavailab,file=path(numpath+2*(k-1)+2) &
          (1:length(numpath+2*(k-1)+2)),status='old',err=998)
@@ -275,5 +277,5 @@
   return
 
-998   write(*,*) ' #### FLEXPART MODEL ERROR! FILE   #### '
+998   write(*,*) ' #### FLEXPART MODEL ERROR! AVAILABLE FILE   #### '
   write(*,'(a)') '     '//path(numpath+2*(k-1)+2) &
        (1:length(numpath+2*(k-1)+2))
@@ -281,5 +283,5 @@
   stop
 
-999   write(*,*) ' #### FLEXPART MODEL ERROR! FILE #### '
+999   write(*,*) ' #### FLEXPART MODEL ERROR! AVAILABLE IILE #### '
   write(*,'(a)') '     '//path(4)(1:length(4))
   write(*,*) ' #### CANNOT BE OPENED           #### '
Index: branches/FLEXPART_9.1.3/src/readcommand.f90
===================================================================
--- trunk/src/readcommand.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readcommand.f90	(revision 14)
@@ -80,85 +80,163 @@
   character(len=50) :: line
   logical :: old
-
+  logical :: nmlout=.false.
+  integer :: readerror
+
+  namelist /command/ &
+    ldirect, &
+    ibdate,ibtime, &
+    iedate,ietime, &
+    loutstep, &
+    loutaver, &
+    loutsample, &
+    itsplit, &
+    lsynctime, &
+    ctl, &
+    ifine, &
+    iout, &
+    ipout, &
+    lsubgrid, &
+    lconvection, &
+    lagespectra, &
+    ipin, &
+    ioutputforeachrelease, &
+    iflux, &
+    mdomainfill, &
+    ind_source, &
+    ind_receptor, &
+    mquasilag, &
+    nested_output, &
+    linit_cond
+
+  ! Presetting namelist command
+  ldirect=1
+  ibdate=20000101
+  ibtime=0
+  iedate=20000102
+  ietime=0
+  loutstep=10800
+  loutaver=10800
+  loutsample=900
+  itsplit=999999999
+  lsynctime=900
+  ctl=-5.0
+  ifine=4
+  iout=3
+  ipout=0
+  lsubgrid=1
+  lconvection=1
+  lagespectra=0
+  ipin=1
+  ioutputforeachrelease=0
+  iflux=1
+  mdomainfill=0
+  ind_source=1
+  ind_receptor=1
+  mquasilag=0
+  nested_output=0
+  linit_cond=0
 
   ! Open the command file and read user options
-  !********************************************
-
-
+  ! Namelist input first: try to read as namelist file
+  !**************************************************************************
   open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old', &
-       err=999)
-
-  ! Check the format of the COMMAND file (either in free format,
-  ! or using formatted mask)
-  ! Use of formatted mask is assumed if line 10 contains the word 'DIRECTION'
-  !**************************************************************************
-
-  call skplin(9,unitcommand)
-  read (unitcommand,901) line
-901   format (a)
-  if (index(line,'LDIRECT') .eq. 0) then
-    old = .false.
-  else
-    old = .true.
-  endif
-  rewind(unitcommand)
-
-  ! Read parameters
-  !****************
-
-  call skplin(7,unitcommand)
-  if (old) call skplin(1,unitcommand)
-
-  read(unitcommand,*) ldirect
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ibdate,ibtime
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) iedate,ietime
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) loutstep
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) loutaver
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) loutsample
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) itsplit
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) lsynctime
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ctl
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ifine
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) iout
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ipout
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) lsubgrid
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) lconvection
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) lagespectra
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ipin
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ioutputforeachrelease
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) iflux
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) mdomainfill
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ind_source
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) ind_receptor
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) mquasilag
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) nested_output
-  if (old) call skplin(3,unitcommand)
-  read(unitcommand,*) linit_cond
+         form='formatted',iostat=readerror)
+  ! If fail, check if file does not exist
+  if (readerror.ne.0) then
+
+    print*,'***ERROR: file COMMAND not found. Check your pathnames file.'
+    stop
+
+  endif
+
+  read(unitcommand,command,iostat=readerror)
   close(unitcommand)
 
+  ! If error in namelist format, try to open with old input code
+  if (readerror.ne.0) then
+
+    open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old', &
+         err=999)
+
+    ! Check the format of the COMMAND file (either in free format,
+    ! or using formatted mask)
+    ! Use of formatted mask is assumed if line 10 contains the word 'DIRECTION'
+    !**************************************************************************
+
+    call skplin(9,unitcommand)
+    read (unitcommand,901) line
+  901   format (a)
+    if (index(line,'LDIRECT') .eq. 0) then
+      old = .false.
+    else
+      old = .true.
+    endif
+    rewind(unitcommand)
+
+    ! Read parameters
+    !****************
+
+    call skplin(7,unitcommand)
+    if (old) call skplin(1,unitcommand)
+
+    read(unitcommand,*) ldirect
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ibdate,ibtime
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) iedate,ietime
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) loutstep
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) loutaver
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) loutsample
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) itsplit
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) lsynctime
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ctl
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ifine
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) iout
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ipout
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) lsubgrid
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) lconvection
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) lagespectra
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ipin
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ioutputforeachrelease
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) iflux
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) mdomainfill
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ind_source
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) ind_receptor
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) mquasilag
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) nested_output
+    if (old) call skplin(3,unitcommand)
+    read(unitcommand,*) linit_cond
+    close(unitcommand)
+
+  endif ! input format
+
+  ! write command file in namelist format to output directory if requested
+  if (nmlout.eqv..true.) then
+    open(unitcommand,file=path(2)(1:length(2))//'COMMAND.namelist',status='new',err=999)
+    write(unitcommand,nml=command)
+    close(unitcommand)
+  endif
+
   ifine=max(ifine,1)
-
 
   ! Determine how Markov chain is formulated (for w or for w/sigw)
Index: branches/FLEXPART_9.1.3/src/readpartpositions.f90
===================================================================
--- trunk/src/readpartpositions.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readpartpositions.f90	(revision 14)
@@ -77,11 +77,5 @@
 
   read(unitpartin) numpointin
-  if (numpointin.ne.numpoint) then
-     write(*,*) ' ####              WARNING                     #### '
-     write(*,*) ' #### NUMBER OF RELEASE LOCATIONS DOES NOT     #### '
-     write(*,*) ' #### AGREE WITH CURRENT SETTINGS!             #### '
-     write(*,*) ' #### THIS IS JUST A CHECK TO SEE IF YOU READ  #### '
-     write(*,*) ' #### THE CORRECT PARTICLE DUMP FILE.          #### '
-  endif
+  if (numpointin.ne.numpoint) goto 995
   do i=1,numpointin
     read(unitpartin)
@@ -152,4 +146,8 @@
   stop
 
+995   write(*,*) ' #### FLEXPART MODEL ERROR IN READPARTPOSITIONS#### '
+  write(*,*) ' #### NUMBER OF RELEASE LOCATIONS DOES NOT     #### '
+  write(*,*) ' #### AGREE WITH CURRENT SETTINGS!             #### '
+  stop
 
 996   write(*,*) ' #### FLEXPART MODEL ERROR IN READPARTPOSITIONS#### '
Index: branches/FLEXPART_9.1.3/src/readpaths.f90
===================================================================
--- trunk/src/readpaths.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readpaths.f90	(revision 14)
@@ -20,5 +20,5 @@
 !**********************************************************************
 
-subroutine readpaths
+subroutine readpaths(pathfile)
 
   !*****************************************************************************
@@ -30,4 +30,7 @@
   !                                                                            *
   !     1 February 1994                                                        *
+  !     last modified                                                          *
+  !     HS, 7.9.2012                                                           *
+  !     option to give pathnames file as command line option                   *
   !                                                                            *
   !*****************************************************************************
@@ -47,11 +50,11 @@
   implicit none
 
-  integer :: i
+  integer   :: i
+  character(256) :: pathfile
 
   ! Read the pathname information stored in unitpath
   !*************************************************
 
-
-  open(unitpath,file='pathnames',status='old',err=999)
+  open(unitpath,file=trim(pathfile),status='old',err=999)
 
   do i=1,numpath
@@ -70,4 +73,5 @@
     length(numpath+2*(i-1)+2)=index(path(numpath+2*(i-1)+2),' ')-1
   end do
+  print*,length(5),length(6)
 
 
Index: branches/FLEXPART_9.1.3/src/readreleases.f90
===================================================================
--- trunk/src/readreleases.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readreleases.f90	(revision 14)
@@ -33,5 +33,5 @@
   !     Update: 29 January 2001                                                *
   !     Release altitude can be either in magl or masl                         *
-  !                                                                            *
+  !     Update: Aug 2013 IP                                                                        *
   !*****************************************************************************
   !                                                                            *
@@ -55,6 +55,11 @@
   ! xpoint2,ypoint2     geograf. coordinates of upper right corner of release  *
   !                     area                                                   *
-  ! weta, wetb          parameters to determine the wet scavenging coefficient *
+  ! before: weta, wetb          parameters to determine the wet scavenging coefficient *
+  ! weta, wetb          parameters to determine the below-cloud scavenging (NIK)     *
+  ! weta_in, wetb_in    parameters to determine the in-cloud scavenging    (NIK)    *
+  ! wetc_in, wetd_in    parameters to determine the in-cloud scavenging    (NIK)    *  
   ! zpoint1,zpoint2     height range, over which release takes place           *
+  ! num_min_discrete    if less, release cannot be randomized and happens at   *
+  !                     time mid-point of release interval                     *
   !                                                                            *
   !*****************************************************************************
@@ -68,6 +73,7 @@
 
   integer :: numpartmax,i,j,id1,it1,id2,it2,specnum_rel,idum,stat
+  integer,parameter :: num_min_discrete=100
   real :: vsh(ni),fracth(ni),schmih(ni),releaserate,xdum,cun
-  real(kind=dp) :: jul1,jul2,juldate
+  real(kind=dp) :: jul1,jul2,julm,juldate
   character(len=50) :: line
   logical :: old
@@ -277,10 +283,20 @@
     dryvel(i)=dryvel(i)*0.01         ! conversion to m/s
 
+
+
   ! Check if wet deposition or OH reaction shall be calculated
   !***********************************************************
     if (weta(i).gt.0.)  then
       WETDEP=.true.
-      write (*,*) 'Wetdeposition switched on: ',weta(i),i
-    endif
+      !write (*,*) 'Wetdeposition switched on: ',weta(i),i
+       write (*,*) 'Wet deposition switched on'
+       write (*,*) 'Below-cloud scavenging coefficients: ',weta(i),i 
+   endif
+
+! NIK 31.01.2013
+    if (weta_in(i).gt.0.)  then
+      write (*,*) 'In-cloud scavenging coefficients: ',weta_in(i),wetb_in(i), wetc_in(i), wetd_in(i),i
+    endif
+
     if (ohreact(i).gt.0) then
       OHREA=.true.
@@ -376,4 +392,5 @@
   jul1=juldate(id1,it1)
   jul2=juldate(id2,it2)
+  julm=(jul1+jul2)/2.
   if (jul1.gt.jul2) then
     write(*,*) 'FLEXPART MODEL ERROR'
@@ -391,6 +408,11 @@
         stop
       endif
-      ireleasestart(numpoint)=int((jul1-bdate)*86400.)
-      ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+      if (npart(numpoint).gt.num_min_discrete) then
+        ireleasestart(numpoint)=int((jul1-bdate)*86400.)
+        ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+      else
+        ireleasestart(numpoint)=int((julm-bdate)*86400.)
+        ireleaseend(numpoint)=int((julm-bdate)*86400.)
+      endif
     else if (ldirect.eq.-1) then
       if ((jul1.lt.edate).or.(jul2.gt.bdate)) then
@@ -401,6 +423,11 @@
         stop
       endif
-      ireleasestart(numpoint)=int((jul1-bdate)*86400.)
-      ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+      if (npart(numpoint).gt.num_min_discrete) then
+        ireleasestart(numpoint)=int((jul1-bdate)*86400.)
+        ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+      else
+        ireleasestart(numpoint)=int((julm-bdate)*86400.)
+        ireleaseend(numpoint)=int((julm-bdate)*86400.)
+      endif
     endif
   endif
Index: branches/FLEXPART_9.1.3/src/readreleases.f90.9.1.0
===================================================================
--- branches/FLEXPART_9.1.3/src/readreleases.f90.9.1.0	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readreleases.f90.9.1.0	(revision 14)
@@ -0,0 +1,494 @@
+!**********************************************************************
+! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
+! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
+! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
+!                                                                     *
+! This file is part of FLEXPART.                                      *
+!                                                                     *
+! FLEXPART is free software: you can redistribute it and/or modify    *
+! it under the terms of the GNU General Public License as published by*
+! the Free Software Foundation, either version 3 of the License, or   *
+! (at your option) any later version.                                 *
+!                                                                     *
+! FLEXPART is distributed in the hope that it will be useful,         *
+! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
+! GNU General Public License for more details.                        *
+!                                                                     *
+! You should have received a copy of the GNU General Public License   *
+! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
+!**********************************************************************
+
+subroutine readreleases
+
+  !*****************************************************************************
+  !                                                                            *
+  !     This routine reads the release point specifications for the current    *
+  !     model run. Several release points can be used at the same time.        *
+  !                                                                            *
+  !     Author: A. Stohl                                                       *
+  !                                                                            *
+  !     18 May 1996                                                            *
+  !                                                                            *
+  !     Update: 29 January 2001                                                *
+  !     Release altitude can be either in magl or masl                         *
+  !                                                                            *
+  !*****************************************************************************
+  !                                                                            *
+  ! Variables:                                                                 *
+  ! decay               decay constant of species                              *
+  ! dquer [um]          mean particle diameters                                *
+  ! dsigma              e.g. dsigma=10 or dsigma=0.1 means that 68% of the mass*
+  !                     are between 0.1*dquer and 10*dquer                     *
+  ! ireleasestart, ireleaseend [s] starting time and ending time of each       *
+  !                     release                                                *
+  ! kindz               1: zpoint is in m agl, 2: zpoint is in m asl, 3: zpoint*
+  !                     is in hPa                                              *
+  ! npart               number of particles to be released                     *
+  ! nspec               number of species to be released                       *
+  ! density [kg/m3]     density of the particles                               *
+  ! rm [s/m]            Mesophyll resistance                                   *
+  ! species             name of species                                        *
+  ! xmass               total mass of each species                             *
+  ! xpoint1,ypoint1     geograf. coordinates of lower left corner of release   *
+  !                     area                                                   *
+  ! xpoint2,ypoint2     geograf. coordinates of upper right corner of release  *
+  !                     area                                                   *
+  ! weta, wetb          parameters to determine the wet scavenging coefficient *
+  ! zpoint1,zpoint2     height range, over which release takes place           *
+  !                                                                            *
+  !*****************************************************************************
+
+  use point_mod
+  use xmass_mod
+  use par_mod
+  use com_mod
+
+  implicit none
+
+  integer :: numpartmax,i,j,id1,it1,id2,it2,specnum_rel,idum,stat
+  real :: vsh(ni),fracth(ni),schmih(ni),releaserate,xdum,cun
+  real(kind=dp) :: jul1,jul2,juldate
+  character(len=50) :: line
+  logical :: old
+
+  !sec, read release to find how many releasepoints should be allocated
+
+  open(unitreleases,file=path(1)(1:length(1))//'RELEASES',status='old', &
+       err=999)
+
+  ! Check the format of the RELEASES file (either in free format,
+  ! or using a formatted mask)
+  ! Use of formatted mask is assumed if line 10 contains the word 'DIRECTION'
+  !**************************************************************************
+
+  call skplin(12,unitreleases)
+  read (unitreleases,901) line
+901   format (a)
+  if (index(line,'Total') .eq. 0) then
+    old = .false.
+  else
+    old = .true.
+  endif
+  rewind(unitreleases)
+
+
+  ! Skip first 11 lines (file header)
+  !**********************************
+
+  call skplin(11,unitreleases)
+
+
+  read(unitreleases,*,err=998) nspec
+  if (old) call skplin(2,unitreleases)
+  do i=1,nspec
+    read(unitreleases,*,err=998) specnum_rel
+    if (old) call skplin(2,unitreleases)
+  end do
+
+  numpoint=0
+100   numpoint=numpoint+1
+  read(unitreleases,*,end=25)
+  read(unitreleases,*,err=998,end=25) idum,idum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) idum,idum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) idum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xdum
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) idum
+  if (old) call skplin(2,unitreleases)
+  do i=1,nspec
+    read(unitreleases,*,err=998) xdum
+    if (old) call skplin(2,unitreleases)
+  end do
+  !save compoint only for the first 1000 release points
+  read(unitreleases,'(a40)',err=998) compoint(1)(1:40)
+  if (old) call skplin(1,unitreleases)
+
+  goto 100
+
+25   numpoint=numpoint-1
+
+  !allocate memory for numpoint releaspoint
+    allocate(ireleasestart(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(ireleaseend(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(xpoint1(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(xpoint2(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(ypoint1(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(ypoint2(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(zpoint1(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(zpoint2(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(kindz(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(xmass(numpoint,maxspec) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(rho_rel(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(npart(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+    allocate(xmasssave(numpoint) &
+         ,stat=stat)
+    if (stat.ne.0) write(*,*)'ERROR: could not allocate RELEASPOINT'
+
+   write (*,*) ' Releasepoints allocated: ', numpoint
+
+   do i=1,numpoint
+     xmasssave(i)=0.
+   end do
+
+  !now save the information
+  DEP=.false.
+  DRYDEP=.false.
+  WETDEP=.false.
+  OHREA=.false.
+  do i=1,maxspec
+    DRYDEPSPEC(i)=.false.
+  end do
+
+  rewind(unitreleases)
+
+
+  ! Skip first 11 lines (file header)
+  !**********************************
+
+  call skplin(11,unitreleases)
+
+
+  ! Assign species-specific parameters needed for physical processes
+  !*************************************************************************
+
+  read(unitreleases,*,err=998) nspec
+  if (nspec.gt.maxspec) goto 994
+  if (old) call skplin(2,unitreleases)
+  do i=1,nspec
+    read(unitreleases,*,err=998) specnum_rel
+    if (old) call skplin(2,unitreleases)
+    call readspecies(specnum_rel,i)
+
+  ! For backward runs, only 1 species is allowed
+  !*********************************************
+
+  !if ((ldirect.lt.0).and.(nspec.gt.1)) then
+  !write(*,*) '#####################################################'
+  !write(*,*) '#### FLEXPART MODEL SUBROUTINE READRELEASES:     ####'
+  !write(*,*) '#### FOR BACKWARD RUNS, ONLY 1 SPECIES IS ALLOWED####'
+  !write(*,*) '#####################################################'
+  !  stop
+  !endif
+
+  ! Molecular weight
+  !*****************
+
+    if (((iout.eq.2).or.(iout.eq.3)).and. &
+         (weightmolar(i).lt.0.)) then
+      write(*,*) 'For mixing ratio output, valid molar weight'
+      write(*,*) 'must be specified for all simulated species.'
+      write(*,*) 'Check table SPECIES or choose concentration'
+      write(*,*) 'output instead if molar weight is not known.'
+      stop
+    endif
+
+
+  ! Radioactive decay
+  !******************
+
+    decay(i)=0.693147/decay(i) !conversion half life to decay constant
+
+
+  ! Dry deposition of gases
+  !************************
+
+    if (reldiff(i).gt.0.) &
+         rm(i)=1./(henry(i)/3000.+100.*f0(i))    ! mesophyll resistance
+
+  ! Dry deposition of particles
+  !****************************
+
+    vsetaver(i)=0.
+    cunningham(i)=0.
+    dquer(i)=dquer(i)*1000000.         ! Conversion m to um
+    if (density(i).gt.0.) then                  ! Additional parameters
+     call part0(dquer(i),dsigma(i),density(i),fracth,schmih,cun,vsh)
+      do j=1,ni
+        fract(i,j)=fracth(j)
+        schmi(i,j)=schmih(j)
+        vset(i,j)=vsh(j)
+        cunningham(i)=cunningham(i)+cun*fract(i,j)
+        vsetaver(i)=vsetaver(i)-vset(i,j)*fract(i,j)
+      end do
+      write(*,*) 'Average setting velocity: ',i,vsetaver(i)
+    endif
+
+  ! Dry deposition for constant deposition velocity
+  !************************************************
+
+    dryvel(i)=dryvel(i)*0.01         ! conversion to m/s
+
+  ! Check if wet deposition or OH reaction shall be calculated
+  !***********************************************************
+    if (weta(i).gt.0.)  then
+      WETDEP=.true.
+      write (*,*) 'Wetdeposition switched on: ',weta(i),i
+    endif
+    if (ohreact(i).gt.0) then
+      OHREA=.true.
+      write (*,*) 'OHreaction switched on: ',ohreact(i),i
+    endif
+
+
+    if ((reldiff(i).gt.0.).or.(density(i).gt.0.).or. &
+         (dryvel(i).gt.0.)) then
+      DRYDEP=.true.
+      DRYDEPSPEC(i)=.true.
+    endif
+
+  end do
+
+    if (WETDEP.or.DRYDEP) DEP=.true.
+
+  ! Read specifications for each release point
+  !*******************************************
+
+  numpoint=0
+  numpartmax=0
+  releaserate=0.
+1000   numpoint=numpoint+1
+  read(unitreleases,*,end=250)
+  read(unitreleases,*,err=998,end=250) id1,it1
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) id2,it2
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xpoint1(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) ypoint1(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) xpoint2(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) ypoint2(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) kindz(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) zpoint1(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) zpoint2(numpoint)
+  if (old) call skplin(2,unitreleases)
+  read(unitreleases,*,err=998) npart(numpoint)
+  if (old) call skplin(2,unitreleases)
+  do i=1,nspec
+    read(unitreleases,*,err=998) xmass(numpoint,i)
+    if (old) call skplin(2,unitreleases)
+  end do
+  !save compoint only for the first 1000 release points
+  if (numpoint.le.1000) then
+    read(unitreleases,'(a40)',err=998) compoint(numpoint)(1:40)
+  else
+    read(unitreleases,'(a40)',err=998) compoint(1001)(1:40)
+  endif
+  if (old) call skplin(1,unitreleases)
+  if (numpoint.le.1000) then
+    if((xpoint1(numpoint).eq.0.).and.(ypoint1(numpoint).eq.0.).and. &
+         (xpoint2(numpoint).eq.0.).and.(ypoint2(numpoint).eq.0.).and. &
+         (compoint(numpoint)(1:8).eq.'        ')) goto 250
+  else
+    if((xpoint1(numpoint).eq.0.).and.(ypoint1(numpoint).eq.0.).and. &
+         (xpoint2(numpoint).eq.0.).and.(ypoint2(numpoint).eq.0.)) goto 250
+  endif
+
+
+  ! If a release point contains no particles, stop and issue error message
+  !***********************************************************************
+
+  if (npart(numpoint).eq.0) then
+    write(*,*) 'FLEXPART MODEL ERROR'
+    write(*,*) 'RELEASES file is corrupt.'
+    write(*,*) 'At least for one release point, there are zero'
+    write(*,*) 'particles released. Make changes to RELEASES.'
+    stop
+  endif
+
+  ! Check whether x coordinates of release point are within model domain
+  !*********************************************************************
+
+   if (xpoint1(numpoint).lt.xlon0) &
+        xpoint1(numpoint)=xpoint1(numpoint)+360.
+   if (xpoint1(numpoint).gt.xlon0+(nxmin1)*dx) &
+        xpoint1(numpoint)=xpoint1(numpoint)-360.
+   if (xpoint2(numpoint).lt.xlon0) &
+        xpoint2(numpoint)=xpoint2(numpoint)+360.
+   if (xpoint2(numpoint).gt.xlon0+(nxmin1)*dx) &
+        xpoint2(numpoint)=xpoint2(numpoint)-360.
+
+  ! Determine relative beginning and ending times of particle release
+  !******************************************************************
+
+  jul1=juldate(id1,it1)
+  jul2=juldate(id2,it2)
+  if (jul1.gt.jul2) then
+    write(*,*) 'FLEXPART MODEL ERROR'
+    write(*,*) 'Release stops before it begins.'
+    write(*,*) 'Make changes to file RELEASES.'
+    stop
+  endif
+  if (mdomainfill.eq.0) then   ! no domain filling
+    if (ldirect.eq.1) then
+      if ((jul1.lt.bdate).or.(jul2.gt.edate)) then
+        write(*,*) 'FLEXPART MODEL ERROR'
+        write(*,*) 'Release starts before simulation begins or ends'
+        write(*,*) 'after simulation stops.'
+        write(*,*) 'Make files COMMAND and RELEASES consistent.'
+        stop
+      endif
+      ireleasestart(numpoint)=int((jul1-bdate)*86400.)
+      ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+    else if (ldirect.eq.-1) then
+      if ((jul1.lt.edate).or.(jul2.gt.bdate)) then
+        write(*,*) 'FLEXPART MODEL ERROR'
+        write(*,*) 'Release starts before simulation begins or ends'
+        write(*,*) 'after simulation stops.'
+        write(*,*) 'Make files COMMAND and RELEASES consistent.'
+        stop
+      endif
+      ireleasestart(numpoint)=int((jul1-bdate)*86400.)
+      ireleaseend(numpoint)=int((jul2-bdate)*86400.)
+    endif
+  endif
+
+
+  ! Check, whether the total number of particles may exceed totally allowed
+  ! number of particles at some time during the simulation
+  !************************************************************************
+
+  ! Determine the release rate (particles per second) and total number
+  ! of particles released during the simulation
+  !*******************************************************************
+
+  if (ireleasestart(numpoint).ne.ireleaseend(numpoint)) then
+    releaserate=releaserate+real(npart(numpoint))/ &
+         real(ireleaseend(numpoint)-ireleasestart(numpoint))
+  else
+    releaserate=99999999
+  endif
+  numpartmax=numpartmax+npart(numpoint)
+  goto 1000
+
+
+250   close(unitreleases)
+
+  write (*,*) ' Particles allocated for this run: ',maxpart, ', released in simulation: ',  numpartmax
+  numpoint=numpoint-1
+
+  if (ioutputforeachrelease.eq.1) then
+    maxpointspec_act=numpoint
+  else
+    maxpointspec_act=1
+  endif
+
+  if (releaserate.gt. &
+       0.99*real(maxpart)/real(lage(nageclass))) then
+    if (numpartmax.gt.maxpart) then
+  write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL SUBROUTINE READRELEASES:     ####'
+  write(*,*) '####                                             ####'
+  write(*,*) '####WARNING - TOTAL NUMBER OF PARTICLES SPECIFIED####'
+  write(*,*) '#### IN FILE "RELEASES" MAY AT SOME POINT DURING ####'
+  write(*,*) '#### THE SIMULATION EXCEED THE MAXIMUM ALLOWED   ####'
+  write(*,*) '#### NUMBER (MAXPART).IF RELEASES DO NOT OVERLAP,####'
+  write(*,*) '#### FLEXPART CAN POSSIBLY COMPLETE SUCCESSFULLY.####'
+  write(*,*) '#### HOWEVER, FLEXPART MAY HAVE TO STOP          ####'
+  write(*,*) '#### AT SOME TIME DURING THE SIMULATION. PLEASE  ####'
+  write(*,*) '#### MAKE SURE THAT YOUR SETTINGS ARE CORRECT.   ####'
+  write(*,*) '#####################################################'
+      write(*,*) 'Maximum release rate may be: ',releaserate, &
+           ' particles per second'
+      write(*,*) 'Maximum allowed release rate is: ', &
+           real(maxpart)/real(lage(nageclass)),' particles per second'
+      write(*,*) &
+           'Total number of particles released during the simulation is: ', &
+           numpartmax
+      write(*,*) 'Maximum allowed number of particles is: ',maxpart
+    endif
+  endif
+
+  return
+
+994   write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL SUBROUTINE READRELEASES:     ####'
+  write(*,*) '####                                             ####'
+  write(*,*) '#### ERROR - MAXIMUM NUMBER OF EMITTED SPECIES IS####'
+  write(*,*) '#### TOO LARGE. PLEASE REDUCE NUMBER OF SPECIES. ####'
+  write(*,*) '#####################################################'
+  stop
+
+998   write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL SUBROUTINE READRELEASES:     ####'
+  write(*,*) '####                                             ####'
+  write(*,*) '#### FATAL ERROR - FILE "RELEASES" IS            ####'
+  write(*,*) '#### CORRUPT. PLEASE CHECK YOUR INPUTS FOR       ####'
+  write(*,*) '#### MISTAKES OR GET A NEW "RELEASES"-           ####'
+  write(*,*) '#### FILE ...                                    ####'
+  write(*,*) '#####################################################'
+  stop
+
+
+999   write(*,*) '#####################################################'
+  write(*,*) '   FLEXPART MODEL SUBROUTINE READRELEASES: '
+  write(*,*)
+  write(*,*) 'FATAL ERROR - FILE CONTAINING PARTICLE RELEASE POINTS'
+  write(*,*) 'POINTS IS NOT AVAILABLE OR YOU ARE NOT'
+  write(*,*) 'PERMITTED FOR ANY ACCESS'
+  write(*,*) '#####################################################'
+  stop
+
+end subroutine readreleases
Index: branches/FLEXPART_9.1.3/src/readspecies.f90
===================================================================
--- trunk/src/readspecies.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readspecies.f90	(revision 14)
@@ -31,4 +31,7 @@
   !   11 July 1996                                                             *
   !                                                                            *
+  !   Changes:                                                                 *
+  !   N. Kristiansen, 31.01.2013: Including parameters for in-cloud scavenging *
+  !                                                                            *
   !*****************************************************************************
   !                                                                            *
@@ -36,5 +39,9 @@
   ! decaytime(maxtable)  half time for radiological decay                      *
   ! specname(maxtable)   names of chemical species, radionuclides              *
-  ! wetscava, wetscavb   Parameters for determining scavenging coefficient     *
+  ! weta, wetb           Parameters for determining below-cloud scavenging     *
+  ! weta_in              Parameter for determining in-cloud scavenging         *
+  ! wetb_in              Parameter for determining in-cloud scavenging         *
+  ! wetc_in              Parameter for determining in-cloud scavenging         *
+  ! wetd_in              Parameter for determining in-cloud scavenging         *
   ! ohreact              OH reaction rate                                      *
   ! id_spec              SPECIES number as referenced in RELEASE file          *
@@ -78,4 +85,15 @@
     read(unitspecies,'(f18.2)',end=22) wetb(pos_spec)
   !  write(*,*) wetb(pos_spec)
+
+!*** NIK 31.01.2013: including in-cloud scavening parameters
+   read(unitspecies,'(e18.1)',end=22) weta_in(pos_spec)
+  !  write(*,*) weta_in(pos_spec)
+   read(unitspecies,'(f18.2)',end=22) wetb_in(pos_spec)
+  !  write(*,*) wetb_in(pos_spec)
+   read(unitspecies,'(f18.2)',end=22) wetc_in(pos_spec)
+  !  write(*,*) wetc_in(pos_spec)
+   read(unitspecies,'(f18.2)',end=22) wetd_in(pos_spec)
+  !  write(*,*) wetd_in(pos_spec)
+
     read(unitspecies,'(f18.1)',end=22) reldiff(pos_spec)
   !  write(*,*) reldiff(pos_spec)
Index: branches/FLEXPART_9.1.3/src/readspecies.f90-9.1.1
===================================================================
--- branches/FLEXPART_9.1.3/src/readspecies.f90-9.1.1	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readspecies.f90-9.1.1	(revision 14)
@@ -0,0 +1,188 @@
+!**********************************************************************
+! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
+! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
+! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
+!                                                                     *
+! This file is part of FLEXPART.                                      *
+!                                                                     *
+! FLEXPART is free software: you can redistribute it and/or modify    *
+! it under the terms of the GNU General Public License as published by*
+! the Free Software Foundation, either version 3 of the License, or   *
+! (at your option) any later version.                                 *
+!                                                                     *
+! FLEXPART is distributed in the hope that it will be useful,         *
+! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
+! GNU General Public License for more details.                        *
+!                                                                     *
+! You should have received a copy of the GNU General Public License   *
+! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
+!**********************************************************************
+
+subroutine readspecies(id_spec,pos_spec)
+
+  !*****************************************************************************
+  !                                                                            *
+  !     This routine reads names and physical constants of chemical species/   *
+  !     radionuclides given in the parameter pos_spec                          *
+  !                                                                            *
+  !   Author: A. Stohl                                                         *
+  !                                                                            *
+  !   11 July 1996                                                             *
+  !                                                                            *
+  !*****************************************************************************
+  !                                                                            *
+  ! Variables:                                                                 *
+  ! decaytime(maxtable)  half time for radiological decay                      *
+  ! specname(maxtable)   names of chemical species, radionuclides              *
+  ! wetscava, wetscavb   Parameters for determining scavenging coefficient     *
+  ! ohreact              OH reaction rate                                      *
+  ! id_spec              SPECIES number as referenced in RELEASE file          *
+  ! id_pos               position where SPECIES data shall be stored           *
+  !                                                                            *
+  ! Constants:                                                                 *
+  !                                                                            *
+  !*****************************************************************************
+
+  use par_mod
+  use com_mod
+
+  implicit none
+
+  integer :: i, pos_spec,j
+  integer :: idow,ihour,id_spec
+  character(len=3) :: aspecnumb
+  logical :: spec_found
+
+  ! Open the SPECIES file and read species names and properties
+  !************************************************************
+  specnum(pos_spec)=id_spec
+  write(aspecnumb,'(i3.3)') specnum(pos_spec)
+  open(unitspecies,file= &
+       path(1)(1:length(1))//'SPECIES/SPECIES_'//aspecnumb,status='old', &
+       err=998)
+  !write(*,*) 'reading SPECIES',specnum(pos_spec)
+
+  ASSSPEC=.FALSE.
+
+  do i=1,6
+    read(unitspecies,*)
+  end do
+
+    read(unitspecies,'(a10)',end=22) species(pos_spec)
+  !  write(*,*) species(pos_spec)
+    read(unitspecies,'(f18.1)',end=22) decay(pos_spec)
+  !  write(*,*) decay(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) weta(pos_spec)
+  !  write(*,*) weta(pos_spec)
+    read(unitspecies,'(f18.2)',end=22) wetb(pos_spec)
+  !  write(*,*) wetb(pos_spec)
+    read(unitspecies,'(f18.1)',end=22) reldiff(pos_spec)
+  !  write(*,*) reldiff(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) henry(pos_spec)
+  !  write(*,*) henry(pos_spec)
+    read(unitspecies,'(f18.1)',end=22) f0(pos_spec)
+  !  write(*,*) f0(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) density(pos_spec)
+  !  write(*,*) density(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) dquer(pos_spec)
+  !  write(*,*) dquer(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) dsigma(pos_spec)
+  !  write(*,*) dsigma(pos_spec)
+    read(unitspecies,'(f18.2)',end=22) dryvel(pos_spec)
+  !  write(*,*) dryvel(pos_spec)
+    read(unitspecies,'(f18.2)',end=22) weightmolar(pos_spec)
+  !  write(*,*) weightmolar(pos_spec)
+    read(unitspecies,'(e18.1)',end=22) ohreact(pos_spec)
+  !  write(*,*) ohreact(pos_spec)
+    read(unitspecies,'(i18)',end=22) spec_ass(pos_spec)
+  !  write(*,*) spec_ass(pos_spec)
+    read(unitspecies,'(f18.2)',end=22) kao(pos_spec)
+  !       write(*,*) kao(pos_spec)
+    i=pos_spec
+
+    if ((weta(pos_spec).gt.0).and.(henry(pos_spec).le.0)) then
+       if (dquer(pos_spec).le.0) goto 996 ! no particle, no henry set
+    endif
+
+    if (spec_ass(pos_spec).gt.0) then
+       spec_found=.FALSE.
+       do j=1,pos_spec-1
+          if (spec_ass(pos_spec).eq.specnum(j)) then
+             spec_ass(pos_spec)=j
+             spec_found=.TRUE.
+             ASSSPEC=.TRUE.
+          endif
+       end do
+       if (spec_found.eqv..FALSE.) then
+          goto 997
+       endif
+    endif
+
+    if (dsigma(i).eq.1.) dsigma(i)=1.0001   ! avoid floating exception
+    if (dsigma(i).eq.0.) dsigma(i)=1.0001   ! avoid floating exception
+
+    if ((reldiff(i).gt.0.).and.(density(i).gt.0.)) then
+      write(*,*) '#### FLEXPART MODEL ERROR! FILE "SPECIES"    ####'
+      write(*,*) '#### IS CORRUPT. SPECIES CANNOT BE BOTH      ####'
+      write(*,*) '#### PARTICLE AND GAS.                       ####'
+      write(*,*) '#### SPECIES NUMBER',aspecnumb
+      stop
+    endif
+20   continue
+
+
+  ! Read in daily and day-of-week variation of emissions, if available
+  !*******************************************************************
+
+    do j=1,24           ! initialize everything to no variation
+      area_hour(i,j)=1.
+      point_hour(i,j)=1.
+    end do
+    do j=1,7
+      area_dow(i,j)=1.
+      point_dow(i,j)=1.
+    end do
+
+    read(unitspecies,*,end=22)
+    do j=1,24     ! 24 hours, starting with 0-1 local time
+      read(unitspecies,*) ihour,area_hour(i,j),point_hour(i,j)
+    end do
+    read(unitspecies,*)
+    do j=1,7      ! 7 days of the week, starting with Monday
+      read(unitspecies,*) idow,area_dow(i,j),point_dow(i,j)
+    end do
+
+22   close(unitspecies)
+
+   return
+
+996   write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL ERROR!                      #### '
+  write(*,*) '#### WET DEPOSITION SWITCHED ON, BUT NO HENRYS  #### '
+  write(*,*) '#### CONSTANT IS SET                            ####'
+  write(*,*) '#### PLEASE MODIFY SPECIES DESCR. FILE!        #### '
+  write(*,*) '#####################################################'
+  stop
+
+
+997   write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL ERROR!                      #### '
+  write(*,*) '#### THE ASSSOCIATED SPECIES HAS TO BE DEFINED  #### '
+  write(*,*) '#### BEFORE THE ONE WHICH POINTS AT IT          #### '
+  write(*,*) '#### PLEASE CHANGE ORDER IN RELEASES OR ADD     #### '
+  write(*,*) '#### THE ASSOCIATED SPECIES IN RELEASES         #### '
+  write(*,*) '#####################################################'
+  stop
+
+
+998   write(*,*) '#####################################################'
+  write(*,*) '#### FLEXPART MODEL ERROR!                      #### '
+  write(*,*) '#### THE SPECIES FILE FOR SPECIES ', id_spec
+  write(*,*) '#### CANNOT BE FOUND: CREATE FILE'
+  write(*,*) '#### ',path(1)(1:length(1)),'SPECIES/SPECIES_',aspecnumb
+  write(*,*) '#####################################################'
+  stop
+
+
+end subroutine readspecies
Index: branches/FLEXPART_9.1.3/src/readwind.f90
===================================================================
--- trunk/src/readwind.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readwind.f90	(revision 14)
@@ -101,4 +101,9 @@
   character(len=24) :: gribErrorMsg = 'Error reading grib file'
   character(len=20) :: gribFunction = 'readwind'
+
+  !HSO conversion of ECMWF etadot to etadot*dp/deta
+  logical :: etacon=.false.
+  real,parameter :: p00=101325.
+  real :: dak,dbk
 
   hflswitch=.false.
@@ -365,4 +370,20 @@
   endif
 
+  ! convert from ECMWF etadot to etadot*dp/deta as needed by FLEXPART
+  if(etacon.eqv..true.) then
+    do k=1,nwzmax
+      dak=akm(k+1)-akm(k)
+      dbk=bkm(k+1)-bkm(k)
+      do i=0,nxmin1
+        do j=0,nymin1 
+          wwh(i,j,k)=2*wwh(i,j,k)*ps(i,j,1,n)*(dak/ps(i,j,1,n)+dbk)/(dak/p00+dbk)
+          if (k.gt.1) then 
+            wwh(i,j,k)=wwh(i,j,k)-wwh(i,j,k-1)
+          endif
+        end do
+      end do
+    end do
+  endif
+
   ! For global fields, assign the leftmost data column also to the rightmost
   ! data column; if required, shift whole grid by nxshift grid points
Index: branches/FLEXPART_9.1.3/src/readwind_emos.f90
===================================================================
--- trunk/src/readwind_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,325 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine readwind(indj,n,uuh,vvh,wwh)
-
-  !**********************************************************************
-  !                                                                     *
-  !             TRAJECTORY MODEL SUBROUTINE READWIND                    *
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  !             AUTHOR:      G. WOTAWA                                  *
-  !             DATE:        1997-08-05                                 *
-  !             LAST UPDATE: 2000-10-17, Andreas Stohl                  *
-  !                                                                     *
-  !**********************************************************************
-  !  Changes, Bernd C. Krueger, Feb. 2001:
-  !   Variables tth and qvh (on eta coordinates) in common block
-  !**********************************************************************
-  !                                                                     *
-  ! DESCRIPTION:                                                        *
-  !                                                                     *
-  ! READING OF ECMWF METEOROLOGICAL FIELDS FROM INPUT DATA FILES. THE   *
-  ! INPUT DATA FILES ARE EXPECTED TO BE AVAILABLE IN GRIB CODE          *
-  !                                                                     *
-  ! INPUT:                                                              *
-  ! indj               indicates number of the wind field to be read in *
-  ! n                  temporal index for meteorological fields (1 to 3)*
-  !                                                                     *
-  ! IMPORTANT VARIABLES FROM COMMON BLOCK:                              *
-  !                                                                     *
-  ! wfname             File name of data to be read in                  *
-  ! nx,ny,nuvz,nwz     expected field dimensions                        *
-  ! nlev_ec            number of vertical levels ecmwf model            *
-  ! uu,vv,ww           wind fields                                      *
-  ! tt,qv              temperature and specific humidity                *
-  ! ps                 surface pressure                                 *
-  !                                                                     *
-  !**********************************************************************
-
-  use par_mod
-  use com_mod
-
-  implicit none
-
-  real :: uuh(0:nxmax-1,0:nymax-1,nuvzmax)
-  real :: vvh(0:nxmax-1,0:nymax-1,nuvzmax)
-  real :: wwh(0:nxmax-1,0:nymax-1,nwzmax)
-  integer :: indj,i,j,k,n,levdiff2,ifield,iumax,iwmax,lunit
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmax+nymax),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,ierr,iword
-  !integer iswap
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  real :: xaux,yaux,xaux0,yaux0
-  real,parameter :: eps=1.e-4
-  real :: ewss(0:nxmax-1,0:nymax-1),nsss(0:nxmax-1,0:nymax-1)
-  real :: plev1,pmean,tv,fu,hlev1,ff10m,fflev1
-
-  character(len=1) :: yoper = 'D'
-  logical :: hflswitch,strswitch
-
-  hflswitch=.false.
-  strswitch=.false.
-  levdiff2=nlev_ec-nwz+1
-  iumax=0
-  iwmax=0
-
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(3)(1:length(3))//wfname(indj),'r',ierr)
-  if(ierr.lt.0) goto 999
-
-  ifield=0
-10   ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-  call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-  if(ierr.eq.-1) goto 50    ! EOF DETECTED
-  if(ierr.lt.-1) goto 888   ! ERROR DETECTED
-
-  ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !  iswap=1+ilen/4
-  !  call swap32(inbuff,iswap)
-  !else if (inbuff(1).ne.1196575042) then    ! big endian
-  !  stop 'subroutine gridcheck: corrupt GRIB data'
-  !endif
-
-
-  call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-       zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-  if (ierr.ne.0) goto 888   ! ERROR DETECTED
-
-  if(ifield.eq.1) then
-
-  ! CHECK GRID SPECIFICATIONS
-
-    if(isec2(2).ne.nxfield) stop 'READWIND: NX NOT CONSISTENT'
-    if(isec2(3).ne.ny) stop 'READWIND: NY NOT CONSISTENT'
-    if(isec2(12)/2-1.ne.nlev_ec) &
-         stop 'READWIND: VERTICAL DISCRETIZATION NOT CONSISTENT'
-    xaux=real(isec2(5))/1000.+real(nxshift)*dx
-    yaux=real(isec2(7))/1000.
-    xaux0=xlon0
-    yaux0=ylat0
-    if(xaux.lt.0.) xaux=xaux+360.
-    if(yaux.lt.0.) yaux=yaux+360.
-    if(xaux0.lt.0.) xaux0=xaux0+360.
-    if(yaux0.lt.0.) yaux0=yaux0+360.
-    if(abs(xaux-xaux0).gt.eps) &
-         stop 'READWIND: LOWER LEFT LONGITUDE NOT CONSISTENT'
-    if(abs(yaux-yaux0).gt.eps) &
-         stop 'READWIND: LOWER LEFT LATITUDE NOT CONSISTENT'
-  endif
-
-  do j=0,nymin1
-    do i=0,nxfield-1
-      k=isec1(8)
-      if(isec1(6).eq.130) tth(i,j,nlev_ec-k+2,n)= &!! TEMPERATURE
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.131) uuh(i,j,nlev_ec-k+2)= &!! U VELOCITY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.132) vvh(i,j,nlev_ec-k+2)= &!! V VELOCITY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.133) then                      !! SPEC. HUMIDITY
-        qvh(i,j,nlev_ec-k+2,n)=zsec4(nxfield*(ny-j-1)+i+1)
-        if (qvh(i,j,nlev_ec-k+2,n) .lt. 0.) &
-             qvh(i,j,nlev_ec-k+2,n) = 0.
-  !        this is necessary because the gridded data may contain
-  !        spurious negative values
-      endif
-      if(isec1(6).eq.134) ps(i,j,1,n)= &!! SURF. PRESS.
-           zsec4(nxfield*(ny-j-1)+i+1)
-
-      if(isec1(6).eq.135) wwh(i,j,nlev_ec-k+1)= &!! W VELOCITY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.141) sd(i,j,1,n)= &!! SNOW DEPTH
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.151) msl(i,j,1,n)= &!! SEA LEVEL PRESS.
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.164) tcc(i,j,1,n)= &!! CLOUD COVER
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.165) u10(i,j,1,n)= &!! 10 M U VELOCITY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.166) v10(i,j,1,n)= &!! 10 M V VELOCITY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.167) tt2(i,j,1,n)= &!! 2 M TEMPERATURE
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.168) td2(i,j,1,n)= &!! 2 M DEW POINT
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.142) then                      !! LARGE SCALE PREC.
-        lsprec(i,j,1,n)=zsec4(nxfield*(ny-j-1)+i+1)
-        if (lsprec(i,j,1,n).lt.0.) lsprec(i,j,1,n)=0.
-      endif
-      if(isec1(6).eq.143) then                      !! CONVECTIVE PREC.
-        convprec(i,j,1,n)=zsec4(nxfield*(ny-j-1)+i+1)
-        if (convprec(i,j,1,n).lt.0.) convprec(i,j,1,n)=0.
-      endif
-      if(isec1(6).eq.146) sshf(i,j,1,n)= &!! SENS. HEAT FLUX
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if((isec1(6).eq.146).and.(zsec4(nxfield*(ny-j-1)+i+1).ne.0.)) &
-           hflswitch=.true.    ! Heat flux available
-      if(isec1(6).eq.176) then                      !! SOLAR RADIATION
-        ssr(i,j,1,n)=zsec4(nxfield*(ny-j-1)+i+1)
-        if (ssr(i,j,1,n).lt.0.) ssr(i,j,1,n)=0.
-      endif
-      if(isec1(6).eq.180) ewss(i,j)= &!! EW SURFACE STRESS
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.181) nsss(i,j)= &!! NS SURFACE STRESS
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(((isec1(6).eq.180).or.(isec1(6).eq.181)).and. &
-           (zsec4(nxfield*(ny-j-1)+i+1).ne.0.)) strswitch=.true.    ! stress available
-      if(isec1(6).eq.129) oro(i,j)= &!! ECMWF OROGRAPHY
-           zsec4(nxfield*(ny-j-1)+i+1)/ga
-      if(isec1(6).eq.160) excessoro(i,j)= &!! STANDARD DEVIATION OF OROGRAPHY
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.172) lsm(i,j)= &!! ECMWF LAND SEA MASK
-           zsec4(nxfield*(ny-j-1)+i+1)
-      if(isec1(6).eq.131) iumax=max(iumax,nlev_ec-k+1)
-      if(isec1(6).eq.135) iwmax=max(iwmax,nlev_ec-k+1)
-    end do
-  end do
-
-  goto 10                      !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-50   call pbclose(lunit,ierr)     !! FINNISHED READING / CLOSING GRIB FILE
-
-  if(levdiff2.eq.0) then
-    iwmax=nlev_ec+1
-    do i=0,nxmin1
-      do j=0,nymin1
-        wwh(i,j,nlev_ec+1)=0.
-      end do
-    end do
-  endif
-
-
-  ! For global fields, assign the leftmost data column also to the rightmost
-  ! data column; if required, shift whole grid by nxshift grid points
-  !*************************************************************************
-
-  if (xglobal) then
-    call shift_field_0(ewss,nxfield,ny)
-    call shift_field_0(nsss,nxfield,ny)
-    call shift_field_0(oro,nxfield,ny)
-    call shift_field_0(excessoro,nxfield,ny)
-    call shift_field_0(lsm,nxfield,ny)
-    call shift_field(ps,nxfield,ny,1,1,2,n)
-    call shift_field(sd,nxfield,ny,1,1,2,n)
-    call shift_field(msl,nxfield,ny,1,1,2,n)
-    call shift_field(tcc,nxfield,ny,1,1,2,n)
-    call shift_field(u10,nxfield,ny,1,1,2,n)
-    call shift_field(v10,nxfield,ny,1,1,2,n)
-    call shift_field(tt2,nxfield,ny,1,1,2,n)
-    call shift_field(td2,nxfield,ny,1,1,2,n)
-    call shift_field(lsprec,nxfield,ny,1,1,2,n)
-    call shift_field(convprec,nxfield,ny,1,1,2,n)
-    call shift_field(sshf,nxfield,ny,1,1,2,n)
-    call shift_field(ssr,nxfield,ny,1,1,2,n)
-    call shift_field(tth,nxfield,ny,nuvzmax,nuvz,2,n)
-    call shift_field(qvh,nxfield,ny,nuvzmax,nuvz,2,n)
-    call shift_field(uuh,nxfield,ny,nuvzmax,nuvz,1,1)
-    call shift_field(vvh,nxfield,ny,nuvzmax,nuvz,1,1)
-    call shift_field(wwh,nxfield,ny,nwzmax,nwz,1,1)
-  endif
-
-  do i=0,nxmin1
-    do j=0,nymin1
-      surfstr(i,j,1,n)=sqrt(ewss(i,j)**2+nsss(i,j)**2)
-    end do
-  end do
-
-  if ((.not.hflswitch).or.(.not.strswitch)) then
-    write(*,*) 'WARNING: No flux data contained in GRIB file ', &
-         wfname(indj)
-
-  ! CALCULATE USTAR AND SSHF USING THE PROFILE METHOD
-  ! As ECMWF has increased the model resolution, such that now the first model
-  ! level is at about 10 m (where 10-m wind is given), use the 2nd ECMWF level
-  ! (3rd model level in FLEXPART) for the profile method
-  !***************************************************************************
-
-    do i=0,nxmin1
-      do j=0,nymin1
-        plev1=akz(3)+bkz(3)*ps(i,j,1,n)
-        pmean=0.5*(ps(i,j,1,n)+plev1)
-        tv=tth(i,j,3,n)*(1.+0.61*qvh(i,j,3,n))
-        fu=-r_air*tv/ga/pmean
-        hlev1=fu*(plev1-ps(i,j,1,n))   ! HEIGTH OF FIRST MODEL LAYER
-        ff10m= sqrt(u10(i,j,1,n)**2+v10(i,j,1,n)**2)
-        fflev1=sqrt(uuh(i,j,3)**2+vvh(i,j,3)**2)
-        call pbl_profile(ps(i,j,1,n),td2(i,j,1,n),hlev1, &
-             tt2(i,j,1,n),tth(i,j,3,n),ff10m,fflev1, &
-             surfstr(i,j,1,n),sshf(i,j,1,n))
-        if(sshf(i,j,1,n).gt.200.) sshf(i,j,1,n)=200.
-        if(sshf(i,j,1,n).lt.-400.) sshf(i,j,1,n)=-400.
-      end do
-    end do
-  endif
-
-
-  ! Assign 10 m wind to model level at eta=1.0 to have one additional model
-  ! level at the ground
-  ! Specific humidity is taken the same as at one level above
-  ! Temperature is taken as 2 m temperature
-  !**************************************************************************
-
-     do i=0,nxmin1
-        do j=0,nymin1
-           uuh(i,j,1)=u10(i,j,1,n)
-           vvh(i,j,1)=v10(i,j,1,n)
-           qvh(i,j,1,n)=qvh(i,j,2,n)
-           tth(i,j,1,n)=tt2(i,j,1,n)
-        end do
-     end do
-
-  if(iumax.ne.nuvz-1) stop 'READWIND: NUVZ NOT CONSISTENT'
-  if(iwmax.ne.nwz)    stop 'READWIND: NWZ NOT CONSISTENT'
-
-  return
-888   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfname(indj),'                    #### '
-  write(*,*) ' #### IS NOT GRIB FORMAT !!!                  #### '
-  stop 'Execution terminated'
-999   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfname(indj),'                    #### '
-  write(*,*) ' #### CANNOT BE OPENED !!!                    #### '
-  stop 'Execution terminated'
-
-end subroutine readwind
Index: branches/FLEXPART_9.1.3/src/readwind_gfs.f90
===================================================================
--- trunk/src/readwind_gfs.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/readwind_gfs.f90	(revision 14)
@@ -703,5 +703,4 @@
   endif
 
-
   if(iumax.ne.nuvz) stop 'READWIND: NUVZ NOT CONSISTENT'
   if(iumax.ne.nwz)    stop 'READWIND: NWZ NOT CONSISTENT'
Index: branches/FLEXPART_9.1.3/src/readwind_gfs_emos.f90
===================================================================
--- trunk/src/readwind_gfs_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,533 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine readwind(indj,n,uuh,vvh,wwh)
-
-  !**********************************************************************
-  !                                                                     *
-  !             TRAJECTORY MODEL SUBROUTINE READWIND                    *
-  !                                                                     *
-  !**********************************************************************
-  !                                                                     *
-  !             AUTHOR:      G. WOTAWA                                  *
-  !             DATE:        1997-08-05                                 *
-  !             LAST UPDATE: 2000-10-17, Andreas Stohl                  *
-  !             CAHENGE: 16/11/2005, Caroline Forster, GFS data         *
-  !                                                                     *
-  !**********************************************************************
-  !  Changes, Bernd C. Krueger, Feb. 2001:
-  !   Variables tth and qvh (on eta coordinates) in common block
-  !**********************************************************************
-  !                                                                     *
-  ! DESCRIPTION:                                                        *
-  !                                                                     *
-  ! READING OF ECMWF METEOROLOGICAL FIELDS FROM INPUT DATA FILES. THE   *
-  ! INPUT DATA FILES ARE EXPECTED TO BE AVAILABLE IN GRIB CODE          *
-  !                                                                     *
-  ! INPUT:                                                              *
-  ! indj               indicates number of the wind field to be read in *
-  ! n                  temporal index for meteorological fields (1 to 3)*
-  !                                                                     *
-  ! IMPORTANT VARIABLES FROM COMMON BLOCK:                              *
-  !                                                                     *
-  ! wfname             File name of data to be read in                  *
-  ! nx,ny,nuvz,nwz     expected field dimensions                        *
-  ! nlev_ec            number of vertical levels ecmwf model            *
-  ! uu,vv,ww           wind fields                                      *
-  ! tt,qv              temperature and specific humidity                *
-  ! ps                 surface pressure                                 *
-  !                                                                     *
-  !**********************************************************************
-
-  use par_mod
-  use com_mod
-
-  implicit none
-
-  real :: uuh(0:nxmax-1,0:nymax-1,nuvzmax)
-  real :: vvh(0:nxmax-1,0:nymax-1,nuvzmax)
-  real :: wwh(0:nxmax-1,0:nymax-1,nwzmax)
-  integer :: ii,indj,i,j,k,n,levdiff2,ifield,iumax,iwmax,lunit
-
-  ! NCEP
-
-  integer :: numpt,numpu,numpv,numpw,numprh
-  real :: help, temp, ew
-  real :: elev
-  real :: ulev1(0:nxmax-1,0:nymax-1),vlev1(0:nxmax-1,0:nymax-1)
-  real :: tlev1(0:nxmax-1,0:nymax-1)
-  real :: qvh2(0:nxmax-1,0:nymax-1)
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmax+nymax),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,iswap,ierr,iword
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  real :: xaux,yaux,xaux0,yaux0
-  real,parameter :: eps=1.e-4
-  real :: ewss(0:nxmax-1,0:nymax-1),nsss(0:nxmax-1,0:nymax-1)
-  real :: plev1,hlev1,ff10m,fflev1
-
-  character(len=1) :: yoper = 'D'
-  logical :: hflswitch,strswitch
-
-  hflswitch=.false.
-  strswitch=.false.
-  levdiff2=nlev_ec-nwz+1
-  iumax=0
-  iwmax=0
-
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(3)(1:length(3))//wfname(indj),'r',ierr)
-  if(ierr.lt.0) goto 999
-
-  numpt=0
-  numpu=0
-  numpv=0
-  numpw=0
-  numprh=0
-  ifield=0
-10   ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-  call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-  if(ierr.eq.-1) goto 50    ! EOF DETECTED
-  if(ierr.lt.-1) goto 888   ! ERROR DETECTED
-
-  ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !  iswap=1+ilen/4
-  !  call swap32(inbuff,iswap)
-  !else if (inbuff(1).ne.1196575042) then    ! big endian
-  !  stop 'subroutine gridcheck: corrupt GRIB data'
-  !endif
-
-
-  call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-       zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-  if (ierr.ne.0) goto 10   ! ERROR DETECTED
-
-  if(ifield.eq.1) then
-
-  ! CHECK GRID SPECIFICATIONS
-
-    if(isec2(2).ne.nxfield) stop 'READWIND: NX NOT CONSISTENT'
-    if(isec2(3).ne.ny) stop 'READWIND: NY NOT CONSISTENT'
-    xaux=real(isec2(5))/1000.+real(nxshift)*dx
-    if(xaux.eq.0.) xaux=-179.0     ! NCEP DATA
-    yaux=real(isec2(7))/1000.
-    xaux0=xlon0
-    yaux0=ylat0
-    if(xaux.lt.0.) xaux=xaux+360.
-    if(yaux.lt.0.) yaux=yaux+360.
-    if(xaux0.lt.0.) xaux0=xaux0+360.
-    if(yaux0.lt.0.) yaux0=yaux0+360.
-    if(abs(xaux-xaux0).gt.eps) &
-         stop 'READWIND: LOWER LEFT LONGITUDE NOT CONSISTENT'
-    if(abs(yaux-yaux0).gt.eps) &
-         stop 'READWIND: LOWER LEFT LATITUDE NOT CONSISTENT'
-  endif
-
-  do j=0,nymin1
-    do i=0,nxfield-1
-      if((isec1(6).eq.011).and.(isec1(7).eq.100)) then
-  ! TEMPERATURE
-         if((i.eq.0).and.(j.eq.0)) then
-            do ii=1,nuvz
-              if ((isec1(8)*100.0).eq.akz(ii)) numpt=ii
-            end do
-        endif
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          tth(179+i,j,numpt,n)=help
-        else
-          tth(i-181,j,numpt,n)=help
-        endif
-      endif
-      if((isec1(6).eq.033).and.(isec1(7).eq.100)) then
-  ! U VELOCITY
-         if((i.eq.0).and.(j.eq.0)) then
-            do ii=1,nuvz
-              if ((isec1(8)*100.0).eq.akz(ii)) numpu=ii
-            end do
-        endif
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          uuh(179+i,j,numpu)=help
-        else
-          uuh(i-181,j,numpu)=help
-        endif
-      endif
-      if((isec1(6).eq.034).and.(isec1(7).eq.100)) then
-  ! V VELOCITY
-         if((i.eq.0).and.(j.eq.0)) then
-            do ii=1,nuvz
-              if ((isec1(8)*100.0).eq.akz(ii)) numpv=ii
-            end do
-        endif
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          vvh(179+i,j,numpv)=help
-        else
-          vvh(i-181,j,numpv)=help
-        endif
-      endif
-      if((isec1(6).eq.052).and.(isec1(7).eq.100)) then
-  ! RELATIVE HUMIDITY -> CONVERT TO SPECIFIC HUMIDITY LATER
-         if((i.eq.0).and.(j.eq.0)) then
-            do ii=1,nuvz
-              if ((isec1(8)*100.0).eq.akz(ii)) numprh=ii
-            end do
-        endif
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          qvh(179+i,j,numprh,n)=help
-        else
-          qvh(i-181,j,numprh,n)=help
-        endif
-      endif
-      if((isec1(6).eq.001).and.(isec1(7).eq.001)) then
-  ! SURFACE PRESSURE
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          ps(179+i,j,1,n)=help
-        else
-          ps(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.039).and.(isec1(7).eq.100)) then
-  ! W VELOCITY
-         if((i.eq.0).and.(j.eq.0)) then
-            do ii=1,nuvz
-              if ((isec1(8)*100.0).eq.akz(ii)) numpw=ii
-            end do
-        endif
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          wwh(179+i,j,numpw)=help
-        else
-          wwh(i-181,j,numpw)=help
-        endif
-      endif
-      if((isec1(6).eq.066).and.(isec1(7).eq.001)) then
-  ! SNOW DEPTH
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          sd(179+i,j,1,n)=help
-        else
-          sd(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.002).and.(isec1(7).eq.102)) then
-  ! MEAN SEA LEVEL PRESSURE
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          msl(179+i,j,1,n)=help
-        else
-          msl(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.071).and.(isec1(7).eq.244)) then
-  ! TOTAL CLOUD COVER
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          tcc(179+i,j,1,n)=help
-        else
-          tcc(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.033).and.(isec1(7).eq.105).and. &
-           (isec1(8).eq.10)) then
-  ! 10 M U VELOCITY
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          u10(179+i,j,1,n)=help
-        else
-          u10(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.034).and.(isec1(7).eq.105).and. &
-           (isec1(8).eq.10)) then
-  ! 10 M V VELOCITY
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          v10(179+i,j,1,n)=help
-        else
-          v10(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.011).and.(isec1(7).eq.105).and. &
-           (isec1(8).eq.02)) then
-  ! 2 M TEMPERATURE
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          tt2(179+i,j,1,n)=help
-        else
-          tt2(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.017).and.(isec1(7).eq.105).and. &
-           (isec1(8).eq.02)) then
-  ! 2 M DEW POINT TEMPERATURE
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          td2(179+i,j,1,n)=help
-        else
-          td2(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.062).and.(isec1(7).eq.001)) then
-  ! LARGE SCALE PREC.
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          lsprec(179+i,j,1,n)=help
-        else
-          lsprec(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.063).and.(isec1(7).eq.001)) then
-  ! CONVECTIVE PREC.
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          convprec(179+i,j,1,n)=help
-        else
-          convprec(i-181,j,1,n)=help
-        endif
-      endif
-  ! SENS. HEAT FLUX
-      sshf(i,j,1,n)=0.0     ! not available from gfs.tccz.pgrbfxx files
-      hflswitch=.false.    ! Heat flux not available
-  ! SOLAR RADIATIVE FLUXES
-      ssr(i,j,1,n)=0.0      ! not available from gfs.tccz.pgrbfxx files
-  ! EW SURFACE STRESS
-      ewss(i,j)=0.0         ! not available from gfs.tccz.pgrbfxx files
-  ! NS SURFACE STRESS
-      nsss(i,j)=0.0         ! not available from gfs.tccz.pgrbfxx files
-      strswitch=.false.    ! stress not available
-      if((isec1(6).eq.007).and.(isec1(7).eq.001)) then
-  ! TOPOGRAPHY
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          oro(179+i,j)=help
-          excessoro(179+i,j)=0.0 ! ISOBARIC SURFACES: SUBGRID TERRAIN DISREGARDED
-        else
-          oro(i-181,j)=help
-          excessoro(i-181,j)=0.0 ! ISOBARIC SURFACES: SUBGRID TERRAIN DISREGARDED
-        endif
-      endif
-      if((isec1(6).eq.081).and.(isec1(7).eq.001)) then
-  ! LAND SEA MASK
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          lsm(179+i,j)=help
-        else
-          lsm(i-181,j)=help
-        endif
-      endif
-      if((isec1(6).eq.221).and.(isec1(7).eq.001)) then
-  ! MIXING HEIGHT
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          hmix(179+i,j,1,n)=help
-        else
-          hmix(i-181,j,1,n)=help
-        endif
-      endif
-      if((isec1(6).eq.052).and.(isec1(7).eq.105).and. &
-           (isec1(8).eq.02)) then
-  ! 2 M RELATIVE HUMIDITY
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          qvh2(179+i,j)=help
-        else
-          qvh2(i-181,j)=help
-        endif
-      endif
-      if((isec1(6).eq.011).and.(isec1(7).eq.107)) then
-  ! TEMPERATURE LOWEST SIGMA LEVEL
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          tlev1(179+i,j)=help
-        else
-          tlev1(i-181,j)=help
-        endif
-      endif
-      if((isec1(6).eq.033).and.(isec1(7).eq.107)) then
-  ! U VELOCITY LOWEST SIGMA LEVEL
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          ulev1(179+i,j)=help
-        else
-          ulev1(i-181,j)=help
-        endif
-      endif
-      if((isec1(6).eq.034).and.(isec1(7).eq.107)) then
-  ! V VELOCITY LOWEST SIGMA LEVEL
-        help=zsec4(nxfield*(ny-j-1)+i+1)
-        if(i.le.180) then
-          vlev1(179+i,j)=help
-        else
-          vlev1(i-181,j)=help
-        endif
-      endif
-
-    end do
-  end do
-
-  if((isec1(6).eq.33).and.(isec1(7).eq.100)) then
-  ! NCEP ISOBARIC LEVELS
-    iumax=iumax+1
-  endif
-
-
-  goto 10                      !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-50   call pbclose(lunit,ierr)     !! FINNISHED READING / CLOSING GRIB FILE
-
-  ! TRANSFORM RH TO SPECIFIC HUMIDITY
-
-  do j=0,ny-1
-    do i=0,nxfield-1
-      do k=1,nuvz
-        help=qvh(i,j,k,n)
-        temp=tth(i,j,k,n)
-        plev1=akm(k)+bkm(k)*ps(i,j,1,n)
-        elev=ew(temp)*help/100.0
-        qvh(i,j,k,n)=xmwml*(elev/(plev1-((1.0-xmwml)*elev)))
-      end do
-    end do
-  end do
-
-  ! CALCULATE 2 M DEW POINT FROM 2 M RELATIVE HUMIDITY
-  ! USING BOLTON'S (1980) FORMULA
-  ! BECAUSE td2 IS NOT AVAILABLE FROM NCEP GFS DATA
-
-  do j=0,ny-1
-    do i=0,nxfield-1
-        help=qvh2(i,j)
-        temp=tt2(i,j,1,n)
-        elev=ew(temp)/100.*help/100.   !vapour pressure in hPa
-        td2(i,j,1,n)=243.5/(17.67/log(elev/6.112)-1)+273.
-        if (help.le.0.) td2(i,j,1,n)=tt2(i,j,1,n)
-    end do
-  end do
-
-  if(levdiff2.eq.0) then
-    iwmax=nlev_ec+1
-    do i=0,nxmin1
-      do j=0,nymin1
-        wwh(i,j,nlev_ec+1)=0.
-      end do
-    end do
-  endif
-
-
-  ! For global fields, assign the leftmost data column also to the rightmost
-  ! data column; if required, shift whole grid by nxshift grid points
-  !*************************************************************************
-
-  if (xglobal) then
-    call shift_field_0(ewss,nxfield,ny)
-    call shift_field_0(nsss,nxfield,ny)
-    call shift_field_0(oro,nxfield,ny)
-    call shift_field_0(excessoro,nxfield,ny)
-    call shift_field_0(lsm,nxfield,ny)
-    call shift_field_0(ulev1,nxfield,ny)
-    call shift_field_0(vlev1,nxfield,ny)
-    call shift_field_0(tlev1,nxfield,ny)
-    call shift_field_0(qvh2,nxfield,ny)
-    call shift_field(ps,nxfield,ny,1,1,2,n)
-    call shift_field(sd,nxfield,ny,1,1,2,n)
-    call shift_field(msl,nxfield,ny,1,1,2,n)
-    call shift_field(tcc,nxfield,ny,1,1,2,n)
-    call shift_field(u10,nxfield,ny,1,1,2,n)
-    call shift_field(v10,nxfield,ny,1,1,2,n)
-    call shift_field(tt2,nxfield,ny,1,1,2,n)
-    call shift_field(td2,nxfield,ny,1,1,2,n)
-    call shift_field(lsprec,nxfield,ny,1,1,2,n)
-    call shift_field(convprec,nxfield,ny,1,1,2,n)
-    call shift_field(sshf,nxfield,ny,1,1,2,n)
-    call shift_field(ssr,nxfield,ny,1,1,2,n)
-    call shift_field(hmix,nxfield,ny,1,1,2,n)
-    call shift_field(tth,nxfield,ny,nuvzmax,nuvz,2,n)
-    call shift_field(qvh,nxfield,ny,nuvzmax,nuvz,2,n)
-    call shift_field(uuh,nxfield,ny,nuvzmax,nuvz,1,1)
-    call shift_field(vvh,nxfield,ny,nuvzmax,nuvz,1,1)
-    call shift_field(wwh,nxfield,ny,nwzmax,nwz,1,1)
-  endif
-
-  do i=0,nxmin1
-    do j=0,nymin1
-      surfstr(i,j,1,n)=sqrt(ewss(i,j)**2+nsss(i,j)**2)
-    end do
-  end do
-
-  if ((.not.hflswitch).or.(.not.strswitch)) then
-  !  write(*,*) 'WARNING: No flux data contained in GRIB file ',
-  !    +  wfname(indj)
-
-  ! CALCULATE USTAR AND SSHF USING THE PROFILE METHOD
-  !***************************************************************************
-
-    do i=0,nxmin1
-      do j=0,nymin1
-        hlev1=30.0                     ! HEIGHT OF FIRST MODEL SIGMA LAYER
-        ff10m= sqrt(u10(i,j,1,n)**2+v10(i,j,1,n)**2)
-        fflev1=sqrt(ulev1(i,j)**2+vlev1(i,j)**2)
-        call pbl_profile(ps(i,j,1,n),td2(i,j,1,n),hlev1, &
-             tt2(i,j,1,n),tlev1(i,j),ff10m,fflev1, &
-             surfstr(i,j,1,n),sshf(i,j,1,n))
-        if(sshf(i,j,1,n).gt.200.) sshf(i,j,1,n)=200.
-        if(sshf(i,j,1,n).lt.-400.) sshf(i,j,1,n)=-400.
-      end do
-    end do
-  endif
-
-
-  if(iumax.ne.nuvz) stop 'READWIND: NUVZ NOT CONSISTENT'
-  if(iumax.ne.nwz)    stop 'READWIND: NWZ NOT CONSISTENT'
-
-  return
-888   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfname(indj),'                    #### '
-  write(*,*) ' #### IS NOT GRIB FORMAT !!!                  #### '
-  stop 'Execution terminated'
-999   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfname(indj),'                    #### '
-  write(*,*) ' #### CANNOT BE OPENED !!!                    #### '
-  stop 'Execution terminated'
-
-end subroutine readwind
Index: branches/FLEXPART_9.1.3/src/readwind_nests_emos.f90
===================================================================
--- trunk/src/readwind_nests_emos.f90	(revision 14)
+++ 	(revision )
@@ -1,286 +1,0 @@
-!**********************************************************************
-! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
-! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
-! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
-!                                                                     *
-! This file is part of FLEXPART.                                      *
-!                                                                     *
-! FLEXPART is free software: you can redistribute it and/or modify    *
-! it under the terms of the GNU General Public License as published by*
-! the Free Software Foundation, either version 3 of the License, or   *
-! (at your option) any later version.                                 *
-!                                                                     *
-! FLEXPART is distributed in the hope that it will be useful,         *
-! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
-! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
-! GNU General Public License for more details.                        *
-!                                                                     *
-! You should have received a copy of the GNU General Public License   *
-! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
-!**********************************************************************
-
-subroutine readwind_nests(indj,n,uuhn,vvhn,wwhn)
-  !                           i   i  o    o    o
-  !*****************************************************************************
-  !                                                                            *
-  !     This routine reads the wind fields for the nested model domains.       *
-  !     It is similar to subroutine readwind, which reads the mother domain.   *
-  !                                                                            *
-  !     Authors: A. Stohl, G. Wotawa                                           *
-  !                                                                            *
-  !     8 February 1999                                                        *
-  !                                                                            *
-  !     Last update: 17 October 2000, A. Stohl                                 *
-  !                                                                            *
-  !*****************************************************************************
-  !  Changes, Bernd C. Krueger, Feb. 2001:
-  !   Variables tthn and qvhn (on eta coordinates) in common block
-  !*****************************************************************************
-
-  use par_mod
-  use com_mod
-
-  implicit none
-
-  real :: uuhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,maxnests)
-  real :: vvhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,maxnests)
-  real :: wwhn(0:nxmaxn-1,0:nymaxn-1,nwzmax,maxnests)
-  integer :: indj,i,j,k,n,levdiff2,ifield,iumax,iwmax,lunit,l
-
-  ! VARIABLES AND ARRAYS NEEDED FOR GRIB DECODING
-
-  ! dimension of isec2 at least (22+n), where n is the number of parallels or
-  ! meridians in a quasi-regular (reduced) Gaussian or lat/long grid
-
-  ! dimension of zsec2 at least (10+nn), where nn is the number of vertical
-  ! coordinate parameters
-
-  integer :: isec0(2),isec1(56),isec2(22+nxmaxn+nymaxn),isec3(2)
-  integer :: isec4(64),inbuff(jpack),ilen,ierr,iword
-  !integer iswap
-  real :: zsec2(60+2*nuvzmax),zsec3(2),zsec4(jpunp)
-  real :: xaux,yaux,xaux0,yaux0
-  real :: ewss(0:nxmaxn-1,0:nymaxn-1),nsss(0:nxmaxn-1,0:nymaxn-1)
-  real :: plev1,pmean,tv,fu,hlev1,ff10m,fflev1
-
-  character(len=1) :: yoper = 'D'
-  logical :: hflswitch,strswitch
-
-
-  do l=1,numbnests
-    hflswitch=.false.
-    strswitch=.false.
-    levdiff2=nlev_ec-nwz+1
-    iumax=0
-    iwmax=0
-
-  !
-  ! OPENING OF DATA FILE (GRIB CODE)
-  !
-5   call pbopen(lunit,path(numpath+2*(l-1)+1) &
-         (1:length(numpath+2*(l-1)+1))//wfnamen(l,indj),'r',ierr)
-    if(ierr.lt.0) goto 999
-
-    ifield=0
-10    ifield=ifield+1
-  !
-  ! GET NEXT FIELDS
-  !
-    call pbgrib(lunit,inbuff,jpack,ilen,ierr)
-    if(ierr.eq.-1) goto 50    ! EOF DETECTED
-    if(ierr.lt.-1) goto 888   ! ERROR DETECTED
-
-    ierr=1
-
-  ! Check whether we are on a little endian or on a big endian computer
-  !********************************************************************
-
-  !  if (inbuff(1).eq.1112101447) then         ! little endian, swap bytes
-  !    iswap=1+ilen/4
-  !    call swap32(inbuff,iswap)
-  !  else if (inbuff(1).ne.1196575042) then    ! big endian
-  !    stop 'subroutine gridcheck: corrupt GRIB data'
-  !  endif
-
-    call gribex(isec0,isec1,isec2,zsec2,isec3,zsec3,isec4, &
-         zsec4,jpunp,inbuff,jpack,iword,yoper,ierr)
-    if (ierr.ne.0) goto 888   ! ERROR DETECTED
-
-    if(ifield.eq.1) then
-
-  ! CHECK GRID SPECIFICATIONS
-
-      if(isec2(2).ne.nxn(l)) stop &
-           'READWIND: NX NOT CONSISTENT FOR A NESTING LEVEL'
-      if(isec2(3).ne.nyn(l)) stop &
-           'READWIND: NY NOT CONSISTENT FOR A NESTING LEVEL'
-      if(isec2(12)/2-1.ne.nlev_ec) stop 'READWIND: VERTICAL DISCRET&
-           &IZATION NOT CONSISTENT FOR A NESTING LEVEL'
-      xaux=real(isec2(5))/1000.
-      yaux=real(isec2(7))/1000.
-      xaux0=xlon0n(l)
-      yaux0=ylat0n(l)
-      if(xaux.lt.0.) xaux=xaux+360.
-      if(yaux.lt.0.) yaux=yaux+360.
-      if(xaux0.lt.0.) xaux0=xaux0+360.
-      if(yaux0.lt.0.) yaux0=yaux0+360.
-      if(xaux.ne.xaux0) &
-           stop 'READWIND: LOWER LEFT LONGITUDE NOT CONSISTENT FOR A NES&
-           &TING LEVEL'
-      if(yaux.ne.yaux0) &
-           stop 'READWIND: LOWER LEFT LATITUDE NOT CONSISTENT FOR A NEST&
-           &ING LEVEL'
-    endif
-
-
-    do j=0,nyn(l)-1
-      do i=0,nxn(l)-1
-        k=isec1(8)
-        if(isec1(6).eq.130) tthn(i,j,nlev_ec-k+2,n,l)= &!! TEMPERATURE
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.131) uuhn(i,j,nlev_ec-k+2,l)= &!! U VELOCITY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.132) vvhn(i,j,nlev_ec-k+2,l)= &!! V VELOCITY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.133) then                         !! SPEC. HUMIDITY
-          qvhn(i,j,nlev_ec-k+2,n,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-          if (qvhn(i,j,nlev_ec-k+2,n,l) .lt. 0.) &
-               qvhn(i,j,nlev_ec-k+2,n,l) = 0.
-  !          this is necessary because the gridded data may contain
-  !          spurious negative values
-        endif
-        if(isec1(6).eq.134) psn(i,j,1,n,l)= &!! SURF. PRESS.
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.135) wwhn(i,j,nlev_ec-k+1,l)= &!! W VELOCITY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.141) sdn(i,j,1,n,l)= &!! SNOW DEPTH
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.151) msln(i,j,1,n,l)= &!! SEA LEVEL PRESS.
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.164) tccn(i,j,1,n,l)= &!! CLOUD COVER
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.165) u10n(i,j,1,n,l)= &!! 10 M U VELOCITY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.166) v10n(i,j,1,n,l)= &!! 10 M V VELOCITY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.167) tt2n(i,j,1,n,l)= &!! 2 M TEMPERATURE
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.168) td2n(i,j,1,n,l)= &!! 2 M DEW POINT
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.142) then                         !! LARGE SCALE PREC.
-          lsprecn(i,j,1,n,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-          if (lsprecn(i,j,1,n,l).lt.0.) lsprecn(i,j,1,n,l)=0.
-        endif
-        if(isec1(6).eq.143) then                         !! CONVECTIVE PREC.
-          convprecn(i,j,1,n,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-          if (convprecn(i,j,1,n,l).lt.0.) convprecn(i,j,1,n,l)=0.
-        endif
-        if(isec1(6).eq.146) sshfn(i,j,1,n,l)= &!! SENS. HEAT FLUX
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if((isec1(6).eq.146).and. &
-             (zsec4(nxn(l)*(nyn(l)-j-1)+i+1).ne.0.)) hflswitch=.true.    ! Heat flux available
-        if(isec1(6).eq.176) then                         !! SOLAR RADIATION
-          ssrn(i,j,1,n,l)=zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-          if (ssrn(i,j,1,n,l).lt.0.) ssrn(i,j,1,n,l)=0.
-        endif
-        if(isec1(6).eq.180) ewss(i,j)= &!! EW SURFACE STRESS
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.181) nsss(i,j)= &!! NS SURFACE STRESS
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(((isec1(6).eq.180).or.(isec1(6).eq.181)).and. &
-             (zsec4(nxn(l)*(nyn(l)-j-1)+i+1).ne.0.)) strswitch=.true.    ! stress available
-        if(isec1(6).eq.129) oron(i,j,l)= &!! ECMWF OROGRAPHY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)/ga
-        if(isec1(6).eq.160) excessoron(i,j,l)= &!! STANDARD DEVIATION OF OROGRAPHY
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.172) lsmn(i,j,l)= &!! ECMWF LAND SEA MASK
-             zsec4(nxn(l)*(nyn(l)-j-1)+i+1)
-        if(isec1(6).eq.131) iumax=max(iumax,nlev_ec-k+1)
-        if(isec1(6).eq.135) iwmax=max(iwmax,nlev_ec-k+1)
-      end do
-    end do
-
-    goto 10                      !! READ NEXT LEVEL OR PARAMETER
-  !
-  ! CLOSING OF INPUT DATA FILE
-  !
-50   call pbclose(lunit,ierr)     !! FINISHED READING / CLOSING GRIB FILE
-
-    if(levdiff2.eq.0) then
-      iwmax=nlev_ec+1
-      do i=0,nxn(l)-1
-        do j=0,nyn(l)-1
-          wwhn(i,j,nlev_ec+1,l)=0.
-        end do
-      end do
-    endif
-
-    do i=0,nxn(l)-1
-      do j=0,nyn(l)-1
-        surfstrn(i,j,1,n,l)=sqrt(ewss(i,j)**2+nsss(i,j)**2)
-      end do
-    end do
-
-    if ((.not.hflswitch).or.(.not.strswitch)) then
-      write(*,*) 'WARNING: No flux data contained in GRIB file ', &
-           wfnamen(l,indj)
-
-  ! CALCULATE USTAR AND SSHF USING THE PROFILE METHOD
-  ! As ECMWF has increased the model resolution, such that now the first model
-  ! level is at about 10 m (where 10-m wind is given), use the 2nd ECMWF level
-  ! (3rd model level in FLEXPART) for the profile method
-  !***************************************************************************
-
-      do i=0,nxn(l)-1
-        do j=0,nyn(l)-1
-        plev1=akz(3)+bkz(3)*psn(i,j,1,n,l)
-        pmean=0.5*(psn(i,j,1,n,l)+plev1)
-        tv=tthn(i,j,3,n,l)*(1.+0.61*qvhn(i,j,3,n,l))
-        fu=-r_air*tv/ga/pmean
-        hlev1=fu*(plev1-psn(i,j,1,n,l))   ! HEIGTH OF FIRST MODEL LAYER
-        ff10m= sqrt(u10n(i,j,1,n,l)**2+v10n(i,j,1,n,l)**2)
-        fflev1=sqrt(uuhn(i,j,3,l)**2+vvhn(i,j,3,l)**2)
-        call pbl_profile(psn(i,j,1,n,l),td2n(i,j,1,n,l),hlev1, &
-             tt2n(i,j,1,n,l),tthn(i,j,3,n,l),ff10m,fflev1, &
-             surfstrn(i,j,1,n,l),sshfn(i,j,1,n,l))
-        if(sshfn(i,j,1,n,l).gt.200.) sshfn(i,j,1,n,l)=200.
-        if(sshfn(i,j,1,n,l).lt.-400.) sshfn(i,j,1,n,l)=-400.
-        end do
-      end do
-    endif
-
-
-  ! Assign 10 m wind to model level at eta=1.0 to have one additional model
-  ! level at the ground
-  ! Specific humidity is taken the same as at one level above
-  ! Temperature is taken as 2 m temperature
-  !**************************************************************************
-
-    do i=0,nxn(l)-1
-      do j=0,nyn(l)-1
-        uuhn(i,j,1,l)=u10n(i,j,1,n,l)
-        vvhn(i,j,1,l)=v10n(i,j,1,n,l)
-        qvhn(i,j,1,n,l)=qvhn(i,j,2,n,l)
-        tthn(i,j,1,n,l)=tt2n(i,j,1,n,l)
-      end do
-    end do
-
-    if(iumax.ne.nuvz-1) stop &
-         'READWIND: NUVZ NOT CONSISTENT FOR A NESTING LEVEL'
-    if(iwmax.ne.nwz) stop &
-         'READWIND: NWZ NOT CONSISTENT FOR A NESTING LEVEL'
-
-  end do
-
-  return
-888   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfnamen(l,indj),' FOR NESTING LEVEL  #### '
-  write(*,*) ' #### ',l,' IS NOT GRIB FORMAT !!!           #### '
-  stop 'Execution terminated'
-
-
-999   write(*,*) ' #### FLEXPART MODEL ERROR! WINDFIELD         #### '
-  write(*,*) ' #### ',wfnamen(l,indj),'                    #### '
-  write(*,*) ' #### CANNOT BE OPENED FOR NESTING LEVEL ',l,'####'
-
-end subroutine readwind_nests
Index: branches/FLEXPART_9.1.3/src/verttransform.f90
===================================================================
--- trunk/src/verttransform.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/verttransform.f90	(revision 14)
@@ -49,4 +49,6 @@
   ! Sabine Eckhardt, March 2007
   ! added the variable cloud for use with scavenging - descr. in com_mod
+  ! Petra Seibert, 2011/2012: Fixing some deficiencies in this modification
+  ! note that also other subroutines are affected by the fix
   !*****************************************************************************
   !                                                                            *
@@ -70,11 +72,13 @@
 
   integer :: ix,jy,kz,iz,n,kmin,kl,klp,ix1,jy1,ixp,jyp,ixm,jym
-  integer :: rain_cloud_above,kz_inv
+ integer :: rain_cloud_above,kz_inv !SE
+  integer icloudtop !PS
   real :: f_qvsat,pressure
-  real :: rh,lsp,convp
+ !real :: rh,lsp,convp
+  real :: rh,lsp,convp,prec,rhmin  
   real :: uvzlev(nuvzmax),rhoh(nuvzmax),pinmconv(nzmax)
   real :: ew,pint,tv,tvold,pold,dz1,dz2,dz,ui,vi
   real :: xlon,ylat,xlonr,dzdx,dzdy
-  real :: dzdx1,dzdx2,dzdy1,dzdy2
+  real :: dzdx1,dzdx2,dzdy1,dzdy2, precmin
   real :: uuaux,vvaux,uupolaux,vvpolaux,ddpol,ffpol,wdummy
   real :: uuh(0:nxmax-1,0:nymax-1,nuvzmax)
@@ -83,5 +87,7 @@
   real :: wwh(0:nxmax-1,0:nymax-1,nwzmax)
   real :: wzlev(nwzmax),uvwzlev(0:nxmax-1,0:nymax-1,nzmax)
+  logical lconvectprec
   real,parameter :: const=r_air/ga
+  parameter (precmin = 0.002) ! minimum prec in mm/h for cloud diagnostics
 
   logical :: init = .true.
@@ -545,38 +551,108 @@
   !   create a cloud and rainout/washout field, clouds occur where rh>80%
   !   total cloudheight is stored at level 0
+
+
+
   do jy=0,nymin1
     do ix=0,nxmin1
-      rain_cloud_above=0
-      lsp=lsprec(ix,jy,1,n)
-      convp=convprec(ix,jy,1,n)
-      cloudsh(ix,jy,n)=0
-      do kz_inv=1,nz-1
-         kz=nz-kz_inv+1
-         pressure=rho(ix,jy,kz,n)*r_air*tt(ix,jy,kz,n)
-         rh=qv(ix,jy,kz,n)/f_qvsat(pressure,tt(ix,jy,kz,n))
-         clouds(ix,jy,kz,n)=0
-         if (rh.gt.0.8) then ! in cloud
-            if ((lsp.gt.0.01).or.(convp.gt.0.01)) then ! cloud and precipitation
-               rain_cloud_above=1
-               cloudsh(ix,jy,n)=cloudsh(ix,jy,n)+ &
-                    height(kz)-height(kz-1)
-               if (lsp.ge.convp) then
-                  clouds(ix,jy,kz,n)=3 ! lsp dominated rainout
-               else
-                  clouds(ix,jy,kz,n)=2 ! convp dominated rainout
-               endif
-            else ! no precipitation
-                  clouds(ix,jy,kz,n)=1 ! cloud
+
+
+
+  !    rain_cloud_above=0
+  !    lsp=lsprec(ix,jy,1,n)
+  !    convp=convprec(ix,jy,1,n)
+  !    cloudsh(ix,jy,n)=0
+  !    do kz_inv=1,nz-1
+  !       kz=nz-kz_inv+1
+  !       pressure=rho(ix,jy,kz,n)*r_air*tt(ix,jy,kz,n)
+  !       rh=qv(ix,jy,kz,n)/f_qvsat(pressure,tt(ix,jy,kz,n))
+  !       clouds(ix,jy,kz,n)=0
+  !       if (rh.gt.0.8) then ! in cloud
+  !          if ((lsp.gt.0.01).or.(convp.gt.0.01)) then ! cloud and precipitation
+  !             rain_cloud_above=1
+  !             cloudsh(ix,jy,n)=cloudsh(ix,jy,n)+ &
+  !                  height(kz)-height(kz-1)
+  !             if (lsp.ge.convp) then
+  !                clouds(ix,jy,kz,n)=3 ! lsp dominated rainout
+  !             else
+  !                clouds(ix,jy,kz,n)=2 ! convp dominated rainout
+  !             endif
+  !          else ! no precipitation
+  !                clouds(ix,jy,kz,n)=1 ! cloud
+  !          endif
+  !       else ! no cloud
+  !          if (rain_cloud_above.eq.1) then ! scavenging
+  !             if (lsp.ge.convp) then
+  !                clouds(ix,jy,kz,n)=5 ! lsp dominated washout
+  !             else
+  !                clouds(ix,jy,kz,n)=4 ! convp dominated washout
+  !             endif
+  !          endif
+  !       endif
+  !    end do
+
+
+   ! PS 3012
+
+             lsp=lsprec(ix,jy,1,n)
+          convp=convprec(ix,jy,1,n)
+          prec=lsp+convp
+          if (lsp.gt.convp) then !  prectype='lsp'
+            lconvectprec = .false.
+          else ! prectype='cp '
+            lconvectprec = .true.
+          endif
+          rhmin = 0.90 ! standard condition for presence of clouds
+!PS       note that original by Sabine Eckhart was 80%
+!PS       however, for T<-20 C we consider saturation over ice
+!PS       so I think 90% should be enough          
+          icloudbot(ix,jy,n)=icmv
+          icloudtop=icmv ! this is just a local variable
+98        do kz=1,nz
+            pressure=rho(ix,jy,kz,n)*r_air*tt(ix,jy,kz,n)
+            rh=qv(ix,jy,kz,n)/f_qvsat(pressure,tt(ix,jy,kz,n))
+!ps            if (prec.gt.0.01) print*,'relhum',prec,kz,rh,height(kz)
+            if (rh .gt. rhmin) then
+              if (icloudbot(ix,jy,n) .eq. icmv) then
+                icloudbot(ix,jy,n)=nint(height(kz))
+              endif
+              icloudtop=nint(height(kz)) ! use int to save memory
             endif
-         else ! no cloud
-            if (rain_cloud_above.eq.1) then ! scavenging
-               if (lsp.ge.convp) then
-                  clouds(ix,jy,kz,n)=5 ! lsp dominated washout
-               else
-                  clouds(ix,jy,kz,n)=4 ! convp dominated washout
-               endif
+          enddo
+
+!PS try to get a cloud thicker than 50 m 
+!PS if there is at least .01 mm/h  - changed to 0.002 and put into
+!PS parameter precpmin        
+          if ((icloudbot(ix,jy,n) .eq. icmv .or. &
+              icloudtop-icloudbot(ix,jy,n) .lt. 50) .and. &
+              prec .gt. precmin) then
+            rhmin = rhmin - 0.05
+            if (rhmin .ge. 0.30) goto 98 ! give up for <= 25% rel.hum.
+          endif
+!PS implement a rough fix for badly represented convection
+!PS is based on looking at a limited set of comparison data
+          if (lconvectprec .and. icloudtop .lt. 6000 .and. &
+             prec .gt. precmin) then 
+
+            if (convp .lt. 0.1) then
+              icloudbot(ix,jy,n) = 500
+              icloudtop =         8000
+            else
+              icloudbot(ix,jy,n) = 0
+              icloudtop =      10000
             endif
-         endif
-      end do
+          endif
+          if (icloudtop .ne. icmv) then
+            icloudthck(ix,jy,n) = icloudtop-icloudbot(ix,jy,n)
+          else
+            icloudthck(ix,jy,n) = icmv
+          endif
+!PS  get rid of too thin clouds      
+          if (icloudthck(ix,jy,n) .lt. 50) then
+            icloudbot(ix,jy,n)=icmv
+            icloudthck(ix,jy,n)=icmv
+          endif
+
+
     end do
   end do
@@ -605,3 +681,5 @@
   !104   continue
   ! close(4)
+
+
 end subroutine verttransform
Index: branches/FLEXPART_9.1.3/src/wetdepo.f90
===================================================================
--- trunk/src/wetdepo.f90	(revision 14)
+++ branches/FLEXPART_9.1.3/src/wetdepo.f90	(revision 14)
@@ -39,4 +39,7 @@
   ! Code may not be correct for decay of deposition!                           *
   !                                                                            *
+  ! Modification by Sabine Eckhart to introduce a new in-/below-cloud
+  ! scheme, not dated
+  ! Petra Seibert, 2011/2012: Fixing some deficiencies in this modification
   !*****************************************************************************
   !                                                                            *
@@ -71,9 +74,11 @@
 
   integer :: jpart,itime,ltsample,loutnext,ldeltat,i,j,ix,jy
-  integer :: ngrid,itage,nage,hz,il,interp_time, n, clouds_v
-  integer :: ks, kp
+  integer :: ngrid,itage,nage,hz,il,interp_time, n , clouds_v !NIK scheme
+  integer :: kz !PS scheme
+  integer :: ks, kp, n1,n2, icbot,ictop, indcloud
+  integer :: scheme_number ! NIK==1, PS ==2
   real :: S_i, act_temp, cl, cle ! in cloud scavenging
   real :: clouds_h ! cloud height for the specific grid point
-  real :: xtn,ytn,lsp,convp,cc,grfraction,prec,wetscav
+  real :: xtn,ytn,lsp,convp,cc,grfraction,prec,wetscav, precsub,f
   real :: wetdeposit(maxspec),restmass
   real,parameter :: smallnum = tiny(0.0) ! smallest number that can be handled
@@ -146,20 +151,38 @@
     interp_time=nint(itime-0.5*ltsample)
 
-    if (ngrid.eq.0) then
-      call interpol_rain(lsprec,convprec,tcc,nxmax,nymax, &
-           1,nx,ny,memind,real(xtra1(jpart)),real(ytra1(jpart)),1, &
-           memtime(1),memtime(2),interp_time,lsp,convp,cc)
-    else
-      call interpol_rain_nests(lsprecn,convprecn,tccn, &
-           nxmaxn,nymaxn,1,maxnests,ngrid,nxn,nyn,memind,xtn,ytn,1, &
-           memtime(1),memtime(2),interp_time,lsp,convp,cc)
-    endif
-
-    if ((lsp.lt.0.01).and.(convp.lt.0.01)) goto 20
+!    PS nest case still needs to be implemented!!    
+!    if (ngrid.eq.0) then
+!      call interpol_rain(lsprec,convprec,tcc,nxmax,nymax, &
+!           1,nx,ny,memind,real(xtra1(jpart)),real(ytra1(jpart)),1, &
+!           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+           call interpol_rain(lsprec,convprec,tcc,     &
+            icloudbot,icloudthck,nxmax,nymax,1,nx,ny,         &
+            memind,sngl(xtra1(jpart)),sngl(ytra1(jpart)),1,memtime(1), &
+            memtime(2),interp_time,lsp,convp,cc,icbot,ictop,icmv)  
+!    else
+!      call interpol_rain_nests(lsprecn,convprecn,tccn, &
+!           nxmaxn,nymaxn,1,maxnests,ngrid,nxn,nyn,memind,xtn,ytn,1, &
+!           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+!    endif
+
+
+ !   if ((lsp.lt.0.01).and.(convp.lt.0.01)) goto 20
+ !PS 2012: subtract a small value, eg 0.01 mm/h, to remove spurious precip
+        prec = lsp+convp
+        precsub = 0.01
+        if (prec .lt. precsub) then
+          goto 20
+        else
+          f = (prec-precsub)/prec
+          lsp = f*lsp
+          convp = f*convp
+        endif
+
 
   ! get the level were the actual particle is in
       do il=2,nz
         if (height(il).gt.ztra1(jpart)) then
-          hz=il-1
+          !hz=il-1
+          kz=il-1
           goto 26
         endif
@@ -174,15 +197,31 @@
   ! scavenging is done
 
-  if (ngrid.eq.0) then
-     clouds_v=clouds(ix,jy,hz,n)
-     clouds_h=cloudsh(ix,jy,n)
-  else
-     clouds_v=cloudsn(ix,jy,hz,n,ngrid)
-     clouds_h=cloudsnh(ix,jy,n,ngrid)
-  endif
-  !write(*,*) 'there is
-  !    + precipitation',(clouds(ix,jy,ihz,n),ihz=1,20),lsp,convp,hz
-  if (clouds_v.le.1) goto 20
-  !write (*,*) 'there is scavenging'
+!old scheme
+!  if (ngrid.eq.0) then
+!     clouds_v=clouds(ix,jy,hz,n)
+!     clouds_h=cloudsh(ix,jy,n)
+!  else
+!     clouds_v=cloudsn(ix,jy,hz,n,ngrid)
+!     clouds_h=cloudsnh(ix,jy,n,ngrid)
+!  endif
+!  !write(*,*) 'there is
+!  !    + precipitation',(clouds(ix,jy,ihz,n),ihz=1,20),lsp,convp,hz
+!  if (clouds_v.le.1) goto 20
+!  !write (*,*) 'there is scavenging'
+
+  ! PS: part of 2011/2012 fix 
+
+        if (ztra1(jpart) .le. float(ictop)) then
+          if (ztra1(jpart) .gt. float(icbot)) then
+            indcloud = 2 ! in-cloud
+          else
+            indcloud = 1 ! below-cloud
+          endif
+        elseif (ictop .eq. icmv) then
+          indcloud = 0 ! no cloud found, use old scheme
+        else
+          goto 20 ! above cloud
+        endif
+
 
   ! 1) Parameterization of the the area fraction of the grid cell where the
@@ -228,6 +267,12 @@
   !**********************************************************
 
-    do ks=1,nspec                                  ! loop over species
+    do ks=1,nspec            ! loop over species
       wetdeposit(ks)=0.
+
+    
+    !conflicting changes to the same routine: 1=NIK 2 =PS
+    scheme_number=2   
+    if (scheme_number.eq.1) then !NIK 
+
       if (weta(ks).gt.0.) then
         if (clouds_v.ge.4) then
@@ -236,4 +281,5 @@
           wetscav=weta(ks)*prec**wetb(ks)                ! scavenging coeff.
   !        write(*,*) 'bel. wetscav: ',wetscav
+
         else ! below_cloud clouds_v is lt 4 and gt 1 -> in cloud scavenging
   !        IN CLOUD SCAVENGING
@@ -245,12 +291,18 @@
              act_temp=tt(ix,jy,hz,n)
           endif
-          cl=2E-7*prec**0.36
+
+! NIK 31.01.2013: SPECIES defined parameters for the in-cloud scavening 
+! weta_in=2.0E-07 (default)
+! wetb_in=0.36 (default)
+! wetc_in=0.9 (default)
+! wetd_in: Scaling factor for the total in-cloud scavenging (default 1.0-no scaling)
+          cl=weta_in(ks)*prec**wetb_in(ks)
           if (dquer(ks).gt.0) then ! is particle
-            S_i=0.9/cl
+            S_i=wetc_in(ks)/cl
            else ! is gas
             cle=(1-cl)/(henry(ks)*(r_air/3500.)*act_temp)+cl
             S_i=1/cle
            endif
-           wetscav=S_i*prec/3.6E6/clouds_h
+           wetscav=S_i*prec/3.6E6/clouds_h/wetd_in(ks)
   !         write(*,*) 'in. wetscav:'
   !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h
@@ -289,4 +341,72 @@
          wetdeposit(ks)=0.
       endif ! weta(k)
+
+     elseif (scheme_number.eq.2) then ! PS
+
+!PS          indcloud=0 ! Use this for FOR TESTING, 
+!PS          will skip the new in/below cloud method !!!             
+
+          if (weta(ks).gt.0.) then
+            if (indcloud .eq. 1) then ! BELOW CLOUD SCAVENGING
+!C               for aerosols and not highliy soluble substances weta=5E-6
+              wetscav=weta(ks)*prec**wetb(ks)                ! scavenging coeff.
+!c             write(*,*) 'bel. wetscav: ',wetscav
+            elseif (indcloud .eq. 2) then !  IN CLOUD SCAVENGING
+              if (ngrid.gt.0) then
+                 act_temp=ttn(ix,jy,kz,n,ngrid)
+              else
+                 act_temp=tt(ix,jy,kz,n)
+              endif
+
+! from NIK              
+! weta_in=2.0E-07 (default)
+! wetb_in=0.36 (default)
+! wetc_in=0.9 (default)
+
+
+              cl=2E-7*prec**0.36
+              if (dquer(ks).gt.0) then ! is particle
+                S_i=0.9/cl
+              else ! is gas
+                cle=(1-cl)/(henry(ks)*(r_air/3500.)*act_temp)+cl
+                S_i=1/cle
+              endif
+              wetscav=S_i*prec/3.6E6/(ictop-icbot) ! 3.6e6 converts mm/h to m/s
+            else ! PS: no cloud diagnosed, old scheme, 
+!CPS          using with fixed a,b for simplicity, one may wish to change!!
+              wetscav = 1.e-4*prec**0.62
+            endif
+
+
+            wetdeposit(ks)=xmass1(jpart,ks)*    &
+            ! (1.-exp(-wetscav*abs(ltsample)))*fraction  ! wet deposition
+             (1.-exp(-wetscav*abs(ltsample)))*grfraction  ! fraction = grfraction (PS) 
+            restmass = xmass1(jpart,ks)-wetdeposit(ks)
+            if (ioutputforeachrelease.eq.1) then
+              kp=npoint(jpart)
+            else
+              kp=1
+            endif
+            if (restmass .gt. smallnum) then
+              xmass1(jpart,ks)=restmass
+!cccccccccccccccc depostatistic
+!c            wetdepo_sum(ks,kp)=wetdepo_sum(ks,kp)+wetdeposit(ks)
+!cccccccccccccccc depostatistic
+            else
+              xmass1(jpart,ks)=0.
+            endif
+!C Correct deposited mass to the last time step when radioactive decay of 
+!C gridded deposited mass was calculated
+            if (decay(ks).gt.0.) then
+              wetdeposit(ks)=wetdeposit(ks)*exp(abs(ldeltat)*decay(ks))
+            endif
+          else  ! weta(k)<0
+             wetdeposit(ks)=0.
+          endif 
+
+     endif !on scheme
+
+
+
     end do
 
@@ -295,11 +415,21 @@
   !*****************************************************************************
 
-    if (ldirect.eq.1) then
-    call wetdepokernel(nclass(jpart),wetdeposit,real(xtra1(jpart)), &
-         real(ytra1(jpart)),nage,kp)
-    if (nested_output.eq.1) call wetdepokernel_nest(nclass(jpart), &
-         wetdeposit,real(xtra1(jpart)),real(ytra1(jpart)), &
-         nage,kp)
-    endif
+!    if (ldirect.eq.1) then
+!    call wetdepokernel(nclass(jpart),wetdeposit,real(xtra1(jpart)), &
+!         real(ytra1(jpart)),nage,kp)
+!    if (nested_output.eq.1) call wetdepokernel_nest(nclass(jpart), &
+!         wetdeposit,real(xtra1(jpart)),real(ytra1(jpart)), &
+!         nage,kp)
+!    endif
+
+   !PS
+        if (ldirect.eq.1) then
+          call wetdepokernel(nclass(jpart),wetdeposit,     &
+             sngl(xtra1(jpart)),sngl(ytra1(jpart)),nage,kp)
+          if (nested_output.eq.1)                          &
+           call wetdepokernel_nest(nclass(jpart),wetdeposit, &
+             sngl(xtra1(jpart)),sngl(ytra1(jpart)),nage,kp)  
+        endif
+
 
 20  continue
Index: branches/FLEXPART_9.1.3/src/wetdepo.f90-9.1.1
===================================================================
--- branches/FLEXPART_9.1.3/src/wetdepo.f90-9.1.1	(revision 14)
+++ branches/FLEXPART_9.1.3/src/wetdepo.f90-9.1.1	(revision 14)
@@ -0,0 +1,310 @@
+!**********************************************************************
+! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
+! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
+! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
+!                                                                     *
+! This file is part of FLEXPART.                                      *
+!                                                                     *
+! FLEXPART is free software: you can redistribute it and/or modify    *
+! it under the terms of the GNU General Public License as published by*
+! the Free Software Foundation, either version 3 of the License, or   *
+! (at your option) any later version.                                 *
+!                                                                     *
+! FLEXPART is distributed in the hope that it will be useful,         *
+! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
+! GNU General Public License for more details.                        *
+!                                                                     *
+! You should have received a copy of the GNU General Public License   *
+! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
+!**********************************************************************
+
+subroutine wetdepo(itime,ltsample,loutnext)
+  !                     i      i        i
+  !*****************************************************************************
+  !                                                                            *
+  ! Calculation of wet deposition using the concept of scavenging coefficients.*
+  ! For lack of detailed information, washout and rainout are jointly treated. *
+  ! It is assumed that precipitation does not occur uniformly within the whole *
+  ! grid cell, but that only a fraction of the grid cell experiences rainfall. *
+  ! This fraction is parameterized from total cloud cover and rates of large   *
+  ! scale and convective precipitation.                                        *
+  !                                                                            *
+  !    Author: A. Stohl                                                        *
+  !                                                                            *
+  !    1 December 1996                                                         *
+  !                                                                            *
+  ! Correction by Petra Seibert, Sept 2002:                                    *
+  ! use centred precipitation data for integration                             *
+  ! Code may not be correct for decay of deposition!                           *
+  !                                                                            *
+  !*****************************************************************************
+  !                                                                            *
+  ! Variables:                                                                 *
+  ! cc [0-1]           total cloud cover                                       *
+  ! convp [mm/h]       convective precipitation rate                           *
+  ! grfraction [0-1]   fraction of grid, for which precipitation occurs        *
+  ! ix,jy              indices of output grid cell for each particle           *
+  ! itime [s]          actual simulation time [s]                              *
+  ! jpart              particle index                                          *
+  ! ldeltat [s]        interval since radioactive decay was computed           *
+  ! lfr, cfr           area fraction covered by precipitation for large scale  *
+  !                    and convective precipitation (dependent on prec. rate)  *
+  ! loutnext [s]       time for which gridded deposition is next output        *
+  ! loutstep [s]       interval at which gridded deposition is output          *
+  ! lsp [mm/h]         large scale precipitation rate                          *
+  ! ltsample [s]       interval over which mass is deposited                   *
+  ! prec [mm/h]        precipitation rate in subgrid, where precipitation occurs*
+  ! wetdeposit         mass that is wet deposited                              *
+  ! wetgrid            accumulated deposited mass on output grid               *
+  ! wetscav            scavenging coefficient                                  *
+  !                                                                            *
+  ! Constants:                                                                 *
+  !                                                                            *
+  !*****************************************************************************
+
+  use point_mod
+  use par_mod
+  use com_mod
+
+  implicit none
+
+  integer :: jpart,itime,ltsample,loutnext,ldeltat,i,j,ix,jy
+  integer :: ngrid,itage,nage,hz,il,interp_time, n, clouds_v
+  integer :: ks, kp
+  real :: S_i, act_temp, cl, cle ! in cloud scavenging
+  real :: clouds_h ! cloud height for the specific grid point
+  real :: xtn,ytn,lsp,convp,cc,grfraction,prec,wetscav
+  real :: wetdeposit(maxspec),restmass
+  real,parameter :: smallnum = tiny(0.0) ! smallest number that can be handled
+  save lfr,cfr
+
+
+  real :: lfr(5) = (/ 0.5,0.65,0.8,0.9,0.95/)
+  real :: cfr(5) = (/ 0.4,0.55,0.7,0.8,0.9 /)
+
+  ! Compute interval since radioactive decay of deposited mass was computed
+  !************************************************************************
+
+  if (itime.le.loutnext) then
+    ldeltat=itime-(loutnext-loutstep)
+  else                                  ! first half of next interval
+    ldeltat=itime-loutnext
+  endif
+
+
+  ! Loop over all particles
+  !************************
+
+  do jpart=1,numpart
+    if (itra1(jpart).eq.-999999999) goto 20
+    if(ldirect.eq.1)then
+      if (itra1(jpart).gt.itime) goto 20
+    else
+      if (itra1(jpart).lt.itime) goto 20
+    endif
+  ! Determine age class of the particle
+    itage=abs(itra1(jpart)-itramem(jpart))
+    do nage=1,nageclass
+      if (itage.lt.lage(nage)) goto 33
+    end do
+33   continue
+
+
+  ! Determine which nesting level to be used
+  !*****************************************
+
+    ngrid=0
+    do j=numbnests,1,-1
+      if ((xtra1(jpart).gt.xln(j)).and.(xtra1(jpart).lt.xrn(j)).and. &
+           (ytra1(jpart).gt.yln(j)).and.(ytra1(jpart).lt.yrn(j))) then
+        ngrid=j
+        goto 23
+      endif
+    end do
+23   continue
+
+
+  ! Determine nested grid coordinates
+  !**********************************
+
+    if (ngrid.gt.0) then
+      xtn=(xtra1(jpart)-xln(ngrid))*xresoln(ngrid)
+      ytn=(ytra1(jpart)-yln(ngrid))*yresoln(ngrid)
+      ix=int(xtn)
+      jy=int(ytn)
+    else
+      ix=int(xtra1(jpart))
+      jy=int(ytra1(jpart))
+    endif
+
+
+  ! Interpolate large scale precipitation, convective precipitation and
+  ! total cloud cover
+  ! Note that interpolated time refers to itime-0.5*ltsample [PS]
+  !********************************************************************
+    interp_time=nint(itime-0.5*ltsample)
+
+    if (ngrid.eq.0) then
+      call interpol_rain(lsprec,convprec,tcc,nxmax,nymax, &
+           1,nx,ny,memind,real(xtra1(jpart)),real(ytra1(jpart)),1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    else
+      call interpol_rain_nests(lsprecn,convprecn,tccn, &
+           nxmaxn,nymaxn,1,maxnests,ngrid,nxn,nyn,memind,xtn,ytn,1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    endif
+
+    if ((lsp.lt.0.01).and.(convp.lt.0.01)) goto 20
+
+  ! get the level were the actual particle is in
+      do il=2,nz
+        if (height(il).gt.ztra1(jpart)) then
+          hz=il-1
+          goto 26
+        endif
+      end do
+26     continue
+
+  n=memind(2)
+  if (abs(memtime(1)-interp_time).lt.abs(memtime(2)-interp_time)) &
+       n=memind(1)
+
+  ! if there is no precipitation or the particle is above the clouds no
+  ! scavenging is done
+
+  if (ngrid.eq.0) then
+     clouds_v=clouds(ix,jy,hz,n)
+     clouds_h=cloudsh(ix,jy,n)
+  else
+     clouds_v=cloudsn(ix,jy,hz,n,ngrid)
+     clouds_h=cloudsnh(ix,jy,n,ngrid)
+  endif
+  !write(*,*) 'there is
+  !    + precipitation',(clouds(ix,jy,ihz,n),ihz=1,20),lsp,convp,hz
+  if (clouds_v.le.1) goto 20
+  !write (*,*) 'there is scavenging'
+
+  ! 1) Parameterization of the the area fraction of the grid cell where the
+  !    precipitation occurs: the absolute limit is the total cloud cover, but
+  !    for low precipitation rates, an even smaller fraction of the grid cell
+  !    is used. Large scale precipitation occurs over larger areas than
+  !    convective precipitation.
+  !**************************************************************************
+
+    if (lsp.gt.20.) then
+      i=5
+    else if (lsp.gt.8.) then
+      i=4
+    else if (lsp.gt.3.) then
+      i=3
+    else if (lsp.gt.1.) then
+      i=2
+    else
+      i=1
+    endif
+
+    if (convp.gt.20.) then
+      j=5
+    else if (convp.gt.8.) then
+      j=4
+    else if (convp.gt.3.) then
+      j=3
+    else if (convp.gt.1.) then
+      j=2
+    else
+      j=1
+    endif
+
+    grfraction=max(0.05,cc*(lsp*lfr(i)+convp*cfr(j))/(lsp+convp))
+
+  ! 2) Computation of precipitation rate in sub-grid cell
+  !******************************************************
+
+    prec=(lsp+convp)/grfraction
+
+  ! 3) Computation of scavenging coefficients for all species
+  !    Computation of wet deposition
+  !**********************************************************
+
+    do ks=1,nspec                                  ! loop over species
+      wetdeposit(ks)=0.
+      if (weta(ks).gt.0.) then
+        if (clouds_v.ge.4) then
+  !          BELOW CLOUD SCAVENGING
+  !          for aerosols and not highliy soluble substances weta=5E-6
+          wetscav=weta(ks)*prec**wetb(ks)                ! scavenging coeff.
+  !        write(*,*) 'bel. wetscav: ',wetscav
+        else ! below_cloud clouds_v is lt 4 and gt 1 -> in cloud scavenging
+  !        IN CLOUD SCAVENGING
+  ! BUGFIX tt for nested fields should be ttn
+  ! sec may 2008
+          if (ngrid.gt.0) then
+             act_temp=ttn(ix,jy,hz,n,ngrid)
+          else
+             act_temp=tt(ix,jy,hz,n)
+          endif
+          cl=2E-7*prec**0.36
+          if (dquer(ks).gt.0) then ! is particle
+            S_i=0.9/cl
+           else ! is gas
+            cle=(1-cl)/(henry(ks)*(r_air/3500.)*act_temp)+cl
+            S_i=1/cle
+           endif
+  !        wetscav=S_i*prec/3.6E6/clouds_h
+!!!! Modification to decrease scavenging and make it more realistic 
+           wetscav=S_i*prec/3.6E6/clouds_h/10.
+  !         write(*,*) 'in. wetscav:'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h
+        endif
+
+
+  !      if (wetscav.le.0) write (*,*) 'neg, or 0 wetscav!'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h,clouds_v
+        wetdeposit(ks)=xmass1(jpart,ks)* &
+             (1.-exp(-wetscav*abs(ltsample)))*grfraction  ! wet deposition
+  !      new particle mass:
+  !      if (wetdeposit(ks).gt.0) then
+  !         write(*,*) 'wetdepo: ',wetdeposit(ks),ks
+  !      endif
+        restmass = xmass1(jpart,ks)-wetdeposit(ks)
+         if (ioutputforeachrelease.eq.1) then
+           kp=npoint(jpart)
+         else
+           kp=1
+         endif
+        if (restmass .gt. smallnum) then
+          xmass1(jpart,ks)=restmass
+  !ccccccccccccccc depostatistic
+  !       wetdepo_sum(ks,kp)=wetdepo_sum(ks,kp)+wetdeposit(ks)
+  !ccccccccccccccc depostatistic
+        else
+          xmass1(jpart,ks)=0.
+        endif
+  ! Correct deposited mass to the last time step when radioactive decay of
+  ! gridded deposited mass was calculated
+       if (decay(ks).gt.0.) then
+          wetdeposit(ks)=wetdeposit(ks) &
+               *exp(abs(ldeltat)*decay(ks))
+       endif
+      else  ! weta(k)
+         wetdeposit(ks)=0.
+      endif ! weta(k)
+    end do
+
+  ! Sabine Eckhard, June 2008 create deposition runs only for forward runs
+  ! Add the wet deposition to accumulated amount on output grid and nested output grid
+  !*****************************************************************************
+
+    if (ldirect.eq.1) then
+    call wetdepokernel(nclass(jpart),wetdeposit,real(xtra1(jpart)), &
+         real(ytra1(jpart)),nage,kp)
+    if (nested_output.eq.1) call wetdepokernel_nest(nclass(jpart), &
+         wetdeposit,real(xtra1(jpart)),real(ytra1(jpart)), &
+         nage,kp)
+    endif
+
+20  continue
+  end do
+
+end subroutine wetdepo
Index: branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.0
===================================================================
--- branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.0	(revision 14)
+++ branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.0	(revision 14)
@@ -0,0 +1,308 @@
+!**********************************************************************
+! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
+! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
+! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
+!                                                                     *
+! This file is part of FLEXPART.                                      *
+!                                                                     *
+! FLEXPART is free software: you can redistribute it and/or modify    *
+! it under the terms of the GNU General Public License as published by*
+! the Free Software Foundation, either version 3 of the License, or   *
+! (at your option) any later version.                                 *
+!                                                                     *
+! FLEXPART is distributed in the hope that it will be useful,         *
+! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
+! GNU General Public License for more details.                        *
+!                                                                     *
+! You should have received a copy of the GNU General Public License   *
+! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
+!**********************************************************************
+
+subroutine wetdepo(itime,ltsample,loutnext)
+  !                     i      i        i
+  !*****************************************************************************
+  !                                                                            *
+  ! Calculation of wet deposition using the concept of scavenging coefficients.*
+  ! For lack of detailed information, washout and rainout are jointly treated. *
+  ! It is assumed that precipitation does not occur uniformly within the whole *
+  ! grid cell, but that only a fraction of the grid cell experiences rainfall. *
+  ! This fraction is parameterized from total cloud cover and rates of large   *
+  ! scale and convective precipitation.                                        *
+  !                                                                            *
+  !    Author: A. Stohl                                                        *
+  !                                                                            *
+  !    1 December 1996                                                         *
+  !                                                                            *
+  ! Correction by Petra Seibert, Sept 2002:                                    *
+  ! use centred precipitation data for integration                             *
+  ! Code may not be correct for decay of deposition!                           *
+  !                                                                            *
+  !*****************************************************************************
+  !                                                                            *
+  ! Variables:                                                                 *
+  ! cc [0-1]           total cloud cover                                       *
+  ! convp [mm/h]       convective precipitation rate                           *
+  ! grfraction [0-1]   fraction of grid, for which precipitation occurs        *
+  ! ix,jy              indices of output grid cell for each particle           *
+  ! itime [s]          actual simulation time [s]                              *
+  ! jpart              particle index                                          *
+  ! ldeltat [s]        interval since radioactive decay was computed           *
+  ! lfr, cfr           area fraction covered by precipitation for large scale  *
+  !                    and convective precipitation (dependent on prec. rate)  *
+  ! loutnext [s]       time for which gridded deposition is next output        *
+  ! loutstep [s]       interval at which gridded deposition is output          *
+  ! lsp [mm/h]         large scale precipitation rate                          *
+  ! ltsample [s]       interval over which mass is deposited                   *
+  ! prec [mm/h]        precipitation rate in subgrid, where precipitation occurs*
+  ! wetdeposit         mass that is wet deposited                              *
+  ! wetgrid            accumulated deposited mass on output grid               *
+  ! wetscav            scavenging coefficient                                  *
+  !                                                                            *
+  ! Constants:                                                                 *
+  !                                                                            *
+  !*****************************************************************************
+
+  use point_mod
+  use par_mod
+  use com_mod
+
+  implicit none
+
+  integer :: jpart,itime,ltsample,loutnext,ldeltat,i,j,ix,jy
+  integer :: ngrid,itage,nage,hz,il,interp_time, n, clouds_v
+  integer :: ks, kp
+  real :: S_i, act_temp, cl, cle ! in cloud scavenging
+  real :: clouds_h ! cloud height for the specific grid point
+  real :: xtn,ytn,lsp,convp,cc,grfraction,prec,wetscav
+  real :: wetdeposit(maxspec),restmass
+  real,parameter :: smallnum = tiny(0.0) ! smallest number that can be handled
+  save lfr,cfr
+
+
+  real :: lfr(5) = (/ 0.5,0.65,0.8,0.9,0.95/)
+  real :: cfr(5) = (/ 0.4,0.55,0.7,0.8,0.9 /)
+
+  ! Compute interval since radioactive decay of deposited mass was computed
+  !************************************************************************
+
+  if (itime.le.loutnext) then
+    ldeltat=itime-(loutnext-loutstep)
+  else                                  ! first half of next interval
+    ldeltat=itime-loutnext
+  endif
+
+
+  ! Loop over all particles
+  !************************
+
+  do jpart=1,numpart
+    if (itra1(jpart).eq.-999999999) goto 20
+    if(ldirect.eq.1)then
+      if (itra1(jpart).gt.itime) goto 20
+    else
+      if (itra1(jpart).lt.itime) goto 20
+    endif
+  ! Determine age class of the particle
+    itage=abs(itra1(jpart)-itramem(jpart))
+    do nage=1,nageclass
+      if (itage.lt.lage(nage)) goto 33
+    end do
+33   continue
+
+
+  ! Determine which nesting level to be used
+  !*****************************************
+
+    ngrid=0
+    do j=numbnests,1,-1
+      if ((xtra1(jpart).gt.xln(j)).and.(xtra1(jpart).lt.xrn(j)).and. &
+           (ytra1(jpart).gt.yln(j)).and.(ytra1(jpart).lt.yrn(j))) then
+        ngrid=j
+        goto 23
+      endif
+    end do
+23   continue
+
+
+  ! Determine nested grid coordinates
+  !**********************************
+
+    if (ngrid.gt.0) then
+      xtn=(xtra1(jpart)-xln(ngrid))*xresoln(ngrid)
+      ytn=(ytra1(jpart)-yln(ngrid))*yresoln(ngrid)
+      ix=int(xtn)
+      jy=int(ytn)
+    else
+      ix=int(xtra1(jpart))
+      jy=int(ytra1(jpart))
+    endif
+
+
+  ! Interpolate large scale precipitation, convective precipitation and
+  ! total cloud cover
+  ! Note that interpolated time refers to itime-0.5*ltsample [PS]
+  !********************************************************************
+    interp_time=nint(itime-0.5*ltsample)
+
+    if (ngrid.eq.0) then
+      call interpol_rain(lsprec,convprec,tcc,nxmax,nymax, &
+           1,nx,ny,memind,real(xtra1(jpart)),real(ytra1(jpart)),1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    else
+      call interpol_rain_nests(lsprecn,convprecn,tccn, &
+           nxmaxn,nymaxn,1,maxnests,ngrid,nxn,nyn,memind,xtn,ytn,1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    endif
+
+    if ((lsp.lt.0.01).and.(convp.lt.0.01)) goto 20
+
+  ! get the level were the actual particle is in
+      do il=2,nz
+        if (height(il).gt.ztra1(jpart)) then
+          hz=il-1
+          goto 26
+        endif
+      end do
+26     continue
+
+  n=memind(2)
+  if (abs(memtime(1)-interp_time).lt.abs(memtime(2)-interp_time)) &
+       n=memind(1)
+
+  ! if there is no precipitation or the particle is above the clouds no
+  ! scavenging is done
+
+  if (ngrid.eq.0) then
+     clouds_v=clouds(ix,jy,hz,n)
+     clouds_h=cloudsh(ix,jy,n)
+  else
+     clouds_v=cloudsn(ix,jy,hz,n,ngrid)
+     clouds_h=cloudsnh(ix,jy,n,ngrid)
+  endif
+  !write(*,*) 'there is
+  !    + precipitation',(clouds(ix,jy,ihz,n),ihz=1,20),lsp,convp,hz
+  if (clouds_v.le.1) goto 20
+  !write (*,*) 'there is scavenging'
+
+  ! 1) Parameterization of the the area fraction of the grid cell where the
+  !    precipitation occurs: the absolute limit is the total cloud cover, but
+  !    for low precipitation rates, an even smaller fraction of the grid cell
+  !    is used. Large scale precipitation occurs over larger areas than
+  !    convective precipitation.
+  !**************************************************************************
+
+    if (lsp.gt.20.) then
+      i=5
+    else if (lsp.gt.8.) then
+      i=4
+    else if (lsp.gt.3.) then
+      i=3
+    else if (lsp.gt.1.) then
+      i=2
+    else
+      i=1
+    endif
+
+    if (convp.gt.20.) then
+      j=5
+    else if (convp.gt.8.) then
+      j=4
+    else if (convp.gt.3.) then
+      j=3
+    else if (convp.gt.1.) then
+      j=2
+    else
+      j=1
+    endif
+
+    grfraction=max(0.05,cc*(lsp*lfr(i)+convp*cfr(j))/(lsp+convp))
+
+  ! 2) Computation of precipitation rate in sub-grid cell
+  !******************************************************
+
+    prec=(lsp+convp)/grfraction
+
+  ! 3) Computation of scavenging coefficients for all species
+  !    Computation of wet deposition
+  !**********************************************************
+
+    do ks=1,nspec                                  ! loop over species
+      wetdeposit(ks)=0.
+      if (weta(ks).gt.0.) then
+        if (clouds_v.ge.4) then
+  !          BELOW CLOUD SCAVENGING
+  !          for aerosols and not highliy soluble substances weta=5E-6
+          wetscav=weta(ks)*prec**wetb(ks)                ! scavenging coeff.
+  !        write(*,*) 'bel. wetscav: ',wetscav
+        else ! below_cloud clouds_v is lt 4 and gt 1 -> in cloud scavenging
+  !        IN CLOUD SCAVENGING
+  ! BUGFIX tt for nested fields should be ttn
+  ! sec may 2008
+          if (ngrid.gt.0) then
+             act_temp=ttn(ix,jy,hz,n,ngrid)
+          else
+             act_temp=tt(ix,jy,hz,n)
+          endif
+          cl=2E-7*prec**0.36
+          if (dquer(ks).gt.0) then ! is particle
+            S_i=0.9/cl
+           else ! is gas
+            cle=(1-cl)/(henry(ks)*(r_air/3500.)*act_temp)+cl
+            S_i=1/cle
+           endif
+           wetscav=S_i*prec/3.6E6/clouds_h
+  !         write(*,*) 'in. wetscav:'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h
+        endif
+
+
+  !      if (wetscav.le.0) write (*,*) 'neg, or 0 wetscav!'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h,clouds_v
+        wetdeposit(ks)=xmass1(jpart,ks)* &
+             (1.-exp(-wetscav*abs(ltsample)))*grfraction  ! wet deposition
+  !      new particle mass:
+  !      if (wetdeposit(ks).gt.0) then
+  !         write(*,*) 'wetdepo: ',wetdeposit(ks),ks
+  !      endif
+        restmass = xmass1(jpart,ks)-wetdeposit(ks)
+         if (ioutputforeachrelease.eq.1) then
+           kp=npoint(jpart)
+         else
+           kp=1
+         endif
+        if (restmass .gt. smallnum) then
+          xmass1(jpart,ks)=restmass
+  !ccccccccccccccc depostatistic
+  !       wetdepo_sum(ks,kp)=wetdepo_sum(ks,kp)+wetdeposit(ks)
+  !ccccccccccccccc depostatistic
+        else
+          xmass1(jpart,ks)=0.
+        endif
+  ! Correct deposited mass to the last time step when radioactive decay of
+  ! gridded deposited mass was calculated
+       if (decay(ks).gt.0.) then
+          wetdeposit(ks)=wetdeposit(ks) &
+               *exp(abs(ldeltat)*decay(ks))
+       endif
+      else  ! weta(k)
+         wetdeposit(ks)=0.
+      endif ! weta(k)
+    end do
+
+  ! Sabine Eckhard, June 2008 create deposition runs only for forward runs
+  ! Add the wet deposition to accumulated amount on output grid and nested output grid
+  !*****************************************************************************
+
+    if (ldirect.eq.1) then
+    call wetdepokernel(nclass(jpart),wetdeposit,real(xtra1(jpart)), &
+         real(ytra1(jpart)),nage,kp)
+    if (nested_output.eq.1) call wetdepokernel_nest(nclass(jpart), &
+         wetdeposit,real(xtra1(jpart)),real(ytra1(jpart)), &
+         nage,kp)
+    endif
+
+20  continue
+  end do
+
+end subroutine wetdepo
Index: branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.2
===================================================================
--- branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.2	(revision 14)
+++ branches/FLEXPART_9.1.3/src/wetdepo.f90-F9.1.2	(revision 14)
@@ -0,0 +1,318 @@
+!**********************************************************************
+! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
+! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
+! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
+!                                                                     *
+! This file is part of FLEXPART.                                      *
+!                                                                     *
+! FLEXPART is free software: you can redistribute it and/or modify    *
+! it under the terms of the GNU General Public License as published by*
+! the Free Software Foundation, either version 3 of the License, or   *
+! (at your option) any later version.                                 *
+!                                                                     *
+! FLEXPART is distributed in the hope that it will be useful,         *
+! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
+! GNU General Public License for more details.                        *
+!                                                                     *
+! You should have received a copy of the GNU General Public License   *
+! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
+!**********************************************************************
+
+subroutine wetdepo(itime,ltsample,loutnext)
+  !                     i      i        i
+  !*****************************************************************************
+  !                                                                            *
+  ! Calculation of wet deposition using the concept of scavenging coefficients.*
+  ! For lack of detailed information, washout and rainout are jointly treated. *
+  ! It is assumed that precipitation does not occur uniformly within the whole *
+  ! grid cell, but that only a fraction of the grid cell experiences rainfall. *
+  ! This fraction is parameterized from total cloud cover and rates of large   *
+  ! scale and convective precipitation.                                        *
+  !                                                                            *
+  !    Author: A. Stohl                                                        *
+  !                                                                            *
+  !    1 December 1996                                                         *
+  !                                                                            *
+  ! Correction by Petra Seibert, Sept 2002:                                    *
+  ! use centred precipitation data for integration                             *
+  ! Code may not be correct for decay of deposition!                           *
+  !                                                                            *
+  ! Modification by Sabine Eckhart to introduce a new in-/below-cloud
+  ! scheme, not dated
+  ! Petra Seibert, 2011/2012: Fixing some deficiencies in this modification
+  ! note that also other subroutines are affected by the fix
+  !*****************************************************************************
+  !                                                                            *
+  ! Variables:                                                                 *
+  ! cc [0-1]           total cloud cover                                       *
+  ! convp [mm/h]       convective precipitation rate                           *
+  ! grfraction [0-1]   fraction of grid, for which precipitation occurs        *
+  ! ix,jy              indices of output grid cell for each particle           *
+  ! itime [s]          actual simulation time [s]                              *
+  ! jpart              particle index                                          *
+  ! ldeltat [s]        interval since radioactive decay was computed           *
+  ! lfr, cfr           area fraction covered by precipitation for large scale  *
+  !                    and convective precipitation (dependent on prec. rate)  *
+  ! loutnext [s]       time for which gridded deposition is next output        *
+  ! loutstep [s]       interval at which gridded deposition is output          *
+  ! lsp [mm/h]         large scale precipitation rate                          *
+  ! ltsample [s]       interval over which mass is deposited                   *
+  ! prec [mm/h]        precipitation rate in subgrid, where precipitation occurs*
+  ! wetdeposit         mass that is wet deposited                              *
+  ! wetgrid            accumulated deposited mass on output grid               *
+  ! wetscav            scavenging coefficient                                  *
+  !                                                                            *
+  ! Constants:                                                                 *
+  !                                                                            *
+  !*****************************************************************************
+
+  use point_mod
+  use par_mod
+  use com_mod
+
+  implicit none
+
+  integer :: jpart,itime,ltsample,loutnext,ldeltat,i,j,ix,jy
+  integer :: ngrid,itage,nage,hz,il,interp_time, n, clouds_v
+  integer :: ks, kp
+  real :: S_i, act_temp, cl, cle ! in cloud scavenging
+  real :: clouds_h ! cloud height for the specific grid point
+  real :: xtn,ytn,lsp,convp,cc,grfraction,prec,wetscav
+  real :: wetdeposit(maxspec),restmass
+  real,parameter :: smallnum = tiny(0.0) ! smallest number that can be handled
+  save lfr,cfr
+
+
+  real :: lfr(5) = (/ 0.5,0.65,0.8,0.9,0.95/)
+  real :: cfr(5) = (/ 0.4,0.55,0.7,0.8,0.9 /)
+
+  ! Compute interval since radioactive decay of deposited mass was computed
+  !************************************************************************
+
+  if (itime.le.loutnext) then
+    ldeltat=itime-(loutnext-loutstep)
+  else                                  ! first half of next interval
+    ldeltat=itime-loutnext
+  endif
+
+
+  ! Loop over all particles
+  !************************
+
+  do jpart=1,numpart
+    if (itra1(jpart).eq.-999999999) goto 20
+    if(ldirect.eq.1)then
+      if (itra1(jpart).gt.itime) goto 20
+    else
+      if (itra1(jpart).lt.itime) goto 20
+    endif
+  ! Determine age class of the particle
+    itage=abs(itra1(jpart)-itramem(jpart))
+    do nage=1,nageclass
+      if (itage.lt.lage(nage)) goto 33
+    end do
+33   continue
+
+
+  ! Determine which nesting level to be used
+  !*****************************************
+
+    ngrid=0
+    do j=numbnests,1,-1
+      if ((xtra1(jpart).gt.xln(j)).and.(xtra1(jpart).lt.xrn(j)).and. &
+           (ytra1(jpart).gt.yln(j)).and.(ytra1(jpart).lt.yrn(j))) then
+        ngrid=j
+        goto 23
+      endif
+    end do
+23   continue
+
+
+  ! Determine nested grid coordinates
+  !**********************************
+
+    if (ngrid.gt.0) then
+      xtn=(xtra1(jpart)-xln(ngrid))*xresoln(ngrid)
+      ytn=(ytra1(jpart)-yln(ngrid))*yresoln(ngrid)
+      ix=int(xtn)
+      jy=int(ytn)
+    else
+      ix=int(xtra1(jpart))
+      jy=int(ytra1(jpart))
+    endif
+
+
+  ! Interpolate large scale precipitation, convective precipitation and
+  ! total cloud cover
+  ! Note that interpolated time refers to itime-0.5*ltsample [PS]
+  !********************************************************************
+    interp_time=nint(itime-0.5*ltsample)
+
+    if (ngrid.eq.0) then
+      call interpol_rain(lsprec,convprec,tcc,nxmax,nymax, &
+           1,nx,ny,memind,real(xtra1(jpart)),real(ytra1(jpart)),1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    else
+      call interpol_rain_nests(lsprecn,convprecn,tccn, &
+           nxmaxn,nymaxn,1,maxnests,ngrid,nxn,nyn,memind,xtn,ytn,1, &
+           memtime(1),memtime(2),interp_time,lsp,convp,cc)
+    endif
+
+    if ((lsp.lt.0.01).and.(convp.lt.0.01)) goto 20
+
+  ! get the level were the actual particle is in
+      do il=2,nz
+        if (height(il).gt.ztra1(jpart)) then
+          hz=il-1
+          goto 26
+        endif
+      end do
+26     continue
+
+  n=memind(2)
+  if (abs(memtime(1)-interp_time).lt.abs(memtime(2)-interp_time)) &
+       n=memind(1)
+
+  ! if there is no precipitation or the particle is above the clouds no
+  ! scavenging is done
+
+  if (ngrid.eq.0) then
+     clouds_v=clouds(ix,jy,hz,n)
+     clouds_h=cloudsh(ix,jy,n)
+  else
+     clouds_v=cloudsn(ix,jy,hz,n,ngrid)
+     clouds_h=cloudsnh(ix,jy,n,ngrid)
+  endif
+  !write(*,*) 'there is
+  !    + precipitation',(clouds(ix,jy,ihz,n),ihz=1,20),lsp,convp,hz
+  if (clouds_v.le.1) goto 20
+  !write (*,*) 'there is scavenging'
+
+  ! 1) Parameterization of the the area fraction of the grid cell where the
+  !    precipitation occurs: the absolute limit is the total cloud cover, but
+  !    for low precipitation rates, an even smaller fraction of the grid cell
+  !    is used. Large scale precipitation occurs over larger areas than
+  !    convective precipitation.
+  !**************************************************************************
+
+    if (lsp.gt.20.) then
+      i=5
+    else if (lsp.gt.8.) then
+      i=4
+    else if (lsp.gt.3.) then
+      i=3
+    else if (lsp.gt.1.) then
+      i=2
+    else
+      i=1
+    endif
+
+    if (convp.gt.20.) then
+      j=5
+    else if (convp.gt.8.) then
+      j=4
+    else if (convp.gt.3.) then
+      j=3
+    else if (convp.gt.1.) then
+      j=2
+    else
+      j=1
+    endif
+
+    grfraction=max(0.05,cc*(lsp*lfr(i)+convp*cfr(j))/(lsp+convp))
+
+  ! 2) Computation of precipitation rate in sub-grid cell
+  !******************************************************
+
+    prec=(lsp+convp)/grfraction
+
+  ! 3) Computation of scavenging coefficients for all species
+  !    Computation of wet deposition
+  !**********************************************************
+
+    do ks=1,nspec                                  ! loop over species
+      wetdeposit(ks)=0.
+      if (weta(ks).gt.0.) then
+        if (clouds_v.ge.4) then
+  !          BELOW CLOUD SCAVENGING
+  !          for aerosols and not highliy soluble substances weta=5E-6
+          wetscav=weta(ks)*prec**wetb(ks)                ! scavenging coeff.
+  !        write(*,*) 'bel. wetscav: ',wetscav
+        else ! below_cloud clouds_v is lt 4 and gt 1 -> in cloud scavenging
+  !        IN CLOUD SCAVENGING
+  ! BUGFIX tt for nested fields should be ttn
+  ! sec may 2008
+          if (ngrid.gt.0) then
+             act_temp=ttn(ix,jy,hz,n,ngrid)
+          else
+             act_temp=tt(ix,jy,hz,n)
+          endif
+
+! NIK 31.01.2013: SPECIES defined parameters for the in-cloud scavening 
+! weta_in=2.0E-07 (default)
+! wetb_in=0.36 (default)
+! wetc_in=0.9 (default)
+! wetd_in: Scaling factor for the total in-cloud scavenging (default 1.0-no scaling)
+          cl=weta_in(ks)*prec**wetb_in(ks)
+          if (dquer(ks).gt.0) then ! is particle
+            S_i=wetc_in(ks)/cl
+           else ! is gas
+            cle=(1-cl)/(henry(ks)*(r_air/3500.)*act_temp)+cl
+            S_i=1/cle
+           endif
+           wetscav=S_i*prec/3.6E6/clouds_h/wetd_in(ks)
+  !         write(*,*) 'in. wetscav:'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h
+        endif
+
+
+  !      if (wetscav.le.0) write (*,*) 'neg, or 0 wetscav!'
+  !    +          ,wetscav,cle,cl,act_temp,prec,clouds_h,clouds_v
+        wetdeposit(ks)=xmass1(jpart,ks)* &
+             (1.-exp(-wetscav*abs(ltsample)))*grfraction  ! wet deposition
+  !      new particle mass:
+  !      if (wetdeposit(ks).gt.0) then
+  !         write(*,*) 'wetdepo: ',wetdeposit(ks),ks
+  !      endif
+        restmass = xmass1(jpart,ks)-wetdeposit(ks)
+         if (ioutputforeachrelease.eq.1) then
+           kp=npoint(jpart)
+         else
+           kp=1
+         endif
+        if (restmass .gt. smallnum) then
+          xmass1(jpart,ks)=restmass
+  !ccccccccccccccc depostatistic
+  !       wetdepo_sum(ks,kp)=wetdepo_sum(ks,kp)+wetdeposit(ks)
+  !ccccccccccccccc depostatistic
+        else
+          xmass1(jpart,ks)=0.
+        endif
+  ! Correct deposited mass to the last time step when radioactive decay of
+  ! gridded deposited mass was calculated
+       if (decay(ks).gt.0.) then
+          wetdeposit(ks)=wetdeposit(ks) &
+               *exp(abs(ldeltat)*decay(ks))
+       endif
+      else  ! weta(k)
+         wetdeposit(ks)=0.
+      endif ! weta(k)
+    end do
+
+  ! Sabine Eckhard, June 2008 create deposition runs only for forward runs
+  ! Add the wet deposition to accumulated amount on output grid and nested output grid
+  !*****************************************************************************
+
+    if (ldirect.eq.1) then
+    call wetdepokernel(nclass(jpart),wetdeposit,real(xtra1(jpart)), &
+         real(ytra1(jpart)),nage,kp)
+    if (nested_output.eq.1) call wetdepokernel_nest(nclass(jpart), &
+         wetdeposit,real(xtra1(jpart)),real(ytra1(jpart)), &
+         nage,kp)
+    endif
+
+20  continue
+  end do
+
+end subroutine wetdepo
