[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调用出错啊?[Fortran] 纯文本查看 复制代码
open( unit=fileid , file=trim(a) ,status='old')
read(fileid,*)
do i=1,n
read(fileid,*) b(i)
end do
close(fileid)