File: familycheck.ll

package info (click to toggle)
lifelines 3.0.50-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 11,140 kB
  • ctags: 6,517
  • sloc: ansic: 57,468; xml: 8,014; sh: 4,255; makefile: 848; yacc: 601; perl: 170; sed: 16
file content (262 lines) | stat: -rw-r--r-- 7,616 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * @progname    familycheck.ll
 * @version     2000-03-02
 * @author      Dennis Nicklaus nicklaus@fnal.gov
 * @category
 * @output      Text, 80 cols
 * @description
 *
        Consistency checks between indi records and family records
	(making sure links between kids and spouses go both ways.)
	make sure each family that a person says he is a spouse of
	has him as a spouse, and, vice-versa,
	 make sure each person that a family says is a spouse thinks he
	 is a spouse of that family
	It also checks when a person says he is a child in a family that
	the family has that person as a child. 
	And vice-versa, that every child in a family thinks he
	is a child of that family.

	Written by Dennis Nicklaus nicklaus@fnal.gov, 1997.
*/
/* Modifications:
 * 02-mar-00 pbm report multiple HUSB, WIFE, FAMC
 * 01-mar-00 pbm optionally allow SEX U, and missing SEX records
 * 25-sep-99 pbm check for a child in a family more than once
 * 19-feb-99 pbm check for multiple SEX records
 * 13-feb-99 pbm report a child in family when reporting a family with
 *               no parents.
 *		 always show keys of family and individual involved.
 *		 display all messages on screen and write to file.
 */

global(ALLOWSEXU)	/* set to 1 if "SEX U" is allowed */
global(WARNNOSEX)	/* set to 1 to warn about INDIs with no SEX record */

