startup Subroutine

public subroutine startup()

Uses

  • proc~~startup~~UsesGraph proc~startup modstartup::startup module~modboundary modboundary proc~startup->module~modboundary module~moddriver moddriver proc~startup->module~moddriver module~modfields modfields proc~startup->module~modfields module~modforces modforces proc~startup->module~modforces module~modglobal modglobal proc~startup->module~modglobal module~modibmdata modibmdata proc~startup->module~modibmdata module~modinlet modinlet proc~startup->module~modinlet module~modinletdata modinletdata proc~startup->module~modinletdata module~modmpi modmpi proc~startup->module~modmpi module~modpois modpois proc~startup->module~modpois module~modsubgrid modsubgrid proc~startup->module~modsubgrid module~modsurfdata modsurfdata proc~startup->module~modsurfdata module~modthermodynamics modthermodynamics proc~startup->module~modthermodynamics module~moddriver->module~modinletdata module~modinlet->module~modinletdata mpi mpi module~modmpi->mpi module~modsubgriddata modsubgriddata module~modsubgrid->module~modsubgriddata

Arguments

None

Calls

proc~~startup~~CallsGraph proc~startup modstartup::startup mpi_bcast mpi_bcast proc~startup->mpi_bcast proc~calcfluidvolumes modforces::calcfluidvolumes proc~startup->proc~calcfluidvolumes proc~checkinitvalues modstartup::checkinitvalues proc~startup->proc~checkinitvalues proc~createmasks modstartup::createmasks proc~startup->proc~createmasks proc~createscals scalsource.f90::createscals proc~startup->proc~createscals proc~initboundary modboundary::initboundary proc~startup->proc~initboundary proc~initdriver moddriver::initdriver proc~startup->proc~initdriver proc~initfields modfields::initfields proc~startup->proc~initfields proc~initglobal modglobal::initglobal proc~startup->proc~initglobal proc~initinlet modinlet::initinlet proc~startup->proc~initinlet proc~initpois modpois::initpois proc~startup->proc~initpois proc~initsubgrid modsubgrid::initsubgrid proc~startup->proc~initsubgrid proc~initthermodynamics modthermodynamics::initthermodynamics proc~startup->proc~initthermodynamics proc~readinitfiles modstartup::readinitfiles proc~startup->proc~readinitfiles proc~fluidvolume modforces::fluidvolume proc~calcfluidvolumes->proc~fluidvolume proc~uoutletarea modforces::uoutletarea proc~calcfluidvolumes->proc~uoutletarea proc~voutletarea modforces::voutletarea proc~calcfluidvolumes->proc~voutletarea proc~checkinitvalues->mpi_bcast mpi_finalize mpi_finalize proc~checkinitvalues->mpi_finalize proc~createmasks->mpi_bcast mpi_allreduce mpi_allreduce proc~createmasks->mpi_allreduce proc~initglobal->mpi_bcast float float proc~initglobal->float proc~readzincoord modinlet::readzincoord proc~initinlet->proc~readzincoord proc~subgridnamelist modsubgrid::subgridnamelist proc~initsubgrid->proc~subgridnamelist proc~readinitfiles->mpi_bcast proc~avexy_ibm modmpi::avexy_ibm proc~readinitfiles->proc~avexy_ibm proc~boundary modboundary::boundary proc~readinitfiles->proc~boundary proc~calc_halflev modthermodynamics::calc_halflev proc~readinitfiles->proc~calc_halflev proc~drivergen moddriver::drivergen proc~readinitfiles->proc~drivergen proc~randomnize modstartup::randomnize proc~readinitfiles->proc~randomnize proc~readdriverfile moddriver::readdriverfile proc~readinitfiles->proc~readdriverfile proc~readinletfile modinlet::readinletfile proc~readinitfiles->proc~readinletfile proc~readrestartfiles modstartup::readrestartfiles proc~readinitfiles->proc~readrestartfiles proc~slabsum modmpi::slabsum proc~readinitfiles->proc~slabsum proc~thermodynamics modthermodynamics::thermodynamics proc~readinitfiles->proc~thermodynamics proc~avexy_ibm->mpi_allreduce proc~boundary->proc~drivergen proc~cyclichi modboundary::cyclichi proc~boundary->proc~cyclichi proc~cyclichj modboundary::cyclichj proc~boundary->proc~cyclichj proc~cyclicmi modboundary::cyclicmi proc~boundary->proc~cyclicmi proc~cyclicmj modboundary::cyclicmj proc~boundary->proc~cyclicmj proc~cyclicqi modboundary::cyclicqi proc~boundary->proc~cyclicqi proc~cyclicqj modboundary::cyclicqj proc~boundary->proc~cyclicqj proc~cyclicsi modboundary::cyclicsi proc~boundary->proc~cyclicsi proc~cyclicsj modboundary::cyclicsj proc~boundary->proc~cyclicsj proc~fluxtop modboundary::fluxtop proc~boundary->proc~fluxtop proc~fluxtopscal modboundary::fluxtopscal proc~boundary->proc~fluxtopscal proc~inletgen modinlet::inletgen proc~boundary->proc~inletgen proc~inletgennotemp modinlet::inletgennotemp proc~boundary->proc~inletgennotemp proc~inlettop modboundary::inlettop proc~boundary->proc~inlettop proc~iohi modboundary::iohi proc~boundary->proc~iohi proc~iolet modboundary::iolet proc~boundary->proc~iolet proc~ioqi modboundary::ioqi proc~boundary->proc~ioqi proc~iosi modboundary::iosi proc~boundary->proc~iosi proc~scalrec modboundary::scalrec proc~boundary->proc~scalrec proc~scalsirane modboundary::scalSIRANE proc~boundary->proc~scalsirane proc~valuetop modboundary::valuetop proc~boundary->proc~valuetop proc~valuetopscal modboundary::valuetopscal proc~boundary->proc~valuetopscal proc~writedriverfile moddriver::writedriverfile proc~drivergen->proc~writedriverfile proc~sumy_ibm modmpi::sumy_ibm proc~fluidvolume->proc~sumy_ibm proc~excjs modmpi::excjs proc~readinletfile->proc~excjs proc~yinterpolate modinlet::yinterpolate proc~readinletfile->proc~yinterpolate proc~zinterpolate modinlet::zinterpolate proc~readinletfile->proc~zinterpolate proc~zinterpolatet modinlet::zinterpolatet proc~readinletfile->proc~zinterpolatet proc~zinterpolatew modinlet::zinterpolatew proc~readinletfile->proc~zinterpolatew proc~zinterpolate1d modinlet::zinterpolate1d proc~readrestartfiles->proc~zinterpolate1d proc~zinterpolate2d modinlet::zinterpolate2d proc~readrestartfiles->proc~zinterpolate2d proc~zinterpolatet1d modinlet::zinterpolatet1d proc~readrestartfiles->proc~zinterpolatet1d proc~zinterpolatew1d modinlet::zinterpolatew1d proc~readrestartfiles->proc~zinterpolatew1d proc~readzincoord->mpi_bcast proc~slabsum->mpi_allreduce proc~subgridnamelist->mpi_bcast proc~thermodynamics->proc~avexy_ibm proc~thermodynamics->proc~calc_halflev proc~calthv modthermodynamics::calthv proc~thermodynamics->proc~calthv proc~diagfld modthermodynamics::diagfld proc~thermodynamics->proc~diagfld proc~thermo modthermodynamics::thermo proc~thermodynamics->proc~thermo proc~uoutletarea->proc~sumy_ibm proc~voutletarea->mpi_bcast proc~cyclichj->proc~excjs proc~cyclicmj->proc~excjs proc~cyclicqj->proc~excjs proc~cyclicsj->proc~excjs proc~diagfld->proc~avexy_ibm proc~fromztop modthermodynamics::fromztop proc~diagfld->proc~fromztop mpi_sendrecv mpi_sendrecv proc~excjs->mpi_sendrecv proc~inletgen->proc~readinletfile proc~inletgen->proc~slabsum proc~blthicknesst modinlet::blthicknesst proc~inletgen->proc~blthicknesst proc~dispthicknessexp modinlet::dispthicknessexp proc~inletgen->proc~dispthicknessexp proc~enthalpythickness modinlet::enthalpythickness proc~inletgen->proc~enthalpythickness proc~momentumthicknessexp modinlet::momentumthicknessexp proc~inletgen->proc~momentumthicknessexp proc~wallawinlet modinlet::wallawinlet proc~inletgen->proc~wallawinlet proc~writeinletfile modinlet::writeinletfile proc~inletgen->proc~writeinletfile proc~writerestartfiles modsave::writerestartfiles proc~inletgen->proc~writerestartfiles proc~inletgennotemp->proc~readinletfile proc~inletgennotemp->proc~slabsum proc~inletgennotemp->proc~blthicknesst proc~inletgennotemp->proc~dispthicknessexp proc~inletgennotemp->proc~momentumthicknessexp proc~inletgennotemp->proc~wallawinlet proc~inletgennotemp->proc~writeinletfile proc~inletgennotemp->proc~writerestartfiles proc~slabsumi modmpi::slabsumi proc~inlettop->proc~slabsumi proc~iolet->proc~slabsum proc~sumy_ibm->mpi_allreduce proc~slabsumi->mpi_allreduce

