home *** CD-ROM | disk | FTP | other *** search
- # QTAwk program to print calenders
- #
- # Print calender for years specified.
- # input: years for calender - 1 year per line or year range
- # output: calender for each year input - leap years indicated
- # with asteric
- #
- #
- BEGIN {
- #
- # print calenders with day of week header
- #
- printf("\t S M T W T F S\t S M T W T F S\t S M T W T F S\n");
- printf("\t0 1 2 3 4 5 6 7\t1 1 2 3 4 5 6\t2 1 2 3 4 5\n");
- printf("\t 8 9 10 11 12 13 14\t 7 8 9 10 11 12 13\t 6 7 8 9 10 11 12\n");
- printf("\t 15 16 17 18 19 20 21\t 14 15 16 17 18 19 20\t 13 14 15 16 17 18 19\n");
- printf("\t 22 23 24 25 26 27 28\t 21 22 23 24 25 26 27\t 20 21 22 23 24 25 26\n");
- printf("\t 29 30 31 \t 28 29 30 31 \t 27 28 29 30 31\n");
- printf("\t3 1 2 3 4\t4 1 2 3\t5 1 2\n");
- printf("\t 5 6 7 8 9 10 11\t 4 5 6 7 8 9 10\t 3 4 5 6 7 8 9\n");
- printf("\t 12 13 14 15 16 17 18\t 11 12 13 14 15 16 17\t 10 11 12 13 14 15 16\n");
- printf("\t 19 20 21 22 23 24 25\t 18 19 20 21 22 23 24\t 17 18 19 20 21 22 23\n");
- printf("\t 26 27 28 29 30 31 \t 25 26 27 28 29 30 31\t 24 25 26 27 28 29 30\n");
- printf("\t \t \t 31\n");
- printf("\t6 1\n");
- printf("\t 2 3 4 5 6 7 8\n");
- printf("\t 9 10 11 12 13 14 15\n");
- printf("\t 16 17 18 19 20 21 22\n");
- printf("\t 23 24 25 26 27 28 29\n");
- printf("\t 30 31\n\n");
- printf("\t J F M A M J J A S O N D\n");
- #
- # Gregorian/Julian calender flag.
- # TRUE == julian
- # FALSE == gregorian
- #
- greg_jul = FALSE;
- }
-
- # test for proper format
- # "year"
- # or
- # "year1 - year2"
- /^{_d}{4,4}({_w}+\-{_w}+{_d}{4,4})?$/ {
- yr1 = yr2 = int($1);
- if ( NF > 1 ) {
- if ( $1 <= $3 ) yr2 = int($3);
- else {
- fprintf("stderr","Improper Format For Year Range.\nInput Line: %s",$0);
- exit 2;
- }
- }
- for ( yr = yr1 ; yr <= yr2 ; yr++ ) {
- #
- # use jdn function to compute julian day number of first day of
- # each month of year. Then compute week-day of first day of
- # month Sunday == 0, Monday == 1 ... Saturday == 6
- #
- for ( i = 1 ; i <= 12 ; i++ )
- first_day[i] = (jdn(yr,i,1) + 1) % 7;
- # check for leap year
- if ( first_day[2] != first_day[3] ) printf("\t*%d*: ",yr); # yes
- else printf("\t %d : ",yr); # no
- # print first day of each month
- for ( month = 1 ; month <= 12 ; month++ )
- printf("%d ",first_day[month]);
- printf("\n");
- }
- printf("\n");
- }
-
- END {
- # print days in each month at bottom
- printf("\n\t 3 2 3 3 3 3 3 3 3 3 3 3\n");
- printf("\t 1 8 1 0 1 0 1 1 0 1 0 1\n");
- }
-
- # function to convert year/month/day into julian day number
- function jdn(year,month,day) {
- local yr;
- local pfac = 0.6;
- local ljdn;
-
- yr = year + (month - 3.0) / 12.0;
- ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
- + int(day) + 1721117;
- if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
- return ljdn;
- }
-