MODULE global_data



!  Copyright 1994, Miles Ellis, Ivor Philips and Tom Lahey

!  Copyright 1994, Addison-Wesley Publishers Ltd.

!  Copyright 1994, Addison-Wesley Publishing Company Inc.

!  Permission is granted for the use of this code for the purpose of teaching

!  and/or learning the Fortran 90 language provided that the above copyright

!  notices are included in any copies made.

!  Neither the authors nor the publishers accept any responsibility for

!  any results obtained by use of this code.



   IMPLICIT NONE

   TYPE person

      CHARACTER(LEN=15) :: first_name

      CHARACTER(LEN=20) :: last_name

      CHARACTER :: sex

      INTEGER :: marital_status, age

      REAL :: height,weight

   END TYPE person

END MODULE global_data





SUBROUTINE input(people,number_people)



!  Copyright 1994, Miles Ellis, Ivor Philips and Tom Lahey

!  Copyright 1994, Addison-Wesley Publishers Ltd.

!  Copyright 1994, Addison-Wesley Publishing Company Inc.

!  Permission is granted for the use of this code for the purpose of teaching

!  and/or learning the Fortran 90 language provided that the above copyright

!  notices are included in any copies made.

!  Neither the authors nor the publishers accept any responsibility for

!  any results obtained by use of this code.



   USE Global_Data

   IMPLICIT NONE



   ! An input subroutine for a survey



   ! Dummy arguments

   TYPE(person),DIMENSION(:) :: people

   INTEGER :: number_people



   ! Local variables

   INTEGER :: i,max_people



   ! Store maximum number of data sets

   max_people=SIZE(people)



   ! Display data format

   PRINT *,"Type data as follows: " 

   PRINT *,"Cols.  1-15  First name"

   PRINT *,"Cols. 21-40  Last name" 

   PRINT *,"Col.     43  Sex (F=female, M=male)" 

   PRINT *,"Col.     45  Marital status (0=single, 1=married," 

   PRINT *,"             2=widowed, 3=divorced, 4=cohabiting," 

   PRINT *,"             9=unknown)" 

   PRINT *,"Cols. 47,48  Age (in years)" 

   PRINT *,"Cols. 51-53  Height (in cm.)" 

   PRINT *,"Cols. 56-62  Weight (in kg. in the form kkk.ggg)" 

   PRINT *," " 

   PRINT *,"Data should be terminated by the words &

           &'END OF DATA' typed in cols. 1-11" 

   PRINT *," " 



   ! Loop to read data 

   DO i=1,max_people 

      READ '(A15,5X,A20,2X,I1,1X,I1,1X,I2,2X,F3.2,2X,F7.3)', &

           people(i)



      ! Check if this is the terminator record 

      IF (people(i)%first_name(1:11) == "END OF DATA") EXIT



   END DO



   ! Check to see if a terminator was found

   IF (i>max_people) THEN

      PRINT *,"Maximum number of records (",max_people,") read"

      PRINT *,"with no terminator - input halted"

      ! Save number of data records read

      number_people = max_people

   ELSE

      number_people = i-1

   END IF



END SUBROUTINE input

