subroutine trxpl_gs2_oname(zfile)

  ! generate default output filename for GS2 namelist

  use trxpl_gs2_module
  implicit NONE
  character*(*), intent(out) :: zfile

  !--------------------------------------------
  integer ilpre,ilsuf
  character*50 ztmp1,ztmp2,ztmp3
  integer il1,il2,il3
  !--------------------------------------------

  ilpre=len_trim(ofile_prefix)
  ilsuf=len_trim(ofile_suffix)

  call xpand(ztmp1,'t',transp_time,il1)
  call xpand(ztmp2,'dt',transp_delt,il2)
  call xpand(ztmp3,'x',transp_x,il3)

  zfile(1:)=ofile_prefix(1:ilpre)// &
       '_'//ztmp1(1:il1)// &
       '_'//ztmp2(1:il2)// &
       '_'//ztmp3(1:il3)// &
       '_'//ofile_suffix(1:ilsuf)

contains
  subroutine xpand(ztmp,zss,zval,ilen)

    !  generate a filename piece   nnnXnnn

    character*(*), intent(out) :: ztmp   ! filename piece
    character*(*), intent(in) :: zss     ! substring replacing "." point
    real*8, intent(in) :: zval           ! value to encode
    integer, intent(out) :: ilen         ! length of assembled piece at end

    !---------> local:
    character*10 ibuf
    character*3 irem
    integer ilss,ii,jj,kk
    integer intval,irem000
    real*8 znum,zuse
    !---------------------------------

    ilss=len_trim(zss)

    zuse = zval + 0.5d-3  ! for rounding

    if(zuse.ge.1.0d9) then
       ztmp='999999999'//zss(1:ilss)//'999'
    else if(zuse.lt.1.0d-3) then
       ztmp='0'//zss(1:ilss)//'000'
    else

       intval = zuse             ! integer part (seconds)
       write(ibuf,'(I10)') intval
       do ii=1,10
          if(ibuf(ii:ii).ne.' ') then
             jj=ii
             exit
          endif
       enddo

       znum = 1.0d3*(zuse - intval)
       intval = znum             ! fractional part (milliseconds)
       intval = max(0,min(999,intval))
       write(irem,'(I3.3)') intval

       ztmp = ibuf(jj:10)//zss(1:ilss)//irem

    endif

    ilen=len_trim(ztmp)

  end subroutine xpand

end subroutine trxpl_gs2_oname
