Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Derived type containing an allocatable component in input/output lists

victorht
Beginner
1,670 Views

Dear All,

Steve is so helpful here and I can't help asking another question :-)

ifort has a restriction that Variables containing ultimate allocatable array components are forbidden from appearing directly in input/output lists.

[bash]        type a
          integer, allocatable :: a1(:)
        end type a
        
        type(a), allocatable :: b(:)
                
        write(*,*) 'b = ', b
[/bash]


I am wondering is it possible that the future version of ifort will remove this restriction? If not, what is the better way to write out or read in a derived type containing allocatable components? Our derived types are very complicated and contain many components and sub-components, so it will be very painful to explicitly list all the components and sub-components in input/output list.

Thank you very much for your kind help!

Best regards,

Victor

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,670 Views
This is a restriction in the standard. The standard way of dealing with this is a "user-defined derived type I/O procedure", a feature not yet implemented in Intel Fortran and one I don't expect to see for a while.

The wording in the standard is this:

9 If a list item of derived type in a formatted input/output statement is not processed by a defined in-
10 put/output procedure, that list item is treated as if all of the components of the list item were specified
11 in the list in component order; those components shall be accessible in the scoping unit containing the
12 input/output statement and shall not be pointers or allocatable.
13 If a derived-type list item is not processed by a defined input/output procedure and is not treated as a list
14 of its individual components, all the subcomponents of that list item shall be accessible in the scoping unit
15 containing the input/output statement and shall not be pointers or allocatable.
0 Kudos
victorht
Beginner
1,670 Views

Dear Steve,

Thank you very much for your detailed explanation!

I am wondering are there any differences regarding the treatment of derived type containing an allocatable component in a formatted input/output statement vs. in an unformatted statement?

Thanks again for all your help!

Best regards,

Victor

0 Kudos
Steven_L_Intel1
Employee
1,670 Views
Yes, but it doesn't help you. The standard says that if the derived type or any of its subcomponents are to be processed by a user-defined I/O procedure, then it is treated as the list of components but none of those that are not processed by a user-defined I/O procedure may be pointer or allocatable. Otherwise, the derived type is treated as a single entity, but none of the subcomponents may be pointer or allocatable.
0 Kudos
victorht
Beginner
1,670 Views

Thank you again very much, Steve!

Best regards,

Victor

0 Kudos
Reply