#!/bin/csh -ef set prog = `basename $0` if ( ${#argv} < 2 ) then cat << EOF usage : $prog ccyymmdd increment EOF exit( 1 ) endif # --- const ------------------------------------ set ndaymon = ( '31' '28' '31' '30' '31' '30' '31' '31' '30' '31' '30' '31' ) # --- arguments ----------------------------- set datein = $1 set ddays = $2 # --- begin ------------------------------- # extract parts without leading zeros: set year = `echo $datein | /usr/bin/cut -c 1-4` set month = `echo $datein | /usr/bin/cut -c 5-6` set day = `echo $datein | /usr/bin/cut -c 7-8` # on IBM, '09' means octal '9' which is an error ... if ( $month =~ 0? ) set month = `echo $month | /usr/bin/cut -c 2` if ( $day =~ 0? ) set day = `echo $day | /usr/bin/cut -c 2` # Initialize results without leading zeros: @ day2 = ${day} @ month2 = $month @ year2 = $year if ( $ddays > 0 ) then @ day2 = $day2 + $ddays while ( 1 ) @ ndays = $ndaymon[$month2] if ( $month2 == 2 ) then if ( $year2 % 4 == 0 ) set ndays = 29 if ( $year2 % 100 == 0 ) set ndays = 28 if ( $year2 % 400 == 0 ) set ndays = 29 endif if ( $day2 <= $ndays ) break @ day2 = $day2 - $ndays @ month2 = $month2 + 1 if ( $month2 > 12 ) then @ year2 = $year2 + 1 @ month2 = 1 endif end else @ day2 = $day2 + $ddays while ( 1 ) if ( $day2 >= 1 ) break @ month2 = $month2 - 1 if ( $month2 == 0 ) then @ year2 = $year2 - 1 @ month2 = 12 endif @ ndays = $ndaymon[$month2] if ( $month2 == 2 ) then if ( $year2 % 4 == 0 ) set ndays = 29 if ( $year2 % 100 == 0 ) set ndays = 28 if ( $year2 % 400 == 0 ) set ndays = 29 endif @ day2 = $day2 + $ndays end endif # Make resulting day, month, year 2 digits: if ( $day2 < 10 ) set day2 = "0${day2}" if ( $month2 < 10 ) set month2 = "0${month2}" # display the result: echo "${year2}${month2}${day2}"