Index: src/FLEXPART.f90
===================================================================
--- src/FLEXPART.f90	(revision 49e63b96c7b151b073dea74ff5bc766921de3b31)
+++ src/FLEXPART.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -44,5 +44,5 @@
   implicit none
 
-  integer :: i,j,ix,jy,inest, iopt
+  integer :: i, j, ix, jy, inest, iopt
   integer :: idummy = -320
   character(len=256) :: inline_options  !pathfile, flexversion, arg2
@@ -62,5 +62,5 @@
   ! FLEXPART version string
   flexversion_major = '10' ! Major version number, also used for species file names
-  flexversion='Version '//trim(flexversion_major)//'.4.1 (2020-08-05)'
+  flexversion='Version '//trim(flexversion_major)//'.4.1 (2022-11-09)'
   verbosity=0
 
@@ -69,12 +69,12 @@
 
   inline_options='none'
-  select case (iargc())
+  select case (command_argument_count())  ! Portable standard Fortran intrinsic procedure
   case (2)
-    call getarg(1,arg1)
+    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
     pathfile=arg1
-    call getarg(2,arg2)
+    call get_command_argument(2,arg2)     ! Portable standard Fortran intrinsic procedure
     inline_options=arg2
   case (1)
-    call getarg(1,arg1)
+    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
     pathfile=arg1
     if (arg1(1:1).eq.'-') then
@@ -90,5 +90,5 @@
   print*,'Welcome to FLEXPART ', trim(flexversion)
   print*,'FLEXPART is free software released under the GNU General Public License.'
- 
+
 
   ! Ingest inline options
@@ -112,12 +112,12 @@
     endif
     if (trim(inline_options).eq.'-i') then
-       print*, 'Info mode: provide detailed run specific information and stop'
-       verbosity=1
-       info_flag=1
+      print*, 'Info mode: provide detailed run specific information and stop'
+      verbosity=1
+      info_flag=1
     endif
     if (trim(inline_options).eq.'-i2') then
-       print*, 'Info mode: provide more detailed run specific information and stop'
-       verbosity=2
-       info_flag=1
+      print*, 'Info mode: provide more detailed run specific information and stop'
+      verbosity=2
+      info_flag=1
     endif
   endif
@@ -138,5 +138,5 @@
      !print*,'length(4)',length(4)
      !count=0,count_rate=1000
-     CALL SYSTEM_CLOCK(count_clock0, count_rate, count_max)
+     call system_clock(count_clock0, count_rate, count_max)
      !WRITE(*,*) 'SYSTEM_CLOCK',count, count_rate, count_max
      !WRITE(*,*) 'SYSTEM_CLOCK, count_clock0', count_clock0
@@ -159,5 +159,5 @@
       CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
       write(*,*) 'SYSTEM_CLOCK',(count_clock - count_clock0)/real(count_rate) !, count_rate, count_max
-    endif     
+    endif
   endif
 
@@ -217,7 +217,7 @@
   ! both for the mother domain and eventual nests
   !**********************************************
- 
-  if (verbosity.gt.0) then
-     write(*,*) 'call gridcheck'
+
+  if (verbosity.gt.0) then
+    write(*,*) 'call gridcheck'
   endif
 
@@ -258,5 +258,5 @@
 
   if (verbosity.eq.1) then
-     print*,'call readreceptors'
+    print*,'call readreceptors'
   endif
   call readreceptors
@@ -267,5 +267,4 @@
   !call readspecies
 
-
   ! Read the landuse inventory
   !***************************
@@ -329,5 +328,5 @@
     if (verbosity.gt.0) then
       print*,'numpart=0, numparticlecount=0'
-    endif    
+    endif
     numpart=0
     numparticlecount=0
Index: src/FLEXPART_MPI.f90
===================================================================
--- src/FLEXPART_MPI.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/FLEXPART_MPI.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -44,5 +44,5 @@
   implicit none
 
-  integer :: i,j,ix,jy,inest
+  integer :: i, j, ix, jy, inest, iopt
   integer :: idummy = -320
   character(len=256) :: inline_options  !pathfile, flexversion, arg2
@@ -71,7 +71,8 @@
   call gasdev1(idummy,rannumb(maxrand),rannumb(maxrand-1))
 
+
   ! FLEXPART version string
   flexversion_major = '10' ! Major version number, also used for species file names
-  flexversion='Ver. '//trim(flexversion_major)//'.2beta MPI (2017-08-01)'
+  flexversion='Version '//trim(flexversion_major)//'.4.1 MPI (2022-11-09)'
   verbosity=0
 
@@ -80,12 +81,12 @@
 
   inline_options='none'
-  select case (iargc())
+  select case (command_argument_count())  ! Portable standard Fortran intrinsic procedure
   case (2)