proc main ()
{
    /* user customization section. change the following if desired: */
    set(ALLOWSEXU, 1)	/* 1: "SEX U" should not generate a warning */
    set(WARNNOSEX, 0)	/* 0: don't warn if INDI has no SEX record */
    /* end of user customization section */

    print("processing each person and family in the database...")

    forindi(person, number) {
    	
	call checksex(person)
        families(person, fam, spouse, nfam) {
		set(okboss,0)
		set(s, child(root(fam)))
		while(s) {
		  if(or(eqstr(tag(s), "HUSB"), eqstr(tag(s), "WIFE"))) {
		    if(v, value(s)) {
		      if(reference(v)) {
			if(eqstr(substring(v, 2,sub(strlen(v),1)),key(person))){
			  set(okboss, add(okboss,1))
			}
		      }
		    }
		  }
		  set(s, sibling(s))
		}
		if (eq(0,okboss)){
		  print("\nperson ",key(person)," is not a spouse in ",key(fam))
		  "person " key(person) " is not a spouse in " key(fam) nl()
		}
		elsif(ne(1,okboss)){
		  print("\nperson ",key(person)," is a spouse in ",key(fam),
		  	" ",d(okboss)," times")
		  "person " key(person) " is a spouse in " key(fam)
		  	" " d(okboss) " times" nl()
		}
	
	}
	/* now check that this person is a child in the family
	   he thinks he is (and only once) */
	set(fcnt, 0)
	set(s, child(root(person)))
	while(s) {
	  if(eqstr(tag(s), "FAMC")) {
	    if(v, value(s)) {
	      set(fcnt, add(fcnt, 1))
	      if(reference(v)) {
		set(okboss,0)
		children(fam(v),child,num){
		  if (eq(person,child)) {set(okboss, add(okboss,1))}
		}
		set(x, substring(v, 2, sub(strlen(v),1)))
	        if (eq(0,okboss)){
		   print("\nperson ",key(person)," is not in family ", x)
		   "person " key(person) " is not in family "  x nl()
	        }
	        if (gt(okboss, 1)) {
		   print("\nperson ",key(person)," is in family ",x," ",
		   	d(okboss), " times")
		   "person " key(person) " is in family " x " "
		   	d(okboss) " times" nl()
		}
	      }
	    }
	  }
	  set(s, sibling(s))
	}
	if(gt(fcnt, 1)) {
	  print("\nperson ",key(person)," is a child in ", d(fcnt), " families")
	  "person " key(person) " is a child in " d(fcnt) " families" nl()
	}
    }

  /* now check families so that for every spouse the family says is in the 
     family, that spouse also thinks he/she is in the family. */
  /* the family keys aren't terribly useful in LL (or out since LL
     will change the key numbers on import), so print out the key
     of the indi involved, also */

    forfam(fam, number) {
	set(wcnt,0)
	set(hcnt,0)
	set(s, child(root(fam)))
	while(s) {
	  if(or(eqstr(tag(s), "HUSB"), eqstr(tag(s), "WIFE"))) {
	    if(eqstr(tag(s), "HUSB")) {
	      set(hcnt, add(hcnt,1))
	      if(gt(hcnt, 1)) {
	        print("\nfamily ",key(fam)," has more then one husband ",
			substring(value(s), 2, sub(strlen(value(s)),1)))
	        "family " key(fam) " has more then one husband "
			substring(value(s), 2, sub(strlen(value(s)),1))
	      }
	    }
	    if(eqstr(tag(s), "WIFE")) {
	      set(wcnt, add(wcnt,1))
	      if(gt(wcnt, 1)) {
	        print("\nfamily ",key(fam)," has more then one wife ",
			substring(value(s), 2, sub(strlen(value(s)),1)))
	        "family " key(fam) " has more then one wife "
			substring(value(s), 2, sub(strlen(value(s)),1))
	      }
	    }
	    if(v, value(s)) {
	      if(reference(v)) {
	        set(i, indi(v))
		if(eq(i,0)) {
		  print("\nmissing person ",v," in family ",key(fam))
		  "missing person " v " in family " key(fam) nl()
		}
		else {
		  set(okboss,0)
           	  families(i, fam2, spouse, nfam) {
		    if (eq(fam,fam2)){  set(okboss,add(okboss,1))}
	   	  }
		  if(eq(okboss, 0)) {
		    print("\nperson ",key(i),
		    	" is not linked as a spouse to family ", key(fam))
		    "person " key(i) 
		    	" is not linked as a spouse to family " key(fam)
		  }
		  if(gt(okboss, 1)) {
		    print("\nperson ",key(i),
		    	" is linked as a spouse to family ", key(fam),
			" ",d(okboss)," times")
		    "person " key(i) 
		    	" is linked as a spouse to family " key(fam)
			" " d(okboss) " times" 
		  }
		}
	      }
	    }
	  }
	  set(s, sibling(s))
	}
	if (eq(add(hcnt, wcnt),0)) {
	   print("\nno parents in family ",key(fam))
	   "no parents in family " key(fam)
	   children(fam,child,num){
	     print(" ",key(child))
	     " " key(child)
	     break()
	   }
	   nl()
	}
	children(fam,child,num) {
	  set(ccnt, 0)
	  set(s, child(root(child)))
	  while(s) {
	    if(eqstr(tag(s), "FAMC")) {
	      if(v, value(s)) {
	        if(reference(v)) {
	          if(eqstr(substring(v,2,sub(strlen(v),1)), key(fam))) {
		    set(ccnt, add(ccnt, 1))
		  }
		}
	      }
	    }
	    set(s, sibling(s))
	  }
	  if(eq(ccnt,0)) {
	    print("\nchild ",key(child)," is not linked to family ",key(fam))
	    "child " key(child) " is not linked to family " key(fam) nl()
	  }
	  if(gt(ccnt,1)) {
	    print("\nchild ",key(child)," is linked to family ",key(fam),
	    	" ", d(ccnt)," times")
	    "child " key(child) " is linked to family " key(fam)
	    	" " d(ccnt) " times" nl()
	  }
	}
    }
}

proc checksex(i)
{
    set(val, "")
    set(count, 0)
    set(r, inode(i))
    traverse (r, n, x) {
      if(eqstr(tag(n), "SEX")) {
        set(count, add(count,1))
        if(eq(value(n),0)) {
	  print("\nSEX record with no value ",key(i))
	  "SEX record with no value " key(i) nl()
	}
	elsif(or(eqstr(value(n), "M"), eqstr(value(n), "F"),
	         eqstr(value(n), "?"),
		 and(ALLOWSEXU,eqstr(value(n), "U")))) {
	  if(and(ne(count, 1),not(eqstr(value(n),val)))) {
	    print("\nconflicting SEX records ",val," and ",value(n)," ",key(i))
	    "conflicting SEX records " val " and " value(n) " " key(i) nl()
	  }
	  set(val,value(n))
	}
	else {
	  print("\nSEX record with unrecognize value ",value(n)," ",key(i))
	  "SEX record with unrecognize value " value(n) " " key(i) nl()
	  set(val,value(n))
	}
      }
    }
    if(and(WARNNOSEX, eq(count, 0))) {
      print("\nno SEX record ",key(i))
      "no SEX record " key(i) nl()
    }
    elsif(gt(count,1)) {
      print("\ntoo many SEX records (",d(count),") ",key(i))
      "too many SEX records (" d(count) ") " key(i) nl()
    }
}

proc countnodes(n)
{
  set(count,  0)
  if(n) {
    set(count, 1)
    set(t, tag(n))
    while(s, sibling(n)) {
      if(eqstr(tag(s), t)) {
        set(count, add(count,1))
      }
    }
  }
  return(count)
}