program test
use iso_fortran_env
implicit none
print*,input_unit,output_unit !输入输出通道号,ivf输出 5 6
end
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
图片1.png (55.87 KB, 下载次数: 261)
li913 发表于 2018-12-29 14:21
iotype 里面保存了自定义格式,f2008标准中建议 v_list 为输出域宽,其实没多大用。
[mw_shl_code=fortran, ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |