You know that there are “complicated” ways to do what you want. Instead of addressing them, I will answer your first two questions “why?”.
Unlike the built-in assignment, the read statement does not have a target variable, first assigned to the correct size and type parameters for the incoming thing (if it is not already). In fact, it is a requirement that items in the input list are highlighted. Fortran 2008, 9.6.3, clearly states:
If an input or output element is allocated, it must be highlighted.
This is the case whether the distributed variable is a delayed character, a variable with other parameters of the length of the delayed length, or an array.
There is another way to declare a character with a deferred length: assign the pointer attribute to it. However, this will not help you, as we also see
If the input element is a pointer, it must be associated with a definable target ...
Why you don’t have output from your write statement is due to why you see that the character variable is not distributed: you have not met Fortran requirements and therefore cannot expect behavior that isn’t "t.
I will ponder why this limitation is here. I see two obvious ways to ease the restriction
- Allow automatic distribution as a whole;
- allows you to select a symbol of deferred length.
The second case would be easy:
If an input or output element is allocated, it must be assigned, unless it is a scalar character variable with a deferred length.
This, however, is awkward, and such special cases seem to contradict the ideal of the standard as a whole. We will also need a carefully thought-out allusion rule for this special case.
If we move on to the general case for distribution, we presumably require the unallocated effective item to be the last effective item in the list:
integer, allocatable :: a(:), b(:) character(7) :: ifile = '1 2 3 4' read(ifile,*) a, b
and then we need to worry about
type aaargh(len) integer, len :: len integer, dimension(len) :: a, b end type type(aaargh), allocatable :: a(:) character(9) :: ifile = '1 2 3 4 5' read(ifile,*) a
He is very confused very fast. It seems that many problems are solved where there are ways, with varying difficulty, to solve the problem of reading.
Finally, I also note that distribution is possible during a data transfer instruction. Although the variable should be allocated (as the rules apply now), if the derived variable is not necessarily included in the list of input components of the selected variable, if this effective element is processed by a specific input.