examples/cal.mod
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 06 Dec 2010 13:09:21 +0100
changeset 1 c445c931472f
permissions -rw-r--r--
Import glpk-4.45

- Generated files and doc/notes are removed
alpar@1
     1
/* cal.mod - print an ASCII calendar of the given year */
alpar@1
     2
alpar@1
     3
/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
alpar@1
     4
alpar@1
     5
param year, integer, >= 0001, <= 3999, default 2010;
alpar@1
     6
alpar@1
     7
param first_day{m in 1..12}, integer, >= 0, <= 6, :=
alpar@1
     8
      time2str(str2time(year & "-" & m & "-01", "%Y-%m-%d"), "%w");
alpar@1
     9
alpar@1
    10
param days_in_month{m in 1..12}, integer, >= 28, <= 31, :=
alpar@1
    11
      (str2time(year + (if m < 12 then 0 else 1) & "-" &
alpar@1
    12
         (if m < 12 then m+1 else 1) & "-01", "%Y-%m-%d") -
alpar@1
    13
      str2time(year & "-" & m & "-01", "%Y-%m-%d")) / 86400;
alpar@1
    14
alpar@1
    15
param foo{m in 1..12, k in 0..5, d in 0..6}, integer, :=
alpar@1
    16
      7 * k + d + 1 - first_day[m];
alpar@1
    17
alpar@1
    18
param cal{m in 1..12, k in 0..5, d in 0..6}, integer, :=
alpar@1
    19
      if 1 <= foo[m,k,d] and foo[m,k,d] <= days_in_month[m] then
alpar@1
    20
         foo[m,k,d];
alpar@1
    21
alpar@1
    22
printf "\n";
alpar@1
    23
printf "%33s%04d\n", "", year;
alpar@1
    24
printf "\n";
alpar@1
    25
for {t in 1..12 by 3}
alpar@1
    26
{     for {m in t..t+2}
alpar@1
    27
      {  printf "%7s%-14s", "", time2str(str2time(m, "%m"), "%B");
alpar@1
    28
         printf{0..0: m < t+2} "   ";
alpar@1
    29
      }
alpar@1
    30
      printf "\n";
alpar@1
    31
      for {m in t..t+2}
alpar@1
    32
      {  printf "  S  M Tu  W Th  F  S";
alpar@1
    33
         printf{0..0: m < t+2} "   ";
alpar@1
    34
      }
alpar@1
    35
      printf "\n";
alpar@1
    36
      for {k in 0..5}
alpar@1
    37
      {  for {m in t..t+2}
alpar@1
    38
         {  for {d in 0..6}
alpar@1
    39
            {  printf{0..0: cal[m,k,d]  = 0} "   ";
alpar@1
    40
               printf{0..0: cal[m,k,d] != 0} " %2d", cal[m,k,d];
alpar@1
    41
            }
alpar@1
    42
            printf{0..0: m < t+2} "   ";
alpar@1
    43
         }
alpar@1
    44
         printf "\n";
alpar@1
    45
      }
alpar@1
    46
}
alpar@1
    47
printf "\n";
alpar@1
    48
alpar@1
    49
end;