| 1 |
/* |
| 2 |
* @progname common.ll |
| 3 |
* @version 0 of 1996-06-11 |
| 4 |
* @author H. Väisänen |
| 5 |
* @category |
| 6 |
* @output Text |
| 7 |
* @description |
| 8 |
Show common ancestors of a person. |
| 9 |
|
| 10 |
Pedigree collapse means that someone is descended from some persons |
| 11 |
in two or more ways. If person's father and mother are related, |
| 12 |
this program lists the common ancestors and the people between them |
| 13 |
and the person. |
| 14 |
|
| 15 |
The program probably does not work if person is descended from |
| 16 |
common ancestors in more than two ways or if there is different |
| 17 |
number of generations in those two ways. |
| 18 |
|
| 19 |
by H. V<a-umlaut>is<a-umlaut>nen |
| 20 |
Version 0, 11 June 1996 |
| 21 |
*/ |
| 22 |
|
| 23 |
proc main() |
| 24 |
{ |
| 25 |
getindi (person) |
| 26 |
"Common ancestors of " name (person) "\n\n\n" |
| 27 |
|
| 28 |
|
| 29 |
/* Father and his ancestors. */ |
| 30 |
indiset (father_set) |
| 31 |
if (f, father(person)) { |
| 32 |
addtoset (father_set, f, 0) |
| 33 |
set (father_set, union (father_set, ancestorset (father_set))) |
| 34 |
} |
| 35 |
|
| 36 |
/* Mother and her ancestors. */ |
| 37 |
indiset (mother_set) |
| 38 |
if (m, mother(person)) { |
| 39 |
addtoset (mother_set, m, 0) |
| 40 |
set (mother_set, union (mother_set, ancestorset (mother_set))) |
| 41 |
} |
| 42 |
|
| 43 |
/* Their intersection. */ |
| 44 |
indiset (intersection_set) |
| 45 |
set (intersection_set, intersect (father_set, mother_set)) |
| 46 |
valuesort (intersection_set) |
| 47 |
|
| 48 |
/* Is minimum of v always zero? I'm not sure... */ |
| 49 |
set (min, 10000) |
| 50 |
forindiset (intersection_set, indi, v, n) { |
| 51 |
if (lt(v, min)) {set (min, v)} |
| 52 |
} |
| 53 |
|
| 54 |
/* First common ancestors. */ |
| 55 |
indiset (common_ancestor_set) |
| 56 |
forindiset (intersection_set, indi, v, n) { |
| 57 |
if (eq(min, v)) { |
| 58 |
addtoset (common_ancestor_set, indi, 0) |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
if (eq(lengthset(common_ancestor_set), 0)) { |
| 63 |
print ("Person's father and mother are not related.") |
| 64 |
"Person's father and mother are not related.\n" |
| 65 |
return() |
| 66 |
} |
| 67 |
|
| 68 |
set (max_name_length, max_length (common_ancestor_set)) |
| 69 |
|
| 70 |
/* Print first common ancestors. */ |
| 71 |
forindiset (common_ancestor_set, indi, v, n) { |
| 72 |
col (20) |
| 73 |
call print_indi (indi, v, add(max_name_length, 20)) "\n" |
| 74 |
} |
| 75 |
"\n" |
| 76 |
|
| 77 |
|
| 78 |
/* Descendants of first common ancestors. */ |
| 79 |
indiset (descendant_set) |
| 80 |
set (descendant_set, descendantset(common_ancestor_set)) |
| 81 |
|
| 82 |
|
| 83 |
/* Links from the father's side. */ |
| 84 |
indiset (set1) |
| 85 |
set (set1, intersect (descendant_set, father_set)) |
| 86 |
valuesort (set1) |
| 87 |
|
| 88 |
/* Links from the mother's side. */ |
| 89 |
indiset (set2) |
| 90 |
set (set2, intersect (descendant_set, mother_set)) |
| 91 |
valuesort (set2) |
| 92 |
|
| 93 |
|
| 94 |
set (max_name_length, max_length(set1)) |
| 95 |
set (length2, max_length(set2)) |
| 96 |
|
| 97 |
if (gt(length2, max_name_length)) {set (max_name_length, length2)} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
/* Print father's line on the left, mother's line on the right. */ |
| 102 |
table (mom) |
| 103 |
forindiset (set2, indi, v, n) { |
| 104 |
insert (mom, d(v), indi) |
| 105 |
} |
| 106 |
forindiset (set1, indi, v, n) { |
| 107 |
call print_indi (indi, v, add(max_name_length,1)) col(40) |
| 108 |
call print_indi (lookup(mom, d(v)), v, add(max_name_length,40)) "\n" |
| 109 |
} |
| 110 |
|
| 111 |
"\n" |
| 112 |
col (20) |
| 113 |
call print_indi (person, add(v,1), add(max_name_length, 20)) "\n" |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
proc print_indi (indi, v, length) |
| 118 |
{ |
| 119 |
name (indi) col(length) " (" |
| 120 |
if (p, birth(indi)) {year(p)} else {" "} |
| 121 |
" - " |
| 122 |
if (p, death(indi)) {year(p)} else {" "} |
| 123 |
") (" d(v) ")" |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
/* Maximum length of a name of a person in person_set. |
| 128 |
*/ |
| 129 |
func max_length (person_set) |
| 130 |
{ |
| 131 |
set (max_name_length, 0) |
| 132 |
forindiset (person_set, indi, v, n) { |
| 133 |
if (lt(max_name_length, strlen(name(indi)))) { |
| 134 |
set (max_name_length, strlen(name(indi))) |
| 135 |
} |
| 136 |
} |
| 137 |
return (max_name_length) |
| 138 |
} |
| 139 |
/* |
| 140 |
----------------------------------------------------------------------- |
| 141 |
|
| 142 |
This is an example of the output. I have deleted the surnames because |
| 143 |
they contain 8 bit letters. |
| 144 |
|
| 145 |
Common ancestors of Juho XXXXXXXX |
| 146 |
|
| 147 |
|
| 148 |
Maria AAAAAAAAAAA (1606 - 1661) (0) |
| 149 |
Heikki XXXXXXXX (1603 - 1670) (0) |
| 150 |
|
| 151 |
Heikki XXXXXXXX (1628 - 1705) (1) Lauri XXXXXXXX (1637 - 1701) (1) |
| 152 |
Heikki XXXXXXXX (1666 - 1731) (2) Eeva XXXXXXXX (1659 - 1724) (2) |
| 153 |
Aatami XXXXXXXX (1687 - 1733) (3) Anna BBBBBBBB (1691 - 1746) (3) |
| 154 |
Juho XXXXXXXX (1721 - 1775) (4) Ulla CCCCCCCC (1724 - 1789) (4) |
| 155 |
|
| 156 |
Juho XXXXXXXX (1761 - 1848) (5) |
| 157 |
*/ |