PROGRAM Radioactive_decay



!  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



   ! This program processes experimental data relating to

   ! radioactive decay which is stored in a file whose name

   ! is supplied at execution time



   ! Constant declarations

   ! max_readings is maximum number of sets of data

   ! in and out are the unit numbers for reading and writing

   INTEGER,PARAMETER :: max_readings=1000,in=3,out=6



   ! Variable declarations

   INTEGER :: alpha,beta,gamma,i,ios,max_interval=0

   REAL :: time,last_time=0.0,period, &

           av_alpha,av_beta,av_gamma,max_av_gamma=0.0

   CHARACTER(LEN=20) :: data_file_name



   ! Obtain name of data file

   DO

      PRINT *,"Please give name of data file"

      READ '(A)',data_file_name



      ! Open data file on unit number "in"

      OPEN (UNIT=in,FILE=data_file_name,STATUS="OLD",IOSTAT=ios)



      ! Repeat request if file not opened satisfactorily

      IF (ios==0) EXIT

      PRINT *,"Unable to open file - please try again"

   END DO



   ! Print headings 

   WRITE (UNIT=out,FMT=201) 



   ! Process max_readings sets of data in a loop

   DO i=1,max_readings

      READ (UNIT=in,FMT=101) time,alpha,beta,gamma 



      ! Calculate interval since last readings 

      period = time-last_time

      last_time = time



      ! Calculate average rates of emission 

      av_alpha = alpha/period

      av_beta = beta/period

      av_gamma = gamma/period



      ! Print statistics for this interval 

      WRITE (UNIT=out,FMT=202) i,period,alpha,beta,gamma,  &

                               av_alpha,av_beta,av_gamma



      ! Check for maximum gamma radiation in this period

      IF (av_gamma > max_av_gamma) THEN 

         max_av_gamma = av_gamma

         max_interval = i

      END IF

   END DO



   ! Print details of interval with maximum gamma radiation 

   WRITE (UNIT=out,FMT=203) max_av_gamma,max_interval



   ! Format statements

   101 FORMAT (F8.2,3(5X,I6)) 

   201 FORMAT ("1","Interval",T11,"Time",T17,"Alpha", &

       T24,"Beta",T30,"Gamma",T37,"Average",T46,"Average", &

       T55,"Average"/ &

       T38,"Alpha",T47,"Beta",T56,"Gamma") 

   202 FORMAT (I6,F8.2,2I6,I7,2F9.2,F10.2) 

   203 FORMAT ("0",T3,"Maximum average gamma radiation was", &

       F7.2," in interval",I5) 



END PROGRAM Radioactive_decay

