
Fortran Program samp1fixedw.f - 2 digit Year Processing Using a Fixed 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 samp1fixedw.f
C
C Samp1fixedw.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 fixed
C window where the pivot value is defined to be 60, corresponding to the
C year 1960. With this pivot, the 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 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 variables to hold the
C** 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 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, 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, window which returns a 4-digit year 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