Я работаю над кодом на Фортране. И мне приходится иметь дело со многими различными типами выходного файла. Поэтому для управления ими я использую объекты типа.
До сих пор я компилировал свой код с gfortran
для Linux и Windows (и ifort
для Linux); и работает как положено.
Поскольку в ближайшем будущем я хочу интегрировать параллельные вычисления на GPU в свой код с OpenACC, я должен иметь возможность скомпилировать его с pgfortran
(компилятор PGI для Fortran).
Здесь прибывает моя проблема, компиляция (с pgfortran 18-4-0
на окнах) не возвращает мне никакого предупреждения, но при выполнении код вылетает со странной ошибкой: [Exit 3221225477] test.exe
.
Поэтому я попытался изолировать проблему, чтобы решить ее. Я наконец получаю следующее MWE:
MODULE VTK_IO
implicit none
type, abstract :: FormatVTK
contains
procedure(VTK_open_file),nopass, deferred :: open_file_VTK
procedure(VTK_close_file),nopass, deferred :: close_file_VTK
end type FormatVTK
type, extends(FormatVTK) :: FormatAscii
contains
procedure, nopass :: open_file_VTK => open_file_ascii
procedure, nopass :: close_file_VTK => close_file_ascii
end type FormatAscii
type, public :: VTKfileHandler
integer :: unit
class(FormatVTK), allocatable :: type
end type VTKfileHandler
abstract interface
subroutine VTK_open_file( fd )
import VTKfileHandler
class(VTKfileHandler), intent(inout) :: fd
end subroutine
subroutine VTK_close_file(fd)
import VTKfileHandler
class(VTKfileHandler), intent(in) :: fd
end subroutine
end interface
contains
subroutine open_file_ascii( fd )
implicit none
class(VTKfileHandler), intent(inout) :: fd
character(len=80) :: f
!-------------------------------------------------------------------------
write(unit=*, fmt=*) 'open_file_ascii: start'
! stop 6969
f='test_file.txt'
open(newunit = fd%unit, &
file = trim(adjustl(f)), &
form = 'FORMATTED', & ! FORMATTED
access = 'STREAM', & ! SEQUENTIAL
action = 'WRITE', &
status = 'REPLACE')
write(unit=fd%unit,fmt='(100A)') "# vtk DataFile Version "
write(unit=*, fmt=*) 'open_file_ascii: end'
end subroutine open_file_ascii
subroutine close_file_ascii(fd)
implicit none
class(VTKfileHandler), intent(in) :: fd
!-------------------------------------------------------------------------
close(unit=fd%unit)
write(unit=*, fmt=*) 'close_file_ascii: done'
end subroutine close_file_ascii
end module vtk_IO
PROGRAM Test_open
USE VTK_IO
IMPLICIT NONE
type :: OutputFile
class (VTKfileHandler), allocatable :: VTKfile
end type OutputFile
type (OutputFile) :: OutsFiles
!----------------------------------------------------------------------------
print*, 'START: Test_open'
Print*,'initialise_outputs: start'
allocate(VTKfileHandler :: OutsFiles%VTKfile )
allocate(FormatAscii :: OutsFiles%VTKfile%type)
Print*,'initialise_outputs: end'
call OutsFiles%VTKfile%type%open_file_VTK(OutsFiles%VTKfile)
call OutsFiles%VTKfile%type%close_file_VTK(OutsFiles%VTKfile)
print*, 'END: Test_open'
END PROGRAM Test_open
Похоже, что связанная с типом процедура open_file_VTK
не предназначена для процедуры open_file_ascii
. Я думаю, что компилятор теряется с процедурой, связанной с типом. Например, если я удаляю OutsFiles
и напрямую использую VTK-файл, он работает. Но, конечно, мне нужен этот тип встраивания OutputFile
в моем большом коде; в противном случае это было бы слишком просто.
Так это ошибка компилятора? Или я могу что-то сделать, чтобы решить эту проблему?