Called by

proc~~startup~~CalledByGraph proc~startup modstartup::startup program~dalesurban DALESURBAN program~dalesurban->proc~startup

Contents

Source Code


Source Code

   subroutine startup

      !-----------------------------------------------------------------|
      !                                                                 |
      !     Reads all general options from namoptions                   |
      !                                                                 |
      !      Jasper Tomas                 31/03/2014                    |
      !      Chiel van Heerwaarden        15/06/2007                    |
      !      Thijs Heus                   15/06/2007                    |
      !-----------------------------------------------------------------|

      use modglobal, only:initglobal, iexpnr, runtime, dtmax,  &
         lwarmstart, lstratstart, lfielddump, lreadscal, startfile, tfielddump, fieldvars, tsample, tstatsdump, trestart, &
         nsv, imax, jtot, kmax, xsize, ysize, xlat, xlon, xday, xtime, lwalldist, &
         lmoist, lcoriol, igrw_damp, geodamptime, ifnamopt, fname_options, &
         xS,yS,zS,SS,sigS,iwallmom,iwalltemp,iwallmoist,iwallscal,ipoiss,iadv_mom,iadv_tke,iadv_thl,iadv_qt,iadv_sv,courant,diffnr,ladaptive,author,&
         linoutflow, lper2inout, libm, lnudge, tnudge, nnudge, lles, luoutflowr, lvoutflowr, luvolflowr, lvvolflowr, &
         uflowrate, vflowrate, lstoreplane, iplane, &
         lreadmean, iinletgen, inletav, lreadminl, Uinf, Vinf, linletRA, nblocks, &
         lscalrec,lSIRANEinout,lscasrc,lscasrcl,lscasrcr,lydump,lytdump,lxydump,lxytdump,lslicedump,ltdump,ltkedump,lzerogradtop,&
         lzerogradtopscal, lbuoyancy, ltempeq, &
         lfixinlet, lfixutauin, pi, &
         thlsrc, ifixuinf, lvinf, tscale, ltempinout, lmoistinout,  &
         lwallfunc,lprofforc,lchem,k1,JNO2,rv,rd,tnextEB,tEB,dtEB,bldT,wsoil,wgrmax,wwilt,wfc,skyLW,GRLAI,rsmin,nfcts,lEB,lwriteEBfiles,nwalllayers,lconstW, &
         BCxm,BCxT,BCxq,BCxs,BCym,BCyT,BCyq,BCys, &
         BCtopm,BCtopT,BCtopq,BCtops,BCbotm,BCbotT,BCbotq,BCbots, &
         idriver,tdriverstart,driverjobnr,dtdriver,driverstore,lsdriver
      use modsurfdata, only:z0, z0h,  wtsurf, wttop, wqtop, wqsurf, wsvsurf, wsvtop, wsvsurfdum, wsvtopdum, ps, thvs, thls, thl_top, qt_top, qts 
      ! use modsurface,        only : initsurface
      use modfields, only:initfields, dpdx, ncname
      use modpois, only:initpois
      use modboundary, only:initboundary, ksp
      use modthermodynamics, only:initthermodynamics, lqlnr, chi_half
      use modsubgrid, only:initsubgrid
      use modmpi, only:comm3d, myid, mpi_integer, mpi_logical, my_real, mpierr, mpi_character
      use modinlet, only:initinlet
      use modinletdata, only:di, dr, di_test, dti, iangledeg, iangle
      use modibmdata, only:bctfxm, bctfxp, bctfym, bctfyp, bctfz
      use modforces, only: calcfluidvolumes
      use moddriver, only: initdriver

      implicit none
      integer :: ierr

      !declare namelists

      namelist/RUN/ &
         iexpnr, lwarmstart, lstratstart, startfile, &
         runtime, dtmax, trestart, ladaptive, &
         irandom, randu, randthl, randqt, krand, &
         courant, diffnr, author, &
         libm, lles, &
         lper2inout, lwalldist, &
         lreadmean
      namelist/DOMAIN/ &
         imax, jtot, kmax, xsize, ysize, &
         xlat, xlon, xday, xtime, ksp 
      namelist/PHYSICS/ &
         ps, igrw_damp, lmoist, lcoriol, lbuoyancy, ltempeq, &
         lprofforc, ifixuinf, lvinf, tscale, dpdx, &
         luoutflowr, lvoutflowr, luvolflowr, lvvolflowr, &
         uflowrate, vflowrate, &
         lnudge, tnudge, nnudge
      namelist/DYNAMICS/ &
         lqlnr, ipoiss, &
         iadv_mom, iadv_tke, iadv_thl, iadv_qt, iadv_sv
      namelist/BC/ &
         BCxm, BCxT, BCxq, BCxs, &
         BCym, BCyT, BCyq, BCys, &
         BCtopm, BCtopT, BCtopq, BCtops, &
         BCbotm, BCbotT, BCbotq, BCbots, &
         bctfxm, bctfxp, bctfym, bctfyp, bctfz, &
         wttop, thl_top, qt_top, qts, wsvsurfdum, wsvtopdum, &
         wtsurf, wqsurf, thls, z0, z0h
      namelist/INLET/ &
         Uinf, Vinf, di, dti, inletav, linletRA, &
         lstoreplane, lreadminl, lfixinlet, lfixutauin, &
         lwallfunc
      namelist/DRIVER/ &
         idriver, tdriverstart, driverjobnr, dtdriver, &
         driverstore, iplane, lsdriver
      namelist/WALLS/ &
         nblocks, nfcts, iwallmom, iwalltemp, iwallmoist, iwallscal
      namelist/ENERGYBALANCE/ &
         lEB, lwriteEBfiles, lconstW, dtEB, bldT, wsoil, wgrmax, wwilt, wfc, &
         skyLW, GRLAI, rsmin, nwalllayers
      namelist/SCALARS/ &
         lreadscal, lscasrc, lscasrcl, lscasrcr, &
         nsv, xS, yS, zS, SS, sigS
      namelist/CHEMISTRY/ &
         lchem, k1, JNO2
      namelist/OUTPUT/ &
         lfielddump, tfielddump, fieldvars, &
         ltdump, lydump, lytdump, lxydump, lxytdump, &
         lslicedump, ltkedump, tstatsdump, tsample

      if (myid == 0) then
         if (command_argument_count() >= 1) then
            call get_command_argument(1, fname_options)
         end if
         write (*, *) fname_options

         open (ifnamopt, file=fname_options, status='old', iostat=ierr)
         if (ierr /= 0) then
            write(0, *) 'ERROR: Namoptions does not exist'
            write(0, *) 'iostat error: ', ierr
            stop 1
         end if

         read (ifnamopt, RUN, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions RUN'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, RUN)
         rewind (ifnamopt)

         read (ifnamopt, DOMAIN, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions DOMAIN'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, DOMAIN)
         rewind (ifnamopt)

         read (ifnamopt, PHYSICS, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions PHYSICS'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, PHYSICS)
         rewind (ifnamopt)

         read (ifnamopt, DYNAMICS, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions DYNAMICS'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, DYNAMICS)
         rewind (ifnamopt)

         read (ifnamopt, BC, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions BC'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, BC)
         rewind (ifnamopt)

         read (ifnamopt, INLET, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions INLET'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, INLET)
         rewind (ifnamopt)

         read (ifnamopt, DRIVER, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'Problem in namoptions DRIVER'
            write(0, *) 'iostat error: ', ierr
            stop 'ERROR: Problem in namoptions DRIVER'
         endif
         write (6, DRIVER)
         rewind (ifnamopt)

         read (ifnamopt, WALLS, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions WALLS'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, WALLS)
         rewind (ifnamopt)

         read (ifnamopt, ENERGYBALANCE, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions EB'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, ENERGYBALANCE)
         rewind (ifnamopt)

         read (ifnamopt, SCALARS, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions SCALARS'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, SCALARS)
         rewind (ifnamopt)

         read (ifnamopt, CHEMISTRY, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions CHEMISTRY'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, CHEMISTRY)
         rewind (ifnamopt)

         read (ifnamopt, OUTPUT, iostat=ierr)
         if (ierr > 0) then
            write(0, *) 'ERROR: Problem in namoptions OUTPUT'
            write(0, *) 'iostat error: ', ierr
            stop 1
         endif
         write (6, OUTPUT)
         close (ifnamopt)
      end if

      thvs = thls*(1.+(rv/rd - 1.)*qts)

      write (*, *) "starting broadcast"
      !broadcast namelists
      call MPI_BCAST(iexpnr, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(lwarmstart, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lstratstart, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lfielddump, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lreadscal, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch to read scalar pollutant fields (warm start)
      call MPI_BCAST(lscasrc, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315
      call MPI_BCAST(lscasrcl, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315
      call MPI_BCAST(lscasrcr, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315

      call MPI_BCAST(lbuoyancy, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for buoyancy force in modforces
      call MPI_BCAST(ltempeq, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for solving adv/diff equation for temperature
      call MPI_BCAST(lper2inout, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for restart periodic flow to inoutflow
      call MPI_BCAST(libm, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for turning on/off IBM method
      call MPI_BCAST(lnudge, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(nnudge, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(tnudge, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(lwalldist, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for computing wall distances
      call MPI_BCAST(lles, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for turning on/off LES functionality (subgrid model)
      call MPI_BCAST(linletRA, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for turning on/off Running Average in inletgenerator
      call MPI_BCAST(lfixinlet, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for keeping average inlet velocit and temp fixed at inlet (iinletgen=1,2)
      call MPI_BCAST(lfixutauin, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for keeping utau fixed at inlet (iinletgen=1,2)
      call MPI_BCAST(xS, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(yS, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(zS, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(SS, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(sigS, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(idriver    ,1,MPI_INTEGER,0,comm3d,mpierr)        ! ae1212: Added switch for driver inlet simulation                                                                         
      call MPI_BCAST(tdriverstart,1,MY_REAL   ,0,comm3d,mpierr)        ! ae1212
      call MPI_BCAST(driverjobnr,1,MPI_INTEGER,0,comm3d,mpierr)        ! ae1212
      call MPI_BCAST(dtdriver   ,1,MY_REAL    ,0,comm3d,mpierr)        ! ae1212
      call MPI_BCAST(driverstore,1,MPI_INTEGER ,0,comm3d,mpierr)
      call MPI_BCAST(lsdriver   ,1,MPI_LOGICAL,0,comm3d,mpierr)
      write (*, *) "sec BC"
         call MPI_BCAST(BCxm, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCxT, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCxq, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCxs, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCym, 1, MPI_INTEGER, 0, comm3d, mpierr)                                                                                                                                                                             
         call MPI_BCAST(BCyT, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCyq, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCys, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCtopm, 1, MPI_INTEGER, 0, comm3d, mpierr)                                                         
         call MPI_BCAST(BCtopT, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCtopq, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCtops, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCbotm, 1, MPI_INTEGER, 0, comm3d, mpierr) 
         call MPI_BCAST(BCbotT, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCbotq, 1, MPI_INTEGER, 0, comm3d, mpierr)
         call MPI_BCAST(BCbots, 1, MPI_INTEGER, 0, comm3d, mpierr)

      write (*, *) "sec c"

      call MPI_BCAST(lwallfunc, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for reading mean inlet/recycle plane profiles (Uinl,Urec,Wrec)
      call MPI_BCAST(lreadminl, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for reading mean inlet/recycle plane profiles (Uinl,Urec,Wrec)
      call MPI_BCAST(iwalltemp, 1, MPI_INTEGER, 0, comm3d, mpierr) ! case (integer) for wall treatment for temperature (1=no wall function/fixed flux, 2=no wall function/fixed value, 3=uno)
      call MPI_BCAST(iwallmoist, 1, MPI_INTEGER, 0, comm3d, mpierr) ! case (integer) for wall treatment for moisture (1=no wall function/fixed flux, 2=no wall function/fixed value, 3=uno)
      call MPI_BCAST(iwallscal, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iwallmom, 1, MPI_INTEGER, 0, comm3d, mpierr) ! case (integer) for wall treatment for momentum (1=no wall function, 2=werner-wengle, 3=uno)
      write (*, *) "sec d"
      call MPI_BCAST(luoutflowr, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for turning on/off u-velocity correction for fixed mass outflow rate
      call MPI_BCAST(lvoutflowr, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315: added switch for turning on/off v-velocity correction for fixed mass outflow rate
      call MPI_BCAST(luvolflowr, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! bss166: added switch for turning on/off u-velocity correction for fixed volume flow rate
      call MPI_BCAST(lvvolflowr, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! bss116: added switch for turning on/off v-velocity correction for fixed volume flow rate
      call MPI_BCAST(lstoreplane, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for turning on/off for storing i-plane data to serve as inlet for future sim.
      call MPI_BCAST(lreadmean, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! J.Tomas: added switch for reading mean variables from means#MYID#.#EXPNR#
      call MPI_BCAST(lydump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(lytdump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(lxydump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(lxytdump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(lslicedump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(ltdump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing statistics files
      call MPI_BCAST(ltkedump, 1, MPI_LOGICAL, 0, comm3d, mpierr) ! tg3315 added switch for writing tke budget files
      call MPI_BCAST(iplane, 1, MPI_INTEGER, 0, comm3d, mpierr) ! J.Tomas: ib+iplane is the i-plane that is stored if lstoreplane is .true.
      call MPI_BCAST(startfile, 50, MPI_CHARACTER, 0, comm3d, mpierr)
      call MPI_BCAST(author, 80, MPI_CHARACTER, 0, comm3d, mpierr)
      call MPI_BCAST(runtime, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(trestart, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(tfielddump, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(tsample, 1, MY_REAL, 0, comm3d, mpierr) !tg3315
      call MPI_BCAST(tstatsdump, 1, MY_REAL, 0, comm3d, mpierr) !tg3315

      call MPI_BCAST(tEB, 1, MY_REAL, 0, comm3d, mpierr)
      tnextEB = dtEB
      call MPI_BCAST(tnextEB, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(dtmax, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(nsv, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(fieldvars, 50, MPI_CHARACTER, 0, comm3d, mpierr)
      !call MPI_BCAST(nstat      ,1,MPI_INTEGER,0,comm3d,mpierr) !tg3315
      !call MPI_BCAST(ncstat     ,80,MPI_CHARACTER,0,comm3d,mpierr) !tg3315
      call MPI_BCAST(ifixuinf, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(lvinf, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(dpdx, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(tscale, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(imax, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(jtot, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(kmax, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(xsize, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(ysize, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(xlat, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(xlon, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(xday, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(xtime, 1, MY_REAL, 0, comm3d, mpierr)
      write (*, *) "sec f"

      call MPI_BCAST(z0, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(z0h, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bctfxm, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bctfxp, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bctfym, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bctfyp, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bctfz, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(wtsurf, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wqsurf, 1, MY_REAL, 0, comm3d, mpierr)
      allocate (wsvsurf(1:nsv))
      wsvsurf = wsvsurfdum(1:nsv)
      call MPI_BCAST(wsvsurf(1:nsv), nsv, MY_REAL, 0, comm3d, mpierr)
      allocate (wsvtop(1:nsv))
      wsvtop = wsvtopdum(1:nsv)                                                                   
      call MPI_BCAST(wsvtop(1:nsv), nsv, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(ps, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(thvs, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(thls, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(thl_top, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(qt_top, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(qts, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(lmoist, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lcoriol, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lprofforc, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lchem, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(k1, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(JNO2, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(igrw_damp, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(geodamptime, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wttop, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wqtop, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(thlsrc, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(uflowrate, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(vflowrate, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(Uinf, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(Vinf, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(di, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(dti, 1, MY_REAL, 0, comm3d, mpierr)
      dr = di ! initial value is needed
      di_test = di ! initial value is needed
      write (*, *) "sec g"
      call MPI_BCAST(iangledeg, 1, MY_REAL, 0, comm3d, mpierr)
      iangle = iangledeg*pi/180.
      call MPI_BCAST(inletav, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(lqlnr, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(ksp, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(nblocks, 1, MPI_INTEGER, 0, comm3d, mpierr) ! no. of blocks used in IBM

      call MPI_BCAST(nfcts, 1, MPI_INTEGER, 0, comm3d, mpierr)

      call MPI_BCAST(lconstW, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lEB, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(lwriteEBfiles, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(wsoil, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wgrmax, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wwilt, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(wfc, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(dtEB, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(bldT, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(skyLW, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(GRLAI, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(rsmin, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(nwalllayers, 1, MPI_INTEGER, 0, comm3d, mpierr)

      call MPI_BCAST(irandom, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(krand, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(randthl, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(randu, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(randqt, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(ladaptive, 1, MPI_LOGICAL, 0, comm3d, mpierr)
      call MPI_BCAST(courant, 1, MY_REAL, 0, comm3d, mpierr)
      call MPI_BCAST(diffnr, 1, MY_REAL, 0, comm3d, mpierr)

      call MPI_BCAST(ipoiss, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iadv_mom, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iadv_tke, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iadv_thl, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iadv_qt, 1, MPI_INTEGER, 0, comm3d, mpierr)
      call MPI_BCAST(iadv_sv(1:nsv), nsv, MPI_INTEGER, 0, comm3d, mpierr)
      !write(*,*) "sec h"

      ! Allocate and initialize core modules
      call initglobal
      write (*, *) "done initglobal"
      call initfields
      write (*, *) "done initfields"
      call initboundary
      write (*, *) "done initboundayi"
      call initthermodynamics
      write (*, *) "done initthermodynamics"
      !!depreated!!
      ! call initsurface
      write (*, *) "done initsurface"
      call initsubgrid
      write (*, *) "done initsubgrid"
      call initpois
      write (*, *) "done initpois"
      call initinlet ! added by J. Tomas: initialize inlet generator
      write (*, *) "done initinlet"
      call initdriver  ! added by ae1212: initialise driver inlet                             
      write(*,*) "done initdriver"
      call checkinitvalues
      write (*, *) "done checkinitvalues"
      write (6, *) 'Determine masking matrices'
      call createmasks ! determine walls/blocks
      write (6, *) 'Finished determining masking matrices'
      ! calculate fluid volume and outlet areas, needs masking matrices
      call calcfluidvolumes

      call readinitfiles
      write (*, *) "done readinitfiles"
      write (*, *) "done startup"

      call createscals
      write (*, *) "done create scals"

   end subroutine startup