2016-08-06 2 views
2

ifort 컴파일러 버전 15를 사용하여 Fortran에서 사용자 정의 파생 유형 입력 결과를 수행하기위한 최소한의 예제를 작성하려고합니다. 아래에 게시 된 코드는 그에 따라 읽고 쓸 수 있습니다 그러나 이후에 실행 완료 "읽기"및 제어 메인 프로그램으로 리턴하는 동안 다음과 같은 오류가 발생합니다UDDTIO 읽기 : 해제 된 포인터가 할당되지 않았습니다.

module mod_test 

    implicit none 

    type, public :: class_test 
     integer :: foo 
    contains 
     procedure, private :: write_test 
     procedure, private :: read_test 
     generic :: write(formatted) => write_test 
     generic :: read(formatted) => read_test 
    end type class_test 

contains 

    subroutine  write_test(dtv, unit, iotype, v_list, iostat, iomsg) 
     ! 
     implicit none 
     ! 
     class(class_test), intent(in) :: dtv 
     integer  , intent(in) :: unit 
     character(*), intent(in) :: iotype 
     integer  , intent(in) :: v_list(:) 
     integer  , intent(out) :: iostat 
     character(*), intent(inout) :: iomsg 
     ! 
     iostat = 0 
     ! 
     write(unit,'(a,/)') '<foo>' 
     write(unit,*) dtv%foo 
     write(unit,'(/)') 
     write(unit,'(a,/)') '</foo>' 
     ! 
    end subroutine write_test 

    subroutine  read_test(dtv, unit, iotype, v_list, iostat, iomsg) 
     ! 
     implicit none 
     ! 
     class(class_test), intent(inout) :: dtv 
     integer  , intent(in) :: unit 
     character(*), intent(in) :: iotype 
     integer  , intent(in) :: v_list(:) 
     integer  , intent(out) :: iostat 
     character(*), intent(inout) :: iomsg 
     ! 
     read(unit,'(/)') 
     read(unit,*) dtv%foo 
     read(unit,'(/)') 
     read(unit,'(/)') 
     write(*,*) 'z' 
    end subroutine read_test 

end module mod_test 

program main 

    use mod_test 

    implicit none 

    type(class_test) :: test 

    test%foo = 5 

    write(*,*) 'writing' 
    open(unit=1, file='write.out', status='replace', action='write') 
     write(unit=1,fmt=*) test 
    close(unit=1) 

    write(*,*) 'reading' 
    open(unit=1, file='write.out', status='old', action='read') 
     read(unit=1,fmt=*) test 
    close(unit=1) 

    write(*,*) 'end' 

end program main 

문제 :

(61586,0x7fff7e4dd300) malloc: *** error for object 0x10fa7bac4: pointer being freed was not allocated 
*** set a breakpoint in malloc_error_break to debug 

UDDTIO 루틴은 다음과 같이 프로그램에서 호출 줄 바꿈 상태 인 것 같습니다. ments '(/)'. iostat = -1을 읽기 루틴에 추가하면 문제가 "해결"됩니다. 하지만 왜?

답변

1

컴파일러의 런타임에서 오류를 테스트하고 적절한 조치를 취할 수 있도록 임시 인수를 iostat 임시 인수로 정의해야합니다.

UDDTIO는 해당 컴파일러에서 비교적 최근에 구현 된 기능입니다. 가능한 최신 컴파일러 버전을 사용해야합니다.

읽기 및 쓰기 UDDTIO 프로 시저에서 iostat 가명 인수를 적절하게 정의하면 코드가 현재 17.0 베타로 실행됩니다.

추가 UDDTIO 문제는 17.0의 초기 릴리스에서 수정해야하며 너무 멀리 떨어져서는 안됩니다.

+0

감사합니다. Ian. 나는 컴파일러를 업데이트 할 것이다. 필자는 컴파일러 버전에서 iostat = 0을 추가해도 여전히 오류가 발생합니다. iostat = -1 만 도움이됩니다. – lenzinho

관련 문제