Fortran Program samp1fixedw.f - 2 digit Year Processing Using a Fixed Window

Lines in blue are 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 samp1fixedw.f
C
C Samp1fixedw.f reads in 4 lines of data
C consisting of:
C
C    Name1
C    Birthdate1
C    Name2
C    Birthdate2
C
C
C where all entries are character strings
C and the birth dates are in date
C format:  MMDDYY.
C
C Note that while it would be more efficient
C for the format of the input data to be in
C ISO (International Standards Organization)
C date format, YYMMDD, the format used provides
C a more useful program for illustrating problems
C 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
C which individual is older and prints the
C result with birth dates expressed in the
C format MM/DD/YY.
C
C To determine the century value for a date,
C this program uses a fixed window where the
C pivot value is defined to be 60, corresponding
C to the year 1960.  With this pivot, the
C following logic is imposed in subroutine
C "window".    
C
C    if YY >= 60, the century value = 1900
C    if YY <  60, the century value = 2000
C
C This defines the fixed window to span the
C range [1960,2059]
C     
C**
	character*6 date1,date2,date1p,date2p
        character *20 name1,name2
	character*3 month(12)
C** Define variables cy1, cy2 character
C  variables to hold the 4-digit years 
	character*4 cy1, cy2 
	integer m1,m2,d1,d2,y1,y2
        data  month/'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
     1   'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'/
        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,60)
	call window(y2,60)
C** Write the 4-digit years computed by
C   window into variables cy1, cy2
        write(cy1,'(i4)')y1
        write(cy2,'(i4)')y2
C** Concatenate cy1, cy2 to form
C   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
C   lines below to y1, y2
	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 fixed window routine,
C   "window" which returns a 4-digit year
C   subject to the pivot, 60 
	subroutine window (y,ipivot)
	integer y
	if(y.ge.ipivot) then
	  y = y + 1900
	else
	  y = y + 2000
	endif
	return
	end