缺少子程序的显式接口 [英] Missing explicit interface for subroutine

查看:20
本文介绍了缺少子程序的显式接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将带有可变行的两列文本文件读入数组.文本文件的第一列是以秒为单位的时间,第二列是温度.就像这样:

 1.1 102.1 203.2 304.2 405.3 506.3 607.4 70

以下是我写的代码:

<上一页>模块 myData输入 line_info即时的真实的::温度端型类型数据链路类型(line_info)::time_temp类型(数据链路),指针::下一个端型类型(line_info),可分配 :: FileInfoArr(:)端模块程序控制台1使用我的数据隐式无!变量类型(line_info),可分配 :: time_temp_arr(:)!real,allocatable :: File2Arr(:)字符 (len=80) :: FileFullName="C: .txt"调用 File2Arr(FileFullName,time_temp_arr)结束程序控制台1子程序 File2Arr(FileFullName,InfoArray)使用我的数据字符 (len=80) :: FileFullName类型(line_info),可分配的 :: InfoArray(:)类型(数据链路),指针 :: 头类型(数据链路),指针 :: p整数误差,大小,我逻辑活着!检查文件是否存在查询(文件=文件全名,存在=活着)如果(活着==0)那么write(*,*) FileFullName, "不存在."停止万一!使用指针读取文件打开(10,文件=文件全名,状态=旧",iostat=错误)如果(错误/=0)那么write(*,*) "打开文件失败!"停止万一分配(头)无效(头%下一个)p=>头大小=0!read(10,"(A80)") tempstr做while(.true.)读取(10,fmt=*,iostat=error)p%time_temp如果(错误/=0)退出尺寸=尺寸+1分配(p%next,stat=error)!添加下一行如果(错误/=0)那么写(*,*)内存不足!"停止万一p=>p%下一个无效(p%next)结束做!将链接信息保存到数组中分配(信息数组(大小))p=>头我=0做while(关联(p%next))我=我+1InfoArray(i)=p%time_tempp=>p%下一个!write(*,*) FileInfoArr(i)%time, FileInfoArr(i)%temp结束做结束子程序

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

<块引用>

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

关于如何修复此错误的任何想法,感谢您的帮助.

解决方案

把你的子程序 File2Arr 放到模块 MyData 里面(并去掉 use mydata行).它编译了 &为我跑.

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.

解决方案

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

这篇关于缺少子程序的显式接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