<!-- $Id: templm/ancdes_nxd.txt v7.0 2014/11/22 22:01:04 $ -->

%include;ancdes_stat

%( death date year - spouse death date year tf1/tl1 = nxd %)

%define;stat_a2()
  <table class="title" width="100%%"><tr>
    %if;(evar.m = "A")
      <td>[*generation/generations]0</td>
    %end;
    <td align="center">[*year/month/day]0 [death] - [year/month/day]0 [death] x</td>
    <td align="right">[*date of death]</td>
  </tr></table>
%end;

%define;anc_a()
  <div class="stat2 bcbg1">
    %apply;stat_a2()
    %foreach;ancestor_level(l_v)
      %empty_sorted_list;
      %reset_count;
      %if;(level > 1 and (evar.only != "on" or level = l_v))
        %foreach;ancestor;
          %if;(ancestor.is_male and ancestor.same = "")
            %if;(ancestor.death_date.year != "" and ancestor.spouse.death_date.year != "")
              %let;l1;%ancestor.death_date.year;%in;
              %let;l2;%ancestor.spouse.death_date.year;%in;
              %if;(l1 >= l2)
                %let;l3;%expr(l1 - l2)%in;
                %incr_count;
                %apply;add_in_sorted_list(l1,l3,ancestor.sex,ancestor.index)
              %elseif;(l1 < l2)
                %let;l3;%expr(l2 - l1)%in;
                %incr_count;
                %apply;add_in_sorted_list(l2,l3,ancestor.spouse.sex,ancestor.spouse.index)
              %end;
            %end;
          %end;
        %end;
        %apply;stat2()
      %end;
    %end;
  </div>
%end;

%define;des_a2(curlev, maxlev)
  %foreach;family;
    %if;(curlev < maxlev and family.desc_level = curlev)
      %family.set_infinite_desc_level;
      %if;(death_date.year != "" and death_date.prec = ""
           and spouse.death_date.year != "" and spouse.death_date.prec = "")
        %let;a;%death_date.year;%in;
        %let;b;%spouse.death_date.year;%in;
        %incr_count;
        %if;(a >= b)
          %let;l_age;%expr(a - b)%in;
          %apply;add_in_sorted_list(a,l_age,sex,index)
        %elseif;(a < b)
          %let;l_age;%expr(b - a)%in;
          %apply;add_in_sorted_list(b,l_age,spouse.sex,spouse.index)
        %end;
      %end;
      %if;(has_children)
        %foreach;child;
          %apply;des_a2(curlev+1, maxlev)
        %end;
      %end;
    %end;
  %end;
%end;

%( main %)
%apply;togen()
%if;(evar.m = "A")
  %apply;anc_a()
%else;
  <div class="stat2 bcbg1">
    %apply;stat_a2()
    %reset_desc_level;
    %reset_count;
    %empty_sorted_list;
    %apply;des_a2(0,l_v)
    %apply;stat2()
  </div>
%end;
