| iotype 里面保存了自定义格式,f2008标准中建议 v_list 为输出域宽,其实没多大用。 
 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode module fmt_m
  implicit none
  type UDT
    real x, y
    integer ind
  contains
    procedure::write_UDT
    generic :: write(formatted) => write_UDT
  end type
contains
  subroutine write_UDT(dtv,unit,iotype,v_list,iostat,iomsg)
  implicit none
  class(UDT), intent(in):: dtv
  integer,intent(in):: unit
  character(*),intent(in)::iotype
  integer,intent(in)::v_list(:)
  integer,intent(out)::iostat
  character(*),intent(inout)::iomsg
  select case(iotype(1:2))
    case('LI') !listdirected
      write(unit,*) dtv%x, dtv%y, dtv%ind
    case('DT') 
      write(unit,fmt='('//iotype(3:)//')') dtv%x, dtv%y, dtv%ind
    case('NA') !namelist
      !自己写代码
    end select
  end subroutine
end module
  
program test
  use iso_fortran_env
  use fmt_m
  implicit none
  type(UDT)::t=udt(1.2,3.1,3)
  print*,input_unit,output_unit !屏幕输入输出通道号,ivf为 5  6
  write(output_unit,'( dt"f4.1,f8.1,i5" )') t
  write(output_unit,*) t
  pause
end program
   |