-    call getarg(1,arg1)
+    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
     pathfile=arg1
-    call getarg(2,arg2)
+    call get_command_argument(2,arg2)     ! Portable standard Fortran intrinsic procedure
     inline_options=arg2
   case (1)
-    call getarg(1,arg1)
+    call get_command_argument(1,arg1)     ! Portable standard Fortran intrinsic procedure
     pathfile=arg1
     if (arg1(1:1).eq.'-') then
@@ -97,19 +98,30 @@
   end select
   
-  if (lroot) then
   ! Print the GPL License statement
   !*******************************************************
+  if (lroot) then
     print*,'Welcome to FLEXPART ', trim(flexversion)
     print*,'FLEXPART is free software released under the GNU General Public License.'
   endif
-  
+
+
+  ! Ingest inline options
+  !*******************************************************
   if (inline_options(1:1).eq.'-') then
-    if (trim(inline_options).eq.'-v'.or.trim(inline_options).eq.'-v1') then
-      print*, 'Verbose mode 1: display detailed information during run'
+    print*,'inline_options:',inline_options
+    !verbose mode
+    iopt=index(inline_options,'v') 
+    if (iopt.gt.0) then
       verbosity=1
-    endif
-    if (trim(inline_options).eq.'-v2') then
-      print*, 'Verbose mode 2: display more detailed information during run'
-      verbosity=2
+      !print*, iopt, inline_options(iopt+1:iopt+1)
+      if  (trim(inline_options(iopt+1:iopt+1)).eq.'2') then
+        print*, 'Verbose mode 2: display more detailed information during run'
+        verbosity=2
+      endif
+    endif
+    !debug mode 
+    iopt=index(inline_options,'d')
+    if (iopt.gt.0) then
+      debug_mode=.true.
     endif
     if (trim(inline_options).eq.'-i') then
@@ -125,4 +137,11 @@
   endif
            
+  if (verbosity.gt.0) then
+    print*, 'nxmax=',nxmax
+    print*, 'nymax=',nymax
+    print*, 'nzmax=',nzmax
+    print*,'nxshift=',nxshift 
+  endif
+  
   if (verbosity.gt.0) then
     write(*,*) 'call readpaths'
@@ -133,5 +152,5 @@
      !print*,'length(4)',length(4)
      !count=0,count_rate=1000
-    call system_clock(count_clock0, count_rate, count_max)
+     call system_clock(count_clock0, count_rate, count_max)
      !WRITE(*,*) 'SYSTEM_CLOCK',count, count_rate, count_max
      !WRITE(*,*) 'SYSTEM_CLOCK, count_clock0', count_clock0
@@ -157,12 +176,11 @@
   endif
 
-  ! Initialize arrays in com_mod 
+  ! Initialize arrays in com_mod
   !*****************************
-
   if(.not.(lmpreader.and.lmp_use_reader)) call com_mod_allocate_part(maxpart_mpi)
 
 
-! Read the age classes to be used
-!********************************
+  ! Read the age classes to be used
+  !********************************
   if (verbosity.gt.0 .and. lroot) then
     write(*,*) 'call readageclasses'
@@ -185,4 +203,7 @@
   ! Detect metdata format
   !**********************
+  if (verbosity.gt.0 .and. lroot) then
+    write(*,*) 'call detectformat'
+  endif
 
   metdata_format = detectformat()
@@ -207,7 +228,7 @@
   call com_mod_allocate_nests
 
-! Read the model grid specifications,
-! both for the mother domain and eventual nests
-!**********************************************
+  ! Read the model grid specifications,
+  ! both for the mother domain and eventual nests
+  !**********************************************
 
   if (verbosity.gt.0 .and. lroot) then
@@ -221,5 +242,4 @@
   end if
 
-
   if (verbosity.gt.1 .and. lroot) then   
     call system_clock(count_clock, count_rate, count_max)
@@ -227,5 +247,4 @@
   endif      
 
-
   if (verbosity.gt.0 .and. lroot) then
     write(*,*) 'call gridcheck_nests'
@@ -233,10 +252,9 @@
   call gridcheck_nests
 
-
-! Read the output grid specifications
-!************************************
-
-  if (verbosity.gt.0 .and. lroot) then
-    WRITE(*,*) 'call readoutgrid'
+  ! Read the output grid specifications
+  !************************************
+
+  if (verbosity.gt.0 .and. lroot) then
+    write(*,*) 'call readoutgrid'
   endif
 
@@ -246,5 +264,5 @@
     call readoutgrid_nest
     if (verbosity.gt.0.and.lroot) then
-      WRITE(*,*) '# readoutgrid_nest'
+      write(*,*) '# readoutgrid_nest'
     endif
   endif
