summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/dtio_28.f03
blob: 053678b7fd823d267b02fef7df673223276e3620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
! { dg-do run }
! PR78670 Incorrect file position with namelist read under DTIO
MODULE m
  IMPLICIT NONE
  TYPE :: t
    CHARACTER :: c
  CONTAINS
    PROCEDURE :: read_formatted
    GENERIC :: READ(FORMATTED) => read_formatted
    PROCEDURE :: write_formatted
    GENERIC :: WRITE(FORMATTED) => write_formatted
  END TYPE t
CONTAINS
  SUBROUTINE write_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
    CLASS(t), INTENT(IN) :: dtv
    INTEGER, INTENT(IN) :: unit
    CHARACTER(*), INTENT(IN) :: iotype
    INTEGER, INTENT(IN) :: v_list(:)
    INTEGER, INTENT(OUT) :: iostat
    CHARACTER(*), INTENT(INOUT) :: iomsg
    write(unit,'(a)', iostat=iostat, iomsg=iomsg) dtv%c
  END SUBROUTINE write_formatted
  
  SUBROUTINE read_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
    CLASS(t), INTENT(INOUT) :: dtv
    INTEGER, INTENT(IN) :: unit
    CHARACTER(*), INTENT(IN) :: iotype
    INTEGER, INTENT(IN) :: v_list(:)
    INTEGER, INTENT(OUT) :: iostat
    CHARACTER(*), INTENT(INOUT) :: iomsg
    
    CHARACTER :: ch
    dtv%c = ''
    DO
      READ (unit, "(A)", IOSTAT=iostat, IOMSG=iomsg) ch
      IF (iostat /= 0) RETURN
      ! Store first non-blank
      IF (ch /= ' ') THEN
        dtv%c = ch
        RETURN
      END IF
    END DO
  END SUBROUTINE read_formatted
END MODULE m

PROGRAM p
  USE m
  IMPLICIT NONE
  TYPE(t) :: x
  TYPE(t) :: y
  TYPE(t) :: z
  integer :: j, k
  NAMELIST /nml/ j, x, y, z, k
  INTEGER :: unit, iostatus
  
  OPEN(NEWUNIT=unit, STATUS='SCRATCH', ACTION='READWRITE')
  
  x%c = 'a'
  y%c = 'b'
  z%c = 'c'
  j=1
  k=2
  WRITE(unit, nml)
  REWIND (unit)
  x%c = 'x'
  y%c = 'y'
  z%c = 'x'
  j=99
  k=99
  READ (unit, nml, iostat=iostatus)
  if (iostatus.ne.0) STOP 1
  if (j.ne.1 .or. k.ne.2 .or. x%c.ne.'a' .or. y%c.ne.'b' .or. z%c.ne.'c') STOP 2
  !WRITE(*, nml)
END PROGRAM p