On Friday, April 19, 2019 at 5:02:15 PM UTC-4, nshaffer wrote:
> ..
>
> Can anyone educate me on why character constants are not (should not?) be permitted in the format of a read statement?
> ..
Because it is superfluous?!
You may know the Fortran standard permits X editing and TR editing e.g., in section 13 of Fortran 2018:
13.8.1.3 X editing
1 The nX edit descriptor indicates that the transmission of the next
character to or from a record is to occur at the character position n
characters forward from the current position.
NOTE 1
An nX edit descriptor has the same effect as a TRn edit descriptor.
So you can do the following:
read (*, '(i2,1x,i2,1x,i4)') d, m, y
which has the same effect as what appear to be seeking in your code in the original post.
You may know the Fortran standard allows character constants in output editing:
--- begin example ---
integer :: d, m, y
write (*, '(a)', advance='no') "Please enter your date of birth in dd/mm/yyyy format: "
read (*, '(i2,1x,i2,1x,i4)') d, m, y
write (*,'("Day = ",i0,", Month = ",i0,", Year = ",i0)') d, m, y
end
--- end example ---
Upon execution,
Please enter your date of birth in dd/mm/yyyy format: 04/19/2019
Day = 4, Month = 19, Year = 2019
As explained upthread, for your needs " to parse a string like 'foo = 42 ' into a character variable 'foo ' and an integer 42 ", look into NAMELIST, a maligned but useful facility in Fortran:
--- begin example ---
integer :: d, m, y
namelist / bday / d, m, y
character(len=:), allocatable :: s
write (*, '(a)', advance='no') "Please enter your date of birth in dd/mm/yyyy format: "
read (*, '(i2,1x,i2,1x,i4)') d, m, y
write (*,nml=bday)
s = "&bday d=15, m=4, y=1957/"
read( s, nml=bday )
write(*,'("Fortran''s Birthday: ")')
write (*,'("Day = ",i0,", Month = ",i0,", Year = ",i0)') d, m, y
end
--- end example ---
Upon execution,
Please enter your date of birth in dd/mm/yyyy format: 04/19/2019
&BDAY
D=4 ,
M=19 ,
Y=2019 ,
/
Fortran's Birthday:
Day = 15, Month = 4, Year = 1957