缺少子程序的显式接口

时间:2013-06-02 09:12:48

标签: fortran

我只想读一个带有可变线的两列文本文件到一个数组中。 文本文件的第一列是以秒为单位的时间,第二列是温度。就像这样:

    1.1 10
    2.1 20
    3.2 30
    4.2 40
    5.3 50
    6.3 60
    7.4 70

以下是我写的代码:

module myData
    type line_info
        real :: time
        real :: temp
    end type

    type datalink
        type(line_info) :: time_temp
        type(datalink), pointer :: next
    end type

    type(line_info), allocatable :: FileInfoArr(:)
end module

program Console1
    use myData
    implicit none

    ! Variables
    type(line_info),allocatable :: time_temp_arr(:)
    !real,allocatable :: File2Arr(:)
    character (len=80) :: FileFullName="C:\t.txt"       
    call File2Arr(FileFullName,time_temp_arr)   



End Program Console1

Subroutine File2Arr(FileFullName,InfoArray)
    use myData
    character (len=80) :: FileFullName
    type(line_info),allocatable :: InfoArray(:)
    type(datalink), pointer :: head
    type(datalink), pointer :: p
    integer error,size,i


    logical alive  
    ! check if file exists
    inquire(file=FileFullName, exist=alive)
    if(alive==0) then
        write(*,*) FileFullName, "doesn't exist."
        stop
    end if

    ! read file using pointer   
    open(10, file=FileFullName, status="old", iostat=error)
    if(error/=0) then
        write(*,*) "open file fail!"
        stop
    end if

    allocate(head)
    nullify(head%next)
    p=>head
    size=0
    !read(10,"(A80)") tempstr
    do while(.true.)
        read(10, fmt=*, iostat=error) p%time_temp
        if(error/=0) exit
        size=size+1
        allocate(p%next, stat=error) ! add next line
        if(error/=0) then
            write(*,*) "Out of memory!"
            stop
        end if      
        p=>p%next
        nullify(p%next)
    end do
    !save link info into an array
    allocate(InfoArray(size))
    p=>head
    i=0
    do while(associated(p%next))
      i=i+1
      InfoArray(i)=p%time_temp
      p=>p%next 
      !write(*,*) FileInfoArr(i)%time, FileInfoArr(i)%temp
    end do 

End Subroutine

当我编译它时,我得到了这个:

  

错误#8055:该过程有一个伪参数,该参数具有ALLOCATABLE,ASYNCHRONOUS,OPTIONAL,POINTER,TARGET,VALUE或VOLATILE属性。原始源中缺少必需的显式接口。 [TIME_TEMP_ARR]

有关如何解决此错误的任何想法,感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

将子程序File2Arr放入模块MyData内(并删除该子程序中的use mydata行)。它汇编了&我这样做了。

答案 1 :(得分:1)

除了将子例程File2Arr添加到您的模块MyData之外,您还可以使用CONTAINS关键字将其直接放入您的程序中(此处您也可以删除{{1}子程序中的行。)