writedriverfile Subroutine

public subroutine writedriverfile()

Uses

  • proc~~writedriverfile~~UsesGraph proc~writedriverfile writedriverfile module~modfields modfields proc~writedriverfile->module~modfields module~modglobal modglobal proc~writedriverfile->module~modglobal module~modinletdata modinletdata proc~writedriverfile->module~modinletdata module~modmpi modmpi proc~writedriverfile->module~modmpi decomp_2d decomp_2d module~modfields->decomp_2d mpi mpi module~modmpi->mpi

Arguments

None

Called by

proc~~writedriverfile~~CalledByGraph proc~writedriverfile writedriverfile proc~drivergen drivergen proc~drivergen->proc~writedriverfile proc~boundary boundary proc~boundary->proc~drivergen proc~readinitfiles readinitfiles proc~readinitfiles->proc~drivergen program~dalesurban DALESURBAN program~dalesurban->proc~boundary program~dalesurban->proc~readinitfiles

Source Code

  subroutine writedriverfile
    use modglobal, only : runtime,timee,tdriverstart,tdriverstart_cold,ib,ie,ih,jb,je,jh,kb,ke,kh,cexpnr,ifoutput,nstore,ltempeq,lmoist,driverstore,dtdriver,nsv,lhdriver,lqdriver,lsdriver,ibrank,iplanerank,driverid,cdriverid,btime,lwarmstart
    use modfields, only : u0, v0, w0, e120, thl0, qt0, um, sv0
    use modmpi,    only : cmyid,myid
    use modinletdata, only : storetdriver,storeu0driver,storev0driver,storew0driver,storethl0driver,storeqt0driver,&
                             storesv0driver,nfile,nstepreaddriver
    implicit none
    integer :: fileid, IOS
    integer :: i,j,k,n
    integer :: filesizet, filesizev, filesizetest1, filesizetest2, filesizes
    character(15) :: name
    logical :: lexist
    real, allocatable :: arraysizetest(:,:)

    allocate(arraysizetest(jb-jh:je+jh,kb-kh:ke+kh))

    inquire(iolength=filesizet)(timee-tdriverstart)
    ! inquire(iolength=filesizetest1)(timee)
    ! inquire(iolength=filesizetest2)u0(1,1,1)
    inquire(iolength=filesizev)u0(irecydriver,:,:)
    inquire(iolength=filesizes)sv0(irecydriver,:,:,:)
    !!
    ! if((myid==0) .and. (nstepreaddriver==1)) then
      ! write(6,*) 'inquire iolength ', filesizet
      ! write(6,*) 'inquire iolength test', filesizetest1
      ! write(6,*) 'inquire iolength test u', filesizetest2
    ! end if

    ! inquire(iolength=filesizetest1)arraysizetest(:,:)
    ! filesizetest2 = (je-jb+2*jh)*(ke-kb+2*kh)

    ! if((myid==0) .and. (nstepreaddriver==1)) then
      ! write(6,*) 'je,jb,jh,ke,kb,kh', je,jb,jh,ke,kb,kh
      ! write(6,*) 'inquire iolength test 1 ', filesizetest1
      ! write(6,*) 'inquire iolength test 2', filesizetest2
      ! write(6,*) 'inquire iolength', filesizev
    ! end if

    if(driverid==0) then
      write(6,*) '============ Writing driver files ============'
      write(*,*) 'Driver timestep: ', nstepreaddriver
    end if

    if(driverid==0) then
      name = 'tdriver_   .'
      name(9:11)= cdriverid
      name(13:15)= cexpnr
      ! name(15:18)= '.txt'
      inquire(file=name,exist=lexist)
      if (lexist) then
      ! write(6,*) 'Writing Time stamp to file: ', name
        open  (unit=11,file=name,form='unformatted',status='old',access='direct',recl=filesizet,action='write')
      else
        ! write(6,*) 'Creating Time stamp driver file: ', name
        open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizet,action='write',IOSTAT=IOS)
        ! if (IOS > 0) then
          ! write(6,*) 'IOS = ',IOS
        ! endif
      end if

      ! write(*,*) 'filesizet', filesizet
      ! write(ifoutput)  ( storetdriver (n),  n=1,nstore)
      ! write(6,'(A,F9.2)') 'Writing time stamp to file: ', timee-tdriverstart

      if (.not.(lwarmstart)) then
        write(11,rec=nstepreaddriver)  ( timee-tdriverstart)
        write(*,*) 'Driver time:' , timee-tdriverstart
      else ! if lwarmstart
        if (btime<tdriverstart) then
          write(11,rec=nstepreaddriver)  ( timee-tdriverstart)
          write(*,*) 'Driver time:' , timee-tdriverstart
        else
          write(11,rec=nstepreaddriver)  ( timee-tdriverstart_cold)
          write(*,*) 'Driver time:' , timee-tdriverstart_cold
        end if
      end if

      close (unit=11)
    end if

    name = 'udriver_   .'
    ! write (name(13:16)  ,'(i4.4)') nfile
    name(9:11)= cdriverid
    name(13:15)= cexpnr
    ! name(15:18)= '.txt'
    inquire(file=name,exist=lexist)
    if (lexist) then
      ! write(6,*) 'Writing Inlet u-velocity to file: ', name
      open  (unit=11,file=name,form='unformatted',status='old',access='direct',recl=filesizev,action='write')
    else
      ! write(6,*) 'Creating Inlet u-velocity inlet file: ', name
      open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
    end if

    ! write(ifoutput)  (((storeu0driver (j,k,n),j=jb,je),k=kb,ke),  n=1,nstore) ! Nested implied do-loop
    !if(myid==0) then
      !write(6,'(A,e20.12)') 'Writing u0 to file. u0(irecydriver,je,ke)', u0(irecydriver,je,ke)
      !write(6,'(A,e20.12)') 'u0(irecydriver,jb,kb)', u0(irecydriver,jb,kb)
      !write(6,'(A,e20.12)') 'Writing thl0 to file. thl0(irecydriver-1,je,ke)', thl0(irecydriver-1,je,ke)
      !write(6,'(A,e20.12)') 'thl0(irecydriver-1,jb,kb)', thl0(irecydriver-1,jb,kb)
      ! write(6,*) 'irecydriver, je, ke, ib, jb, kb', irecydriver, je, ke, ib, jb, kb
    !end if
    write(11,rec=nstepreaddriver)  (u0(irecydriver,:,:))
    close (unit=11)

    name = 'vdriver_   .'
    ! write (name(13:16)  ,'(i4.4)') nfile
    name(9:11)= cdriverid
    name(13:15)= cexpnr
    ! name(15:18)= '.txt'
    inquire(file=name,exist=lexist)
    if (lexist) then
      ! write(6,*) 'Writing Inlet v-velocity to file: ', name
      open  (unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizev)
    else
      ! write(6,*) 'Creating v-velocity inlet file: ', name
      open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
    end if
    ! write(ifoutput)  (((storev0driver (j,k,n),j=jb,je),k=kb,ke),  n=1,nstore)
    ! '(F8.4)'
    write(11,rec=nstepreaddriver)  (v0(irecydriver-1,:,:)) !tg3315 removed irecydriver-1
    close (unit=11)

    name = 'wdriver_   .'
    ! write (name(13:16)  ,'(i4.4)') nfile
    name(9:11)= cdriverid
    name(13:15)= cexpnr
    ! name(15:18)= '.txt'
    inquire(file=name,exist=lexist)
    if (lexist) then
      ! write(6,*) 'Writing Inlet w-velocity to file: ', name
      open  (unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizev)
    else
      ! write(6,*) 'Creating w-velocity inlet file: ', name
      open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
    end if
    ! write(ifoutput)  (((storew0driver (j,k,n),j=jb,je),k=kb,ke+1),n=1,nstore)
    write(11,rec=nstepreaddriver)  (w0(irecydriver-1,:,:)) !tg3315 removed irecydriver-1
    close (unit=11)

    ! name = 'edriver_   .'
    ! write (name(13:16)  ,'(i4.4)') nfile
    ! name(9:11)= cmyid
    ! name(13:15)= cexpnr
    ! name(15:18)= '.txt'
    ! inquire(file=name,exist=lexist)
    ! if (lexist) then
      ! write(6,*) 'Writing Inlet w-velocity to file: ', name
      ! open(unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizev)
    ! else
      ! write(6,*) 'Creating w-velocity inlet file: ', name
      ! open(unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
    ! end if
    ! write(ifoutput)  (((storew0driver (j,k,n),j=jb,je),k=kb,ke+1),n=1,nstore)
    ! write(11,rec=nstepreaddriver)  (e120(irecydriver,:,:)) !tg3315 removed irecydriver-1
    ! close (unit=11)

    if (ltempeq) then
      name = 'hdriver_   .'
      ! write (name(13:16)  ,'(i4.4)') nfile
      name(9:11)= cdriverid
      name(13:15)= cexpnr
      ! name(15:18)= '.txt'
      inquire(file=name,exist=lexist)
      if (lexist) then
        ! write(6,*) 'Writing Inlet temperature to file: ', name
        open  (unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizev)
      else
        ! write(6,*) 'Creating temperature inlet file: ', name
        ! write(6,*) 'Creating w-velocity inlet file: ', name
        open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
      end if
      ! write(ifoutput)  (((storew0driver (j,k,n),j=jb,je),k=kb,ke+1),n=1,nstore)
      write(11,rec=nstepreaddriver)  (thl0(irecydriver-1,:,:)) !tg3315 removed irecydriver-1
      close (unit=11)
    end if

    if (lmoist ) then
      name = 'qdriver_   .'
      ! write (name(13:16)  ,'(i4.4)') nfile
      name(9:11)= cdriverid
      name(13:15)= cexpnr
      ! name(15:18)= '.txt'
      inquire(file=name,exist=lexist)
      if (lexist) then
        ! write(6,*) 'Writing Inlet temperature to file: ', name
        open  (unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizev)
      else
        ! write(6,*) 'Creating temperature inlet file: ', name
        ! write(6,*) 'Creating w-velocity inlet file: ', name
        open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizev,action='write')
      end if
      ! write(ifoutput)  (((storew0driver (j,k,n),j=jb,je),k=kb,ke+1),n=1,nstore)
      write(11,rec=nstepreaddriver)  (qt0(irecydriver-1,:,:)) !tg3315 removed irecydriver-1
      close (unit=11)
    end if

    if (nsv>0 ) then
      name = 'sdriver_   .'
      ! write (name(13:16)  ,'(i4.4)') nfile
      name(9:11)= cdriverid
      name(13:15)= cexpnr
      ! name(15:18)= '.txt'
      inquire(file=name,exist=lexist)
      if (lexist) then
        ! write(6,*) 'Writing Inlet temperature to file: ', name
        open  (unit=11,file=name,form='unformatted',status='old',action='write',access='direct',recl=filesizes)
      else
        ! write(6,*) 'Creating temperature inlet file: ', name
        ! write(6,*) 'Creating w-velocity inlet file: ', name
        open  (unit=11,file=name,form='unformatted',status='replace',access='direct',recl=filesizes,action='write')
      end if
      ! write(ifoutput)  (((storew0driver (j,k,n),j=jb,je),k=kb,ke+1),n=1,nstore)
      write(11,rec=nstepreaddriver)  (sv0(irecydriver-1,:,:,:)) !tg3315 removed irecydriver-1
      close (unit=11)
    end if

    if (.not.(lwarmstart)) then
      if (driverid==0 .and. runtime+1e-10 < (tdriverstart + (driverstore-1)*dtdriver)) then
        write(*,*) 'Warning! Driver files cannot be written upto ', driverstore, ' steps. &
                    &Consider taking runtime >= (tdriverstart + (driverstore-1)*dtdriver).'
      end if
    else ! if lwarmstart
      if (btime<tdriverstart) then
        if(driverid==0 .and. (btime + runtime) < (tdriverstart + (driverstore-1)*dtdriver) ) then
          write(*,*) 'Warning! Driver files cannot be written upto ', driverstore, ' steps. &
                      &Consider taking runtime + ',btime,' >= (tdriverstart + (driverstore-1)*dtdriver).'
        end if
      else
        if (driverid==0 .and. runtime+1e-10 < (driverstore-1)*dtdriver ) then
          write(*,*) 'Warning! Driver files cannot be written upto ', driverstore, ' steps. &
                      &Consider taking runtime >= (driverstore-1)*dtdriver).'
        end if
      end if
    end if

  end subroutine writedriverfile