Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

fortran - Missing explicit interface for subroutine

I just want to read a two-column text file with variable lines into an array. The first column of the text file is time in the unit of second, and the second is temperature. Just like this:

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

Following is the code I write:

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:.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

When I compile it, I got this :

error #8055: The procedure has a dummy argument that has the ALLOCATABLE, ASYNCHRONOUS, OPTIONAL, POINTER, TARGET, VALUE or VOLATILE attribute. Required explicit interface is missing from original source. [TIME_TEMP_ARR]

Any idea on how to fix this error, thanks for any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Put your subroutine File2Arr inside the module MyData (and remove the use mydata line inside that subroutine). It compiled & ran for me doing that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...