| 1 |
/* |
| 2 |
* @progname span |
| 3 |
* @version 1.1 |
| 4 |
* @author Stephen Dum |
| 5 |
* @category |
| 6 |
* @output text |
| 7 |
* @description |
| 8 |
|
| 9 |
Scan the database and report on the range of ages between birth to marriage, |
| 10 |
birth of parent to birth of child, and age at death. Generates a histogram |
| 11 |
of the results and reports minimum, maximum and average values. Designed |
| 12 |
to be run with llexec, with a command like 'llexec database -x span'. |
| 13 |
|
| 14 |
Note, the resultant histogram will normally fit nicely in a 80 column window, |
| 15 |
(except death range, which could take more like 132 columns) |
| 16 |
if it doesn't it's usually because of some bogus dates (like seeing a mothers |
| 17 |
age as -8 or 70 at the birth of a child.) This script contains added |
| 18 |
complexity to identify the min and max cases, however, the script verify.ll |
| 19 |
will report all the outlying cases in one pass. The average value is |
| 20 |
indicated on the histogram by using asterisks (*). |
| 21 |
|
| 22 |
Also, you can disable the scripts using of dates that are estimates. |
| 23 |
However, this is done by modifing the script rather than having the script |
| 24 |
prompt for an answer, as this is expected to be a less likely case. |
| 25 |
|
| 26 |
Stephen Dum ([email protected]) |
| 27 |
Version 1, 2 November 2005 |
| 28 |
*/ |
| 29 |
|
| 30 |
global(dohist) |
| 31 |
global(estdate) |
| 32 |
|
| 33 |
proc main() |
| 34 |
{ |
| 35 |
set(dohist,1) /* generate histograms */ |
| 36 |
set(estdate,0) /* skip estimated dates */ |
| 37 |
/* we accumulate 4 statistics from the database and store them in |
| 38 |
* the following lists |
| 39 |
*/ |
| 40 |
list(hus_mar) /* marriage age of husband */ |
| 41 |
list(wif_mar) /* marriage age of wife */ |
| 42 |
list(hus_child) /* husbands age at birth of child */ |
| 43 |
list(wif_child) /* wifes age at birth of child */ |
| 44 |
list(death_ages) /* age at death */ |
| 45 |
/* to assist in identifing the unusual extreme situations, |
| 46 |
* (like where it reports a husband was married at 192 years old |
| 47 |
* or at -46 years old |
| 48 |
* we keep some auxilary data for these lists |
| 49 |
*/ |
| 50 |
list(hus_mar_id) /* Family and husband keys */ |
| 51 |
list(wif_mar_id) /* Family and wife keys */ |
| 52 |
list(hus_child_id) /* Family, husband and child key */ |
| 53 |
list(wif_child_id) /* Family, wife and child key */ |
| 54 |
list(death_ages_id) /* Family, husband and child key */ |
| 55 |
|
| 56 |
forfam(fam, cnt) { |
| 57 |
list(hus_dates) /* husband birth dates */ |
| 58 |
list(wif_dates) /* wife birth dates */ |
| 59 |
list(child_dates) /* child birth dates */ |
| 60 |
list(hus_id) /* husband id */ |
| 61 |
list(wif_id) /* wife id */ |
| 62 |
list(child_id) /* child id */ |
| 63 |
/* first process the family and get birth dates for husband, wife and |
| 64 |
* children |
| 65 |
*/ |
| 66 |
set(marr_date,get_marriage_date(fam)) |
| 67 |
|
| 68 |
fornodes(fam,node) { |
| 69 |
if (eqstr(tag(node),"HUSB")) { |
| 70 |
if (val, get_birth_date(indi(value(node)))) { |
| 71 |
push(hus_dates,val) |
| 72 |
push(hus_id,key(indi(value(node)))) |
| 73 |
} |
| 74 |
} elsif (eqstr(tag(node),"WIFE")) { |
| 75 |
if (val, get_birth_date(indi(value(node)))) { |
| 76 |
push(wif_dates,val) |
| 77 |
push(wif_id,key(indi(value(node)))) |
| 78 |
} |
| 79 |
} elsif (eqstr(tag(node),"CHIL")) { |
| 80 |
if (val, get_birth_date(indi(value(node)))) { |
| 81 |
push(child_dates,val) |
| 82 |
push(child_id,key(indi(value(node)))) |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
/* |
| 87 |
print ("Length of hus_dates ",d(length(hus_dates)),nl()) |
| 88 |
print ("Length of wif_dates ",d(length(wif_dates)),nl()) |
| 89 |
print ("Length of child_dates ",d(length(child_dates)),nl()) |
| 90 |
*/ |
| 91 |
/* we now have parents and children dates if any, see if |
| 92 |
* we know enough to process them |
| 93 |
* |
| 94 |
* First - look at marriage date vs parents |
| 95 |
*/ |
| 96 |
if (marr_date) { |
| 97 |
forlist(hus_dates,val,cnt) { |
| 98 |
push(hus_mar,sub(marr_date,val)) |
| 99 |
push(hus_mar_id,concat(key(fam)," ",getel(hus_id,cnt))) |
| 100 |
} |
| 101 |
forlist(wif_dates,val,cnt) { |
| 102 |
push(wif_mar,sub(marr_date,val)) |
| 103 |
push(wif_mar_id,concat(key(fam)," ",getel(wif_id,cnt))) |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/* Second |
| 108 |
for each parent - child pair |
| 109 |
*/ |
| 110 |
forlist(hus_dates,val,cnt) { |
| 111 |
forlist(child_dates,val1,cnt1) { |
| 112 |
push(hus_child,sub(val1,val)) |
| 113 |
push(hus_child_id, |
| 114 |
concat(key(fam)," ",getel(hus_id,cnt)," ",getel(child_id,cnt1)) |
| 115 |
) |
| 116 |
} |
| 117 |
} |
| 118 |
forlist(wif_dates,val,cnt) { |
| 119 |
forlist(child_dates,val1,cnt1) { |
| 120 |
push(wif_child,sub(val1,val)) |
| 121 |
push(wif_child_id, |
| 122 |
concat(key(fam)," ",getel(wif_id,cnt)," ",getel(child_id,cnt1)) |
| 123 |
) |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
forindi(indi,cnt) { |
| 128 |
if (val, get_birth_date(indi)) { |
| 129 |
if (val2,get_death_date(indi)) { |
| 130 |
push(death_ages,sub(val2,val)) |
| 131 |
push(death_ages_id,key(indi)) |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
print(nl()) |
| 136 |
if (not(dohist)) { |
| 137 |
print(" min ave max pairs keys of match",nl()) |
| 138 |
} |
| 139 |
call output(hus_mar,hus_mar_id, "Male Marriage Age ") |
| 140 |
call output(wif_mar,wif_mar_id, "Female Marriage Age") |
| 141 |
call output(hus_child,hus_child_id, "Husband-Child Age ") |
| 142 |
call output(wif_child,wif_child_id, "Wife-Child Age ") |
| 143 |
call output(death_ages,death_ages_id,"Death Age ") |
| 144 |
} |
| 145 |
|
| 146 |
proc output(alist,idlist,title) |
| 147 |
{ |
| 148 |
list(hist) |
| 149 |
if (length(alist)) { |
| 150 |
set(min,getel(alist,1)) |
| 151 |
set(max,min) |
| 152 |
set(min_id,getel(idlist,1)) |
| 153 |
set(max_id,min_id) |
| 154 |
set(sum,0) |
| 155 |
forlist(alist,val,cnt) { |
| 156 |
/* compute histogram data */ |
| 157 |
set(x,div(val,365)) |
| 158 |
setel(hist,x,add(getel(hist,x),1)) |
| 159 |
|
| 160 |
if (gt(min,val)) { |
| 161 |
set(min,val) |
| 162 |
set(min_id,getel(idlist,cnt)) |
| 163 |
} |
| 164 |
if (lt(max,val)) { |
| 165 |
set(max,val) |
| 166 |
set(max_id,getel(idlist,cnt)) |
| 167 |
} |
| 168 |
incr(sum,val) |
| 169 |
} |
| 170 |
set(sum,div(sum,mul(365.0,length(alist)))) |
| 171 |
set(min,div(min,365.0)) |
| 172 |
set(max,div(max,365.0)) |
| 173 |
|
| 174 |
if (dohist) { |
| 175 |
/* generate histogram */ |
| 176 |
set(min,int(min)) |
| 177 |
set(hmax,0) |
| 178 |
forlist(hist,val,cnt) { |
| 179 |
if (gt(val,hmax)) { |
| 180 |
set(hmax,val) |
| 181 |
} |
| 182 |
} |
| 183 |
set(hincr,div(add(hmax,9),10)) |
| 184 |
set(cnt,10) |
| 185 |
while(cnt) { |
| 186 |
set(htar,add(mul(sub(cnt,1),hincr),1)) |
| 187 |
if (or(eq(cnt,10),eq(cnt,7),eq(cnt,4),eq(cnt,1))) { |
| 188 |
print(fl(d(htar),5),"+") |
| 189 |
} else { |
| 190 |
print(" |") |
| 191 |
} |
| 192 |
forlist(hist,val,cnt1) { |
| 193 |
if (ge(cnt1,min)) { |
| 194 |
if (ge(val,htar)) { |
| 195 |
if (eq(cnt1,int(sum))) { |
| 196 |
print("*") |
| 197 |
} else { |
| 198 |
print("x") |
| 199 |
} |
| 200 |
} else { |
| 201 |
print(" ") |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
print (nl()) |
| 206 |
|
| 207 |
decr(cnt) |
| 208 |
} |
| 209 |
set(cnt1,min) |
| 210 |
print( " ") |
| 211 |
while(lt(cnt1,max)) { |
| 212 |
incr(cnt1,5) |
| 213 |
print("+----") |
| 214 |
} |
| 215 |
print(nl()) |
| 216 |
print( " ") |
| 217 |
set(cnt1,sub(min,1)) |
| 218 |
while(lt(cnt1,max)) { |
| 219 |
print(fr(d(cnt1),4)) |
| 220 |
incr(cnt1,5) |
| 221 |
} |
| 222 |
print(" min ave max pairs keys of match",nl()) |
| 223 |
} |
| 224 |
print(title," ",fl(f(min),7),fl(f(sum),7),fl(f(max),8)) |
| 225 |
print(fl(d(length(alist)),6)," ",min_id," :: ",max_id,nl()) |
| 226 |
} else { |
| 227 |
if (dohist) { |
| 228 |
print(" min ave max pairs keys of match",nl()) |
| 229 |
} |
| 230 |
print(title," ",fl("-",7),fl("-",7),fl("-",8),nl()) |
| 231 |
} |
| 232 |
print(nl()) |
| 233 |
} |
| 234 |
|
| 235 |
/* fl(str,len) |
| 236 |
* insert spaces to right of str, to make it's length is at least len |
| 237 |
*/ |
| 238 |
func fr(str,len) { |
| 239 |
if (lt(strlen(str),len)) { |
| 240 |
set(fil,sub(len,strlen(str))) |
| 241 |
incr(fil) |
| 242 |
} else { |
| 243 |
set(fil,1) |
| 244 |
} |
| 245 |
return(concat(str,substring(" ",1,fil))) |
| 246 |
} |
| 247 |
|
| 248 |
/* fl(str,len) |
| 249 |
* insert spaces to left of str, to make it's length at least len |
| 250 |
*/ |
| 251 |
func fl(str,len) { |
| 252 |
if (lt(strlen(str),len)) { |
| 253 |
set(fil,sub(len,strlen(str))) |
| 254 |
} else { |
| 255 |
set(fil,0) |
| 256 |
} |
| 257 |
return(concat(substring(" ",1,fil),str)) |
| 258 |
} |
| 259 |
func get_marriage_date(fam) |
| 260 |
{ |
| 261 |
if (m,marriage(fam)) { |
| 262 |
if (strlen(date(m))) { |
| 263 |
if (estdate) { |
| 264 |
if (index(date(m),"EST",1)) { |
| 265 |
return(0) |
| 266 |
} |
| 267 |
} |
| 268 |
extractdate(m,day,month,year) |
| 269 |
if (year) { |
| 270 |
return(julian(day,month,year)) |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
return(0) |
| 275 |
} |
| 276 |
func get_birth_date(indi) |
| 277 |
{ |
| 278 |
if (b,birth(indi)) { |
| 279 |
if (strlen(date(b))) { |
| 280 |
if (estdate) { |
| 281 |
if (index(date(b),"EST",1)) { |
| 282 |
return(0) |
| 283 |
} |
| 284 |
} |
| 285 |
extractdate(b,day,month,year) |
| 286 |
if (year) { |
| 287 |
return(julian(day,month,year)) |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
return(0) |
| 292 |
} |
| 293 |
func get_death_date(indi) |
| 294 |
{ |
| 295 |
if (b,death(indi)) { |
| 296 |
if (strlen(date(b))) { |
| 297 |
if (estdate) { |
| 298 |
if (index(date(b),"EST",1)) { |
| 299 |
return(0) |
| 300 |
} |
| 301 |
} |
| 302 |
extractdate(b,day,month,year) |
| 303 |
if (year) { |
| 304 |
return(julian(day,month,year)) |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
return(0) |
| 309 |
} |
| 310 |
|
| 311 |
/* |
| 312 |
* The first day that the Gregorian calendar was used in the British Empire |
| 313 |
* was Sep 14, 1752. The previous day was Sep 2, 1752 |
| 314 |
* by the Julian Calendar. The year began at March 25th before this date. |
| 315 |
* Computations not corrected for dates before Sep 14, 1752 nor necessarily |
| 316 |
* for other countries. |
| 317 |
*/ |
| 318 |
|
| 319 |
func julian(day,mon,year) { |
| 320 |
if (gt(mon,2)) { set(mon,sub(mon,3)) } |
| 321 |
else { set(mon,add(mon,9)) decr(year) } |
| 322 |
|
| 323 |
set(c,div(year,100)) |
| 324 |
set(ya, sub(year,mul(100,c))) |
| 325 |
set(jd, add( div(mul(146097,c),4), |
| 326 |
add(div(mul(1461,ya),4), |
| 327 |
add(div(add(mul(153,mon),2),5), |
| 328 |
add(day, 1721119))))) |
| 329 |
/* for our usage this probably doesn't matter |
| 330 |
if (lt(jd,2361222)) { |
| 331 |
print("Warning, Attempt to compute date prior to Brittish use of Gregorian calendar\n") |
| 332 |
} |
| 333 |
*/ |
| 334 |
return(jd) |
| 335 |
} |