Fortran Coder

查看: 6444|回复: 3
打印 上一主题 下一主题

[输入输出] 默认i/o号以及派生类型非默认i/o定义的问题

[复制链接]

798

帖子

2

主题

0

精华

大宗师

F 币
3793 元
贡献
2268 点
楼主
发表于 2018-12-29 12:50:49 | 显示全部楼层
1、
[Fortran] 纯文本查看 复制代码
program test
  use iso_fortran_env
  implicit none
  print*,input_unit,output_unit !输入输出通道号,ivf输出 5  6
end 

2、《Fortran95/2003程序设计》chapman,第14.8节。

评分

参与人数 1贡献 +5 收起 理由
fcode + 5

查看全部评分

798

帖子

2

主题

0

精华

大宗师

F 币
3793 元
贡献
2268 点
沙发
发表于 2018-12-29 14:21:27 | 显示全部楼层
iotype 里面保存了自定义格式,f2008标准中建议 v_list 为输出域宽,其实没多大用。
[Fortran] 纯文本查看 复制代码
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, 下载次数: 223)

图片1.png
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-6 01:57

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表