@@ -263,5 +281,4 @@
   !call readspecies
 
-
   ! Read the landuse inventory
   !***************************
@@ -272,7 +289,6 @@
   call readlanduse
 
-
-! Assign fractional cover of landuse classes to each ECMWF grid point
-!********************************************************************
+  ! Assign fractional cover of landuse classes to each ECMWF grid point
+  !********************************************************************
 
   if (verbosity.gt.0 .and. lroot) then
@@ -289,7 +305,6 @@
   call readreleases
 
-
-! Read and compute surface resistances to dry deposition of gases
-!****************************************************************
+  ! Read and compute surface resistances to dry deposition of gases
+  !****************************************************************
 
   if (verbosity.gt.0 .and. lroot) then
@@ -305,5 +320,4 @@
     print*,'call coordtrafo'
   endif
-
 
   ! Initialize all particles to non-existent
@@ -337,9 +351,7 @@
   endif
 
-
   ! Calculate volume, surface area, etc., of all output grid cells
   ! Allocate fluxes and OHfield if necessary
   !***************************************************************
-
 
   if (verbosity.gt.0 .and. lroot) then
@@ -387,5 +399,5 @@
 
     call writeheader
-! FLEXPART 9.2 ticket ?? write header in ASCII format 
+    ! FLEXPART 9.2 ticket ?? write header in ASCII format 
     call writeheader_txt
 
@@ -445,6 +457,6 @@
   end if
 
-! Calculate particle trajectories
-!********************************
+  ! Calculate particle trajectories
+  !********************************
 
   if (verbosity.gt.0.and. lroot) then
Index: src/gridcheck_ecmwf.f90
===================================================================
--- src/gridcheck_ecmwf.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/gridcheck_ecmwf.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -103,4 +103,6 @@
   ! OPENING OF DATA FILE (GRIB CODE)
   !
