ji460600985 发表于 2014-12-7 20:49:53

子程序调用的问题

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调用出错啊?

li913 发表于 2014-12-7 20:59:27

open( unit=fileid , file=trim(a) ,status='old')
read(fileid,*)
do i=1,n
read(fileid,*) b(i)   
end do
close(fileid)

ji460600985 发表于 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


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

fcode 发表于 2014-12-7 21:56:40

你运行后遇到了什么错误?请告知错误信息。

如果你要跳过第一行,按照沙发代码那样写不是更好吗?
页: [1]
查看完整版本: 子程序调用的问题