module plink_module implicit none type plink character (len=6) :: patient_number = ' ' character (len=20) :: ward = ' ' type (plink), pointer :: next => null() end type plink end module plink_module program ch22_patients use plink_module implicit none character :: more = 'N' type (plink), pointer :: root, current ! allocate space for 1st item in list allocate (root) print *, 'input Patient number:' read '(A)', root%patient_number print *, 'input hospital ward for this patient:' read '(A)', root%ward ! allocate space for 2nd item in list (will be a blank item at end) allocate (root%next) print *, 'another patient? (Y/N)' read '(A)', more current => root ! current points to beginning of list do while (more=='Y' .or. more=='y') ! current points to next item in list current => current%next print *, 'input Patient number:' read '(A)', current%patient_number print *, 'input hospital ward for this patient:' read '(A)', current%ward ! allocate space for next item in list (will be a blank item at end) allocate (current%next) print *, 'another patient? (Y/N)' read '(A)', more end do ! Print out patient numbers and wards print 100 100 format (1x,'Patient number',3x,'ward') current => root do print 200, current%patient_number, current%ward 200 format (5x,a,7x,a) ! current points to next item in list current => current%next if ( .not. associated(current%next)) exit end do end program ch22_patients