0
파생 된 데이터 형식의 필드로 서브 루틴의 입력을 어떻게 전달합니까?포트란 형식의 필드를 서브 루틴의 입력으로
나는 골짜기를 반복 할 연결 목록이 있는데 특정 필드에서만 작업하고 싶지만 다른 필드에서 같은 기능을 호출 할 수 있도록 "이름"필드를 입력으로하고 싶습니다. 목록의. 예를 들어
: 그것은 동일한 이름과 정의를 가지고 있지만 두 곳에서 유형을 정의하면 포트란 표준에 따르면
program main
implicit none
! ----- variables declaration
type :: element
real :: u1
real :: u2
type (element), pointer :: next => null()
end type element
type (element), pointer :: first, last, iele
! ----- code
allocate(first)
last => first
first %u1 = 0
first %u2 = 0
allocate(first %next)
last => first %next
last %u1 = 10
last %u2 = 20
call addten(u1, first)
call addten(u2, first)
iele => first
do while (associated(iele))
write(*,*) iele %u1
iele => iele %next
end do
end program main
! =====
subroutine addten(u, first)
implicit none
! ----- variables declaration
type :: element
real :: u1
real :: u2
type (element), pointer :: next => null()
end type element
real, pointer :: u
type (element), pointer :: iele
! ----- code
iele => first
do while (associated(iele))
iele %u = iele %u + 10
iele => iele %next
end do
end subroutine addten
좋은 지적 그것은 직접 정보를 전달 할 수 없습니다, 당신은 당신의 서브 루틴이 스위치로 이해하고 일부 보조 변수를 전달해야 그는 모듈에 관해서, 내 것이 엉성한 예제였습니다. 큰 코드 덩어리를 본질적으로 복제하고 싶지 않기 때문에 스위치 나 선택을 피하고 싶었습니다. +10 연산은 한 줄이지만 실제 코드는 여러 줄입니다. –
@GiacomoCastiglioni 내가 아는 다른 가능성은 없습니다. –