2013-07-14 48 views
1

输入子程序时出现分段错误。 在调试器中,我可以执行下列代码段中的第一个call RK_sub_step。 一旦进入子程序,就会发生段错误。进入Fortran子程序时出现Segfault错误

module RK_mod 

type(MyType), dimension(1:2) :: q0, q1, q2 

contains 

subroutine RK_sub_step(src, alpha, dest) 
    real(8), dimension(:) :: alpha 
    type(MyType), dimension(1:2,size(alpha)) :: src 
    type(MyType), dimension(1:2), intent(inout) :: dest 

    ! compute dest from alpha and src 
end subroutine 

subroutine RK() 
    real(8) alpha(3) 
    call RK_sub_step((/q0/), (/alpha(1)/), q1) ! <- Segfault here 
    call RK_sub_step((/q0, q1/), alpha(2:3), q2) 
end subroutine 

end module 

任何想法我可能做错了什么?

编辑:

现在我设法绕过通过创建独立的子程序的段错误,我可以打电话为

call RK_sub_step1(q0, alpha(1), q1) 
call RK_sub_step2(q0, q1, alpha(2:3), q2) 
call RK_sub_step4(q0, q1, q2, q3, alpha(4:8), q0) 

但我仍然不知道,如果有可能只有一个像上面进一步子程序,或者为什么这是不可能的。

回答

1

我认为问题是,这

(/q0/) 

构建的myType秩1阵列,其中使段错误行,被传递到一个子程序,其需要一个秩2阵列的作为第一个参数myType。如果q0是rank-1数组,则构造rank-2数组。

0

你也许可以做两件事情,以满足您的单一子程序的愿望:

  • 定义type(mytype), dimension(:,:), allocatable :: qtemp,然后将其分配到合适的尺寸(比如2,2),然后使用循环

    设置
    do i=1,2 
        qtemp(i,:) = (/q0(i), q1(i)/) 
    enddo 
    
  • 写出不同数量的输入变量的不同的子程序,然后使用interface块 - see herehere对那些帮助。