1

I have a class

!> Class representing a general network
type :: net_t
    private

    character(:), allocatable                 :: net_type              !< Type of the net
    integer(kind=integer_4neuro)              :: num_of_neurons        !< Number of neurons in the net
    character(:), allocatable                 :: training_method       !< Used training method

    class(neuron_t), allocatable              :: neuron_arr(:)         !< Array containing all neurons
    integer(kind=integer_4neuro), allocatable :: input_neuron_arr(:)   !< Array of input neuron indices
    integer(kind=integer_4neuro), allocatable :: output_neuron_arr(:)  !< Array of output neuron indices

! class(connection_t), allocatable :: connection_arr(:) !< Array of all connections

contains
    !> Prints information about the network to the standard output.
    procedure :: print_info => print_info_impl

    !> Saves the network instance to the Fortran binary file
    procedure :: save_net_bin => save_net_bin_impl

end type net_t

It contains several arrays (allocatable variables), which are being allocated in constructors (module procedures).

I need to store the class or its properties, at least, into the binary file. I tried to do it by implementing save method:

!> Saves the network instance to the Fortran binary file
subroutine save_net_bin_impl(this, filename)
    type(net_t), intent(in)      :: this      !< Instance of the class 'net_t'
    character(len=*), intent(in) :: filename  !< Name of the file, where the net will be saved into

    open(unit=11, file=filename, form="unformatted", access='stream', position='append')
    write(11) this
    close(unit=11)
end subroutine save_net_bin_impl

But I'm getting following error:

     procedure :: save_net_bin => save_net_bin_impl
             1
Error: Non-polymorphic passed-object dummy argument of ‘save_net_bin_impl’ at (1)

I understand, that the allocatable variables are the cause of my problem, but I have no idea, how to properly solve this problem. Could, you, please, help me with storing this class? write(11) this 1 Error: Data transfer element at (1) cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure

     read(11) new_obj
                    1
Error: Data transfer element at (1) cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure
4

0 回答 0