Fortran Coder

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

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

[复制链接]

2

帖子

1

主题

0

精华

新人

F 币
15 元
贡献
7 点
跳转到指定楼层
楼主
发表于 2014-12-7 20:49:53 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
[Fortran] 纯文本查看 复制代码
01module data_fixed  !save common data using module
02     integer,parameter :: row=32             
03     integer,parameter ::n=row**3
04     integer,parameter :: fileid=10             !   unit=fileid 
05     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
06     character(len=800) ::filenameP="C:\Users\Administrator\Desktop\blend 413K\F0.6 DPD Dynamics (2)\F0.6.00020000.P.Dpd_den"
07     character(len=800) ::filenameT="C:\Users\Administrator\Desktop\blend 413K\F0.6 DPD Dynamics (2)\F0.6.00020000.T.Dpd_den"
08 end module
09 
10 Program Test             !read file from external file
11     use data_fixed       ! call the data module
12     implicit none
13 
14     real :: array_F(n),array_P(n),array_T(n)
15 
16     call readfile(filenameF,array_F)   !call the subroutine
17     call readfile(filenameP,array_P)
18     call readfile(filenameT,array_T)
19     write(*,*) array_F(1:10),array_P(1:10),array_T(1:10)
20 
21 end program
22 
23 subroutine readfile(a,b) 
24     use data_fixed        !call the data module
25     implicit none
26 
27     character(len=80) :: tempstr
28     character(len=800) ::a
29     real :: b(n)
30 
31     integer :: counter=0
32 
33     open( unit=fileid , file=a ,access='sequential',status='old',recl=6)
34     do while (counter < n )   ! pass the first line data
35         counter=counter+1 
36         if ( counter ==1 ) then
37             read(fileid,"(A80)") tempstr
38         end if     
39         read(fileid,*) b(counter)
40     end do
41     close(fileid)
42 end subroutine
为什么array_F调用成功,而array_P和array_T调用出错啊?

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

2038

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1676 元
贡献
715 点

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

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

如果你要跳过第一行,按照沙发代码那样写不是更好吗?

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

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

838

帖子

2

主题

0

精华

大宗师

F 币
3937 元
贡献
2339 点
沙发
发表于 2014-12-7 20:59:27 | 只看该作者
[Fortran] 纯文本查看 复制代码
1open( unit=fileid , file=trim(a) ,status='old')
2 read(fileid,*)
3 do i=1,n
4 read(fileid,*) b(i)   
5 end do
6 close(fileid)
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2025-5-2 15:55

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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