%!PS Days-Of-Year.ps, ggarchar@zapmap.com 12/29/2018
% ADJUST FOR LEAP YEAR
% LEAP YEARS: 2004 2008 2012 2016 2020
/lastDates [ 31 29 31 30 31 30 31 31 30 31 30 31 ] def
/lastDates [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
/pageTitle (2022) def
/theMonth 12 def % MONTH OF FIRST SUN % TEST FOR BORDER VALUE BUG
/theDate 26 def % DATE OF FIRST SUNDAY
/doy 362 def % DAY-OF-YEAR OF FIRST SUNDAY
save /theSave exch def
/Helvetica 15 selectfont
/landScape false def
% MARGINS
/leftMargin 60 def /botMargin 40 def
/rightMargin 40 def /topMargin 40 def
% PAGE SIZE SETTINGS
currentpagedevice /PageSize get aload pop
/pageHeight exch def /pageWidth exch def % 2
landScape { % 3
pageHeight pageWidth
/pageHeight exch def /pageWidth exch def
90 rotate 0 pageHeight neg translate
} if % LANDSCAPE
/areaWidth pageWidth rightMargin sub leftMargin sub def % 4
/areaHeight pageHeight topMargin sub botMargin sub def % 5
% VARIABLES
/monthLabel (JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC) def
/numRows 26 def % NUMBER OF
/numColumns 2 def % NUMBER OF
/rowHeight areaHeight numRows div def % DIVIDE HEIGHT TO FIT
/columnUnit areaWidth 7 div def % DIVIDE WIDTH
/spacing 0 def % BETWEEN COLUMNS, ETC.
/lastDate lastDates theMonth 1 sub get def
/NextDate { % SETS theDate AND theMonth
/theDate theDate 1 add def % NEXT UNIT
/doy doy 1 add def % NEXT DAY OF YEAR
theDate lastDate gt {
/theMonth theMonth 1 add def
/theDate 1 def % FIRST DATE OF MONTH
} if % NEXT MONTH
theMonth lastDates length gt {
/theMonth 1 def
/doy 1 def
} if % JANUARY
/lastDate lastDates theMonth 1 sub get def
} def
/ShowDate {
gsave % THE BOX
currentpoint dayWidth dayHeight rectstroke
grestore
gsave % THE DATE
theMonth 2 mod 0 eq { 0.3 0 0 setrgbcolor } if % RED
gsave
theDate =string cvs % STACK: STRING
dup stringwidth pop 2 div
dayWidth 2 div exch sub % CENTER
11 rmoveto % AND LIFT
show % theDate
grestore
gsave
0.3 0.3 0.3 setrgbcolor % GRAY
/Helvetica 9 selectfont
doy =string cvs % STACK: STRING
dup stringwidth pop %2 div
%dayWidth 2 div exch sub % CENTER
dayWidth exch sub % RIGHT
1 sub 2 rmoveto % AND LIFT
show % DOY
grestore
grestore
} def
/Main {
leftMargin botMargin translate % RELOCATE ORIGIN
0 areaHeight moveto % TOP OF PAGE
gsave
/Helvetica 24 selectfont
pageTitle
%dup stringwidth pop areaWidth exch sub 2 div
205 0 rmoveto
show % PAGE TITLE
grestore
0 52 neg rmoveto % START ROWS DOWN A BIT
0.5 setgray 0 setlinewidth [ 3 2 ] 0 setdash
1 1 0 0.1 setcmykcolor % BLUE
/dayWidth columnUnit 3 div 1 sub def
/dayHeight dayWidth def
/dayWidth dayWidth 2 add def % EXTRA CHARACTER
1 1 numColumns {
/columnNum exch def
gsave
1 1 numRows {
/rowNum exch def % TOP TO BOTTOM
gsave
gsave
gsave
1 1 7 {
/dayNum exch def % TOP TO BOTTOM
ShowDate
theDate lastDate eq { /spacing 6 def /spacing2 6 def } if
dayWidth spacing add 0 spacing sub rmoveto % NEXT DAY IN ROW
theDate 1 eq {
gsave
0.5 setgray
/Helvetica-Bold 12 selectfont
7 dayNum sub dayWidth mul 7 add 7 rmoveto
%theMonth =string cvs show % MONTH LABEL
monthLabel theMonth 1 sub 3 mul 3 getinterval show
grestore
} if
NextDate
/spacing 0 def
} for % EACH DAY IN A ROW
grestore
grestore
grestore
0 spacing2 add dayHeight spacing2 add neg rmoveto % NEXT ROW ON PAGE
/spacing2 0 def
} for % ROWS OF WEEKS
grestore
/shiftRight 3.5 def
columnUnit shiftRight mul 0 rmoveto
/numRows numRows 1 add def
} for % TWO COLUMNS
20 17 moveto 0.4 setgray
(days-of-year.ps ) show
20 0 moveto
/copyright glyphshow ( 2022 ggarchar@zapmap.com) show
showpage
} def
Main (- TOP OF STACK -) pstack clear theSave restore
% END OF FILE