Fortran Coder

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

[子程序] 子程序调用的问题

[复制链接]

2

帖子

1

主题

0

精华

新人

F 币
15 元
贡献
7 点
跳转到指定楼层
楼主
发表于 2014-12-7 20:49:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[Fortran] 纯文本查看 复制代码
module data_fixed  !save common data using module 
     integer,parameter :: row=32              
     integer,parameter ::n=row**3
     integer,parameter :: fileid=10             !   unit=fileid  
     character(len=800) ::filenameF="C:\Users\Administrator\Desktop\blend 413K\F0.6 DPD Dynamics (2)\F0.6.00020000.F.Dpd_den"  !the site of the file that you want to load
     character(len=800) ::filenameP="C:\Users\Administrator\Desktop\blend 413K\F0.6 DPD Dynamics (2)\F0.6.00020000.P.Dpd_den"
     character(len=800) ::filenameT="C:\Users\Administrator\Desktop\blend 413K\F0.6 DPD Dynamics (2)\F0.6.00020000.T.Dpd_den"
 end module

 Program Test             !read file from external file
     use data_fixed       ! call the data module
     implicit none

     real :: array_F(n),array_P(n),array_T(n)

     call readfile(filenameF,array_F)   !call the subroutine
     call readfile(filenameP,array_P)
     call readfile(filenameT,array_T)
     write(*,*) array_F(1:10),array_P(1:10),array_T(1:10)

 end program

 subroutine readfile(a,b)  
     use data_fixed        !call the data module
     implicit none

     character(len=80) :: tempstr
     character(len=800) ::a
     real :: b(n)

     integer :: counter=0

     open( unit=fileid , file=a ,access='sequential',status='old',recl=6)
     do while (counter < n )   ! pass the first line data
         counter=counter+1  
         if ( counter ==1 ) then
             read(fileid,"(A80)") tempstr
         end if      
         read(fileid,*) b(counter)
     end do
     close(fileid)
 end subroutine
为什么array_F调用成功,而array_P和array_T调用出错啊?

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

799

帖子

2

主题

0

精华

大宗师

F 币
3797 元
贡献
2270 点
沙发
发表于 2014-12-7 20:59:27 | 只看该作者
[Fortran] 纯文本查看 复制代码
open( unit=fileid , file=trim(a) ,status='old')
 read(fileid,*) 
 do i=1,n
 read(fileid,*) b(i)    
 end do
 close(fileid)

2

帖子

1

主题

0

精华

新人

F 币
15 元
贡献
7 点
板凳
 楼主| 发表于 2014-12-7 21:02:11 | 只看该作者
li913 发表于 2014-12-7 20:59
open( unit=fileid , file=trim(a) ,status='old')
read(fileid,*)
do i=1,n

我是从第二行开始读取数据的?所以要跳过第一行!

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

地板
发表于 2014-12-7 21:56:40 | 只看该作者
你运行后遇到了什么错误?请告知错误信息。

如果你要跳过第一行,按照沙发代码那样写不是更好吗?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-10 22:13

Powered by Tencent X3.4

© 2013-2024 Tencent

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