+  write(*,*)   'Reading: '//path(3)(1:length(3)) &
+       //trim(wfname(ifn))
 5 call grib_open_file(ifile,path(3)(1:length(3)) &
        //trim(wfname(ifn)),'r',iret)
@@ -418,5 +420,5 @@
 
   nuvz=iumax
-  nwz =iwmax
+  nwz =iwmax + 1       ! +1 needed if input contains only lower levels
   if(nuvz.eq.nlev_ec) nwz=nlev_ec+1
 
Index: src/gridcheck_gfs.f90
===================================================================
--- src/gridcheck_gfs.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/gridcheck_gfs.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -111,4 +111,6 @@
   ! OPENING OF DATA FILE (GRIB CODE)
   !
+  write(*,*)     'Reading: '//path(3)(1:length(3)) &
+         //trim(wfname(ifn))
 5   call grib_open_file(ifile,path(3)(1:length(3)) &
          //trim(wfname(ifn)),'r',iret)
Index: src/gridcheck_nests.f90
===================================================================
--- src/gridcheck_nests.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/gridcheck_nests.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -77,4 +77,7 @@
   igrib=0
   iret=0
+
+  write(*,*) 'Reading: '//path(numpath+2*(l-1)+1) &
+         (1:length(numpath+2*(l-1)+1))//trim(wfnamen(l,ifn))
 
 5   call grib_open_file(ifile,path(numpath+2*(l-1)+1) &
@@ -326,5 +329,5 @@
 
   nuvzn=iumax
-  nwzn=iwmax
+  nwzn=iwmax + 1       ! +1 needed if input contains only lower levels
   if(nuvzn.eq.nlev_ec) nwzn=nlev_ecn+1
 
Index: src/par_mod.f90
===================================================================
--- src/par_mod.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/par_mod.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -131,4 +131,7 @@
   !*********************************************
   
+  ! NOTE: dimensioning of zsec2 in gridcheck depends on nuvzmax, therefore nuvzmax
+  ! must represent all levels even if only lower levels are in the input files.
+
   ! ECMWF
 ! integer,parameter :: nxmax=361,nymax=181,nuvzmax=92,nwzmax=92,nzmax=92,nxshift=359 ! 1.0 degree 92 level
Index: src/readreleases.f90
===================================================================
--- src/readreleases.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readreleases.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -555,4 +555,7 @@
         ireleaseend(numpoint)=int((jul2-bdate)*86400.)
       else
+        write(*,*) 'FLEXPART MODEL WARNING'
+        write(*,*) 'Too few particles to randomize release,'
+        write(*,*) 'release time set to mid-point of release interval'
         ireleasestart(numpoint)=int((julm-bdate)*86400.)
         ireleaseend(numpoint)=int((julm-bdate)*86400.)
Index: src/readspecies.f90
===================================================================
--- src/readspecies.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readspecies.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -104,4 +104,6 @@
   specnum(pos_spec)=id_spec
   write(aspecnumb,'(i3.3)') specnum(pos_spec)
+  write(*,*) 'Reading: '// &
+                        path(1)(1:length(1))//'SPECIES/SPECIES_'//aspecnumb
   open(unitspecies,file=path(1)(1:length(1))//'SPECIES/SPECIES_'//aspecnumb,status='old',form='formatted',err=998)
 !write(*,*) 'reading SPECIES',specnum(pos_spec)
Index: src/readwind_ecmwf.f90
===================================================================
--- src/readwind_ecmwf.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readwind_ecmwf.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -103,4 +103,6 @@
 ! OPENING OF DATA FILE (GRIB CODE)
 !
+  write(*,*)   'Reading: '//path(3)(1:length(3)) &
+       //trim(wfname(indj))
 5 call grib_open_file(ifile,path(3)(1:length(3)) &
        //trim(wfname(indj)),'r',iret)
@@ -386,12 +388,12 @@
   endif
 
-  if(levdiff2.eq.0) then
-    iwmax=nlev_ec+1
+!  if(levdiff2.eq.0) then
+    iwmax=iwmax+1
     do i=0,nxmin1
       do j=0,nymin1
-        wwh(i,j,nlev_ec+1)=0.
+        wwh(i,j,iwmax)=0.
       end do
     end do
-  endif
+!  endif
 
 ! For global fields, assign the leftmost data column also to the rightmost
Index: src/readwind_ecmwf_mpi.f90
===================================================================
--- src/readwind_ecmwf_mpi.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readwind_ecmwf_mpi.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -113,4 +113,6 @@
 ! OPENING OF DATA FILE (GRIB CODE)
 !
+  write(*,*)   'Reading: '//path(3)(1:length(3)) &
+       //trim(wfname(indj))
 5 call grib_open_file(ifile,path(3)(1:length(3)) &
        //trim(wfname(indj)),'r',iret)
@@ -394,12 +396,12 @@
   endif
 
-  if(levdiff2.eq.0) then
-    iwmax=nlev_ec+1
+!  if(levdiff2.eq.0) then
+    iwmax=iwmax+1
     do i=0,nxmin1
       do j=0,nymin1
-        wwh(i,j,nlev_ec+1)=0.
+        wwh(i,j,iwmax)=0.
       end do
     end do
-  endif
+!  endif
 
 ! For global fields, assign the leftmost data column also to the rightmost
Index: src/readwind_gfs.f90
===================================================================
--- src/readwind_gfs.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readwind_gfs.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -103,4 +103,6 @@
 
   !HSO
+  write(*,*)   'Reading: '//path(3)(1:length(3)) &
+         //trim(wfname(indj))
   call grib_open_file(ifile,path(3)(1:length(3)) &
          //trim(wfname(indj)),'r',iret)
Index: src/readwind_nests.f90
===================================================================
--- src/readwind_nests.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/readwind_nests.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -79,5 +79,6 @@
   ! OPENING OF DATA FILE (GRIB CODE)
   !
-
+    write(*,*)   'Reading: '//path(numpath+2*(l-1)+1) &
+         (1:length(numpath+2*(l-1)+1))//trim(wfnamen(l,indj))
 5   call grib_open_file(ifile,path(numpath+2*(l-1)+1) &
          (1:length(numpath+2*(l-1)+1))//trim(wfnamen(l,indj)),'r')
@@ -365,12 +366,12 @@
   endif
 
-  if(levdiff2.eq.0) then
-    iwmax=nlev_ec+1
+!  if(levdiff2.eq.0) then
+    iwmax=iwmax+1
     do i=0,nxn(l)-1
       do j=0,nyn(l)-1
-        wwhn(i,j,nlev_ec+1,l)=0.
+        wwhn(i,j,iwmax,l)=0.
       end do
     end do
-  endif
+!  endif
 
   do i=0,nxn(l)-1
Index: src/writeheader_txt.f90
===================================================================
--- src/writeheader_txt.f90	(revision 92fab6545ef2a8e57cadc977df94b6b510318a1d)
+++ src/writeheader_txt.f90	(revision dba422187e10650e160348f0a0271adfac6b8b88)
@@ -52,5 +52,5 @@
   
   write(unitheader,*) '# ibdate,ibtime, iedate, ietime, flexversion'
-  write(unitheader,*) ibdate, ibtime, iedate, ietime, trim(flexversion) !  'FLEXPART V9.0'
+  write(unitheader,*) ibdate, ibtime, iedate, ietime, trim(flexversion)
   !if (ldirect.eq.1) then
   !  write(unitheader,*) ibdate,ibtime,trim(flexversion) !  'FLEXPART V9.0'
