Y2K Millennium Compliance - University of Delaware


Fortran Program samp1slidew.f - 2 digit Year Processing Using a Sliding Window

Lines in blueare comment lines explaining changes made to the original program, samp1.f. Lines or line segments in red are the lines/segments modified or added.

C**           Program samp1slidew.f
C
C Samp1slidew.f reads in 4 lines of data consisting of:
C
C    Name1
C    Birthdate1
C    Name2
C    Birthdate2
C
C
C where all entries are character strings and the birth dates are in
C date format:  MMDDYY.
C
C Note that while it would be more efficient for the format of the
C input data to be in ISO (International Standards Organization) date
C format, YYMMDD, the format used provides a more useful program for
C illustrating problems associated with y2k remediation.
C
C Example:
C
C    John Smith
C    991201
C    Joe Public
C    981131
C
C The program compares the dates and computes which individual is
C older and prints the result with birth dates expressed in the
C format MM/DD/YY.
C
C To determine the century value for a date, this program uses a sliding
C window where the pivot value is defined to be ipivot and is computed
C as a function of the current year and delta, the number of years in the
C future the sliding window is to span.  That is,
C
C    ipivot =  current year + (delta-1) - c
C      
C where c is the appropriate century value and is computed from 
C 
C    c = [first two digits of (current year + delta)] x 100 
C 
C With this pivot, the following logic is imposed in subroutine
C "window".    
C
C    if YY >= ipivot , the century value = c-100
C    if YY <  ipivot , the century value = c
C
C This defines the fixed window to span the range [c-100+ipivot, c+ipivot] 
C     
C**
C** Define delta = the number of years in the future the sliding window is to span.
	integer delta
	parameter (delta = 59)
C** Define c = the appropriate century value
	common c
C** Define c and delta to be integers; define a(3) for use
with routine idate
	integer a(3), c, delta
	character*6 date1,date2,date1p,date2p
        character *20 name1,name2
	character*3 month(12)
C** Define variables cy1, cy2 character variables to hold the
C** 4-digit years.  Define cchar character variable.
	character*4 cy1, cy2, cchar
	integer m1,m2,d1,d2,y1,y2
        data  month/'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
     1   'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'/
C** Call idate which computes the current date
        call idate(a)
C** Store the current 4-digit year computed in a(3) in iyear 
	iyear = a(3)
C** Write the current year + delta into the character variable, cchar 
        write(cchar,'(i4)')iyear + delta
C**  Read the century value from cchar into integer c and multiply by 100
        read(cchar,'(i2)')c
        c = c*100
C** Compute ipviot
	ipivot = iyear + (delta-1) - c
        read(*,'(a)')name1
	read (*,'(a)')date1 
        read(*,'(a)')name2
	read (*,'(a)')date2 
	read(date1,'(3i2)')m1,d1,y1
        read(date2,'(3i2)')m2,d2,y2
C** Call the window subroutine
	call window(y1,ipivot)
	call window(y2,ipivot)
C** Write the 4-digit years computed by window into variables
 cy1, cy2
        write(cy1,'(i4)')y1
        write(cy2,'(i4)')y2
C** Concatenate cy1, cy2 to form date1p, date2p
        date1p = cy1//date1(1:2)//date1(3:4)
        date2p = cy2//date2(1:2)//date2(3:4)
C** Change 1900+y1, 1900+y2 in the print lines below to y1, y
2
	if(date1p.eq.date2p)then
        print *, name1,' with birth date: ', month(m1),' ',d1,', ',y1
        print *
        print *, 'is the same age as'
        print *
        print *, name2,' with birth date: ', month(m2),' ',d2,', ',y2
	else if(date1p.lt.date2p)then
         print *, name1,' with birth date: ', month(m1),' ',d1,', ',y1
         print *
         print *, 'is older than'
         print *
         print *, name2,' with birth date: ', month(m2),' ',d2,', ',y2
        else
         print *, name1,' with birth date: ', month(m1),' ',d1,', ',y1
         print *
         print *, 'is younger than'
         print *
         print *, name2,' with birth date: ', month(m2),' ',d2,', ',y2
        endif
	end
C** Define the sliding window routine, window, which returns a 4
-digit year subject to the pivot, ipivot 
	subroutine window (y,ipivot)
	common c
	integer y
	integer c
	if(y.ge.ipivot) then
	  y = y + c-100
	else
	  y = y + c
	endif
	return
	end