%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2001-02-14-12:58
% TeXProject.sty                                        %
% Copyright (C) 1995 Stephane Bressan & Eitan M. Gurari %
%                                                       %
% This program can redistributed and/or modified under  %
% the terms of the LaTeX Project Public License         %
% Distributed from CTAN archives in directory           %
% macros/latex/base/lppl.txt; either version 1 of the   %
% License, or (at your option) any later version.       %
%                                                       %
% However, you are allowed to modify this program       %
% without changing its name, if you modify its          %
% signature. Changes to the signature can be introduced %
% with a directive of the form                          %
%            \message{signature}                        %
%                                                       %
% Stephane.Bressan@ecrc.de   gurari@cse.ohio-state.edu  %
% http://www.cse.ohio-state.edu/~gurari/                %
% Needs:                                                %
%   DraTex.sty and AlDraTex.sty                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2001-02-14-12:58}
\ifx\Draw\UnDefined
   \def\DrawRect{\input DraTex.sty }
   \expandafter\DrawRect
\fi
\ifx\Tree\UnDefined
  \def\Tree{\input AlDraTex.sty }
  \expandafter\Tree
\fi
\expandafter\edef\csname :RestoreCatcodes\endcsname{%
   \catcode`\noexpand\noexpand\noexpand \^=\the\catcode`\^%
}
\catcode`\^=7
\expandafter\edef\csname :RestoreCatcodes\endcsname{%
   \csname :RestoreCatcodes\endcsname
   \catcode`\noexpand \_=\the\catcode`\_%
   \catcode`\noexpand \ =\the\catcode`\ %
   \catcode`\noexpand \&=\the\catcode`\&%
   \catcode`\noexpand :=\the\catcode`:%
   \catcode`\noexpand \^^M=\the\catcode`\^^M%
   \let\expandafter\noexpand
       \csname:RestoreCatcodes\endcsname=\noexpand\undefined}
\catcode`\^^M=9        \catcode`\ =9      \catcode`\&=13  \relax
  \expandafter
   \def\csname reseffB:\endcsname#1{\csname reseffC:\endcsname#1:}
\expandafter
   \def\csname reseffC:\endcsname#1:#2:{
                                    \csname reseff:\endcsname{#1}{#2}}
     \catcode`\:=11 \relax
  \newif\ifpwarnn:
\def\warningsoff{\pwarnn:false}
\def\warningson{\pwarnn:true}
\warningson
\def\pwarn:#1{\ifpwarnn: \immediate\write16{l.\the\inputlineno
                                   \space--- warning ---\space #1}\fi}
\def\whitedef:#1{
  \expandafter\def\csname #1\endcsname{\bgroup
    \ignorewhite:  \csname #1:X\endcsname}

  \expandafter\def\csname #1:X\endcsname##1{\egroup
     \expandafter\ifx\csname##1 :type\endcsname\relax \else
        \pwarn:{Redefining\space##1?}
     \fi
     \edef\items:{\item:{##1}\items:}
     \expandafter\let\csname##1 :bool\endcsname=\empty
     \expandafter\edef\csname##1 :prjid\endcsname{
          \expandafter\noexpand\csname\projectid: :minmax\endcsname}
     \csname #1:Y\endcsname{##1}}
  \expandafter\def\csname #1:Y\endcsname}

\def\ignorewhite:{ \ifnum \the\catcode`\ =9 \else
    \catcode`\ =9   \catcode`\^^M=9 \catcode`\^^I=9 \relax \fi }
\def\forbiencomm:{\pwarn:{\string\newproject\space missing}}
\def\defcom#1{
  \expandafter\def\csname#1\endcsname{
     \bgroup  \ignorewhite:  \csname#1:A\endcsname}
  \expandafter\def\csname#1:A\endcsname##1{\egroup
      \csname#1:B\endcsname{##1}}
  \expandafter\def\csname#1:B\endcsname}
\def\verify:::#1{
   \expandafter\ifx\csname#1 :title\endcsname\relax \pwarn:{#1?} \fi
   \csname#1 :prjid\endcsname
%
}
\IntVar\I:I    \IntVar\J:J   \IntVar\K:K
\DecVar\Q:Q    \DecVar\R:R   \DecVar\T:T

  \def\tasknode:{0}
\def\milestonenode:{1}
\def\projectnode:{2}
\whitedef:{DEFTASK:}#1#2{
  \expandafter\edef\csname#1 :type\endcsname{\tasknode:}
  \expandafter\def\csname#1 :title\endcsname{#2}
  \bgroup   \ignorewhite:  \deftaskA:{#1}}

\def\deftaskA:#1#2#3#4#5{\egroup
  \expandafter\edef\csname#1 :date1\endcsname{#2}
  \expandafter\edef\csname#1 :date2\endcsname{#3}
  \def\temp:{#4}
\ifx\temp:\empty
   \pwarn:{`#1'\space has\space no\space contributions}
\else
   \getlist:{#1 :eff}{#4}\reseffA:
   \let\reseff:=\relax
   \let\reseffA:=\reseffB:
   \expandafter\edef\csname#1 :eff\endcsname{\csname#1 :eff\endcsname}
\fi

  \setprev:{#1}{#5}
  \deftaskB:{#1}}

\def\deftaskB:#1#2{
  \expandafter\def\csname#1 :desc\endcsname{#2}
  \trace:{#1} }
\whitedef:{DEFMILESTONE:}#1#2#3{
  \expandafter\edef\csname#1 :type\endcsname{\milestonenode:}
  \expandafter\def\csname#1 :title\endcsname{#2}
  \expandafter\edef\csname#1 :date\endcsname{#3}
  \bgroup   \ignorewhite:  \defmilestoneA:{#1}}

\def\defmilestoneA:#1#2{\egroup
  \setprev:{#1}{#2}
  \defmilestoneB:{#1}}

\def\defmilestoneB:#1#2{
  \expandafter\def\csname#1 :desc\endcsname{#2}
  \trace:{#1}}
\whitedef:{DEFPROJECT:}#1#2{
  \expandafter\edef\csname#1 :type\endcsname{\projectnode:}
  \edef\projects:{{#1}{\projects:}}
  \expandafter\def\csname#1 :title\endcsname{#2}
  \bgroup  \ignorewhite: \defprojectA:{#1}}

\def\defprojectA:#1#2#3{\egroup
  \getlist:{#1 :under}{#2}\utask:
\def\utask:##1{%
  \sapply{:temp,merge,
      {\expandafter \ifx \csname ##1:ancs\endcsname\relax\else
       \csname ##1:ancs\endcsname\fi},{#1}}
  \expandafter \let \csname ##1: ancs\endcsname= \:temp:mkls
  \let\:temp:mkls =\:UnDef
  }
\csname#1: under\endcsname


  \setprev:{#1}{#3}
  \defprojectB:{#1}}

\def\defprojectB:#1#2{
  \expandafter\def\csname#1 :desc\endcsname{#2}
  \trace:{#1}}
\def\setproject:data#1{
   \expandafter\ifx\csname#1 :type\endcsname\relax
      \pwarn:{Missing\space `#1'}
   \fi
   \ifnum\csname#1 :type\endcsname=\projectnode:\relax
      \expandafter\ifx\csname#1 :date1\endcsname\relax
        \def\minY:{10000}  \def\minM:{10000}  \def\minD:{10000}
\def\maxY:{0}  \def\maxM:{0}    \def\maxD:{0}

           \let\utask:=\utask:I
\csname#1 :under\endcsname

        \expandafter\edef\csname#1 :date1\endcsname{\minD:/\minM:/\minY:}
\expandafter\edef\csname#1 :date2\endcsname{\maxD:/\maxM:/\maxY:}

   \fi \fi
}

  \def\newproject{
   \let\item:=\relax
\def\items:{}
\tcount:=0\relax
\let\deftask=\DEFTASK:
\let\defmilestone=\DEFMILESTONE:
\let\defproject=\DEFPROJECT:
\let\restoregal::=~
\def\restoregal:{\let~=\restoregal::}
\def\projects:{}
\def\verify:##1{}
\def\verify::##1{}
\let\minmaxdates=\MINMAXDATES:
\MINMAXDATES:{1/1/0//31/12/99}

}
\def\endprojectdefA:{  \let\deftask=\forbiencomm:
\let\defmilestone=\deftask
\let\defproject=\deftask
\let\minmaxdates=\forbiencomm:

}
\endprojectdefA:

\def\endnewproject{
   \endprojectdefA:       \def\item:##1{
   \let\prev:=\checkmemb:    \csname##1 :prev\endcsname
   \let\utask:=\checkmemb:   \csname##1 :under\endcsname
}
\items:

\ifx \projects:\empty\else
  \expandafter\setproject:\projects:
  \expandafter\verify:dates:\projects:
\fi

   \def\item:##1{ \expandafter\let\csname##1 :bool\endcsname=\UnDef: }
\items:
\let\item:=\UnDef:
\let\items:=\UnDef:
\restoregal:
\let\projects:=\UnDef:
\let\verify:=\verify:::
\let\verify::=\verify:::

   \I:I=\projectid:;  \I:I+1;  \edef\projectid:{\Val\I:I}
}

  \def\filtercommand{
  \def\filtercommand:##1{
    \def\putcommand{##1}
    \let\filtercommand:=\empty
} }
\let\filtercommand:=\empty
\defcom{name}#1{    \verify:{#1}
   \expandafter\expandafter\expandafter\filtercommand:
      \expandafter\expandafter\expandafter{\csname#1 :title\endcsname }}
\defcom{annotation}#1{ \verify:{#1}
    \expandafter\expandafter\expandafter\filtercommand:
    \expandafter\expandafter\expandafter{\csname#1 :desc\endcsname}}
\defcom{resource}#1{{ \verify:{#1}
\ifnum\csname#1 :type\endcsname=\milestonenode:\space
   \pwarn:{`#1'\space has\space no\space resources} ???
\fi
\def\sepitems:{\def\sepitems:{\append:Def\all:des{,\space}}}
\let\reseff:=\reseffI:   \let\all:des=\empty
\traversedo:{#1}\listrsrc:
\expandafter\def\expandafter\all:des
    \expandafter{\expandafter\filtercommand:\expandafter{\all:des}}
 \expandafter}\all:des}
\defcom{effort}#1{{ \def\temp:##1,##2,##3//{
   \def\first:{##1} \def\second:{##2}
}
\temp:#1,,//   \verify:{\first:}
\ifnum\csname\first: :type\endcsname=\milestonenode:\space
    \pwarn:{`#1'\space has\space no\space resources} ???
    \let\:temp=\empty
\else
    \findeffort:\first:\second:
    \edef\:temp{\noexpand\filtercommand:{\temp:}}
\fi
 \expandafter}\:temp}
\defcom{contributions}#1{{  \verify:{#1}
\ifnum\csname#1 :type\endcsname=\milestonenode:\space
         \pwarn:{`#1'\space has\space no\space contributions} ???
\else    \findthecontri:{#1}   \fi
  }}
\defcom{start}#1{ \verify:{#1} \startfinish:{#1}1 }

\defcom{finish}#1{\verify:{#1} \startfinish:{#1}2 }

\def\startfinish:#1#2{
  \ifnum\csname#1 :type\endcsname=\milestonenode:\relax
     \expandafter\expandafter\expandafter
     \filtercommand: \expandafter\expandafter\expandafter
         {\expandafter\expandafter\expandafter
         \showdate:\csname#1 :date\endcsname/0/0/0//}
  \else
     \expandafter\expandafter\expandafter
     \filtercommand:  \expandafter\expandafter\expandafter
         {\expandafter\expandafter\expandafter
        \showdate:\csname#1 :date#2\endcsname/0/0/0//}
 \fi }
\defcom{apply}#1{ \apply:#1,,,,//  }
\defcom{rapply}#1{ \rapply:#1,,,,//  }
\defcom{sapply}#1{
   \edef\:temp{\Val\I:I}
\push:macro\:temp

   \def\temp:##1,##2,##3,##4/+/-]/[{
   \def\result:lst{##1}  \let\list:op=\empty
   \IF \EqText(##2,merge)\THEN
      \def\list:op{\two:args#1,/+/-]/[
\expandafter\edef\csname \result:lst :mkls\endcsname{\arg:one,\arg:two}
\cln:res

}\FI
   \IF \EqText(##2,intersect)\THEN
      \def\list:op{\two:args#1,/+/-]/[
\get:result\in:both
\cln:res

} \FI
   \IF \EqText(##2,subtract)\THEN
      \def\list:op{\two:args#1,/+/-]/[
\get:result\first:only
\cln:res

} \FI
   \IF \EqText(##2,milestones)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\get:result\scr:mi
\cln:res

} \FI
   \IF \EqText(##2,tasks)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\get:result\scr:ta
\cln:res

} \FI
   \IF \EqText(##2,projects)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\get:result\scr:pr
\cln:res

} \FI
   \IF \EqText(##2,after)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\get:result\scr:af
\cln:res

}\FI
   \IF \EqText(##2,before)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two  \def\prev:########1{,########1}
\get:result\scr:be
\cln:res

}\FI
   \IF \EqText(##2,up)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\get:result\scr:up
\cln:res

} \FI
   \IF \EqText(##2,down)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two  \def\utask: ########1{,########1}
\get:result\scr:dw
\cln:res

} \FI
   \IF \EqText(##2,sort)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\let\arg:one=\arg:two
\let\:temp\empty
\get:result\scr:srt  \sapply{##1,\gob:I}

} \FI
   \IF \EqText(##2,defproject)\THEN
      \def\list:op{\one:args#1,/+/-]/[
\df:spr#1/+/-]/[
\ifx \arg:two\empty
   \pwarn:{defproject\space ##1\space without\space members?}
\else
   \let\arg:one=\arg:two
   \get:result\scr:df
   \edef\:temp{{##1}{\AA:k}{\:temp}{}{\BB:k}}
    \expandafter\let\csname##1 :date1\endcsname\relax
    \expandafter\let\csname##1 :date2\endcsname\relax
   \push:macro\checkmemb:  \def\checkmemb:########1{}
   \newproject   \expandafter\defproject\:temp   \endnewproject
   \pop:macro\checkmemb:
\fi
} \FI
   \IF \EqText(##1,traceon)\THEN
      \def\list:op{\let\rs:trc=\empty
} \FI
   \IF \EqText(##1,traceoff)\THEN
      \def\list:op{\def\rs:trc########1{}
} \FI
   \ifx \list:op\empty
      \def\list:op{\futurelet
   \:temp\sapply:apply #1,,,,/+/-]/[
}
   \fi
   \list:op  }
\temp:#1,,,,/+/-]/[

   \pop:macro\:temp
\I:I=\:temp;

}
\IntVar\s:appN
\def\sapply:apply#1,#2,#3/+/-]/[{
   \ifx \:temp\bgroup \else
  \expandafter\ifx\csname #1:mkls\endcsname\relax
     \pwarn:{\string\sapply{#1,\string#2,...}?}
\fi\fi

   \expandafter\edef\csname \result:lst :mkls\endcsname{\ifx
      \:temp\bgroup #1\else
           \expandafter\ifx\csname #1:mkls\endcsname\relax #1
           \else \csname #1:mkls\endcsname
      \fi \fi}
   \cln:res

   \def\breadth{0}
   \def\app:mi{#2}
   \expandafter\expandafter\expandafter\r:app
   \expandafter\expandafter\expandafter\s:app
       \csname \result:lst :mkls\endcsname,/+/-]/[
}
\def\s:app#1{\I:I=\breadth; \I:I+1; \edef\breadth{\Val\I:I}
  \push:macro\breadth
\push:macro\app:mi
\push:macro\app:pr
\push:macro\app:ta

  \app:mi{#1}
  \pop:macro\app:ta
\pop:macro\app:pr
\pop:macro\app:mi
\pop:macro\breadth

}
\def\s:appA#1{\I:I=\breadth; \I:I+1; \edef\breadth{\Val\I:I}
  \push:macro\breadth
\push:macro\app:mi
\push:macro\app:pr
\push:macro\app:ta

  \apply{#1,\app:mi,\app:pr,\app:ta}
  \pop:macro\app:ta
\pop:macro\app:pr
\pop:macro\app:mi
\pop:macro\breadth

}
\def\scr:ta#1{\ifnum\csname#1:type\endcsname=\tasknode:\space
   \edef\:temp{\:temp,#1}\fi }
\def\scr:mi#1{\ifnum\csname#1:type\endcsname=\milestonenode:\space
   \edef\:temp{\:temp,#1}\fi }
\def\scr:pr#1{\ifnum\csname#1:type\endcsname=\projectnode:\space
   \edef\:temp{\:temp,#1}\fi }
\def\df:spr#1,#2,#3,#4,#5/+/-]/[{%
   \def\AA:k{#4}
   \def\BB:k{#5}
}
\def\scr:df#1{\edef\:temp{\ifx\:temp\empty \else \:temp,\fi #1}}
\def\first:only#1{
   \def\a:temp{#1}
   \expandafter\r:app\expandafter\also:second\arg:two,,/+/-]/[
   \ifx \a:temp\empty\else \edef\:temp{\:temp,#1}\fi
}
\def\also:second#1{\def\b:temp{#1}\ifx \a:temp\b:temp
   \let\a:temp\empty\fi}
\def\in:both#1{
   \def\a:temp{#1}
   \expandafter\r:app\expandafter\found:both\arg:two,,/+/-]/[
}
\def\found:both#1{\def\b:temp{#1}\ifx \a:temp\b:temp
   \edef\:temp{\:temp,#1}\fi}
\def\two:args#1,#2,{\futurelet\:temp\first:arg}
\def\first:arg#1,{\verify:arg{#1}
   \edef\arg:one{\ifx \:temp\bgroup
                         #1\else \csname #1:mkls\endcsname \fi}
   \futurelet\:temp\second:arg}
\def\second:arg#1,#2/+/-]/[{\verify:arg{#1}
   \edef\arg:two{\ifx \:temp\bgroup
                         #1\else \csname #1:mkls\endcsname \fi}}
\def\one:args#1,#2,{\futurelet\:temp\second:arg}
\def\verify:arg#1{
   \ifx \:temp\bgroup\else
      \expandafter\ifx \csname #1:mkls\endcsname\relax
          \pwarn:{`#1'\space in\space \string\sapply?}
   \fi \fi}
\def\cln:res{
   \let\:temp=\empty   \car:dinality=0;
   \expandafter\expandafter\expandafter\r:app
   \expandafter\expandafter\expandafter\pre:dup
     \csname \result:lst :mkls\endcsname,,/+/-]/[%
   \expandafter\let\csname \result:lst :mkls\endcsname=\:temp
   \edef\breadth{\Val\car:dinality}
   \rs:trc{\immediate\write16{...[\result:lst]........\:temp}}
}
\IntVar\car:dinality
\def\scr:srt#1{
\expandafter\let\expandafter\:temp\expandafter\empty
  \expandafter\next:compare\:temp,,,/+/-]/[#1/+/-]/[
}
\def\next:compare#1,#2/+/-]/[#3/+/-]/[{
   \if :#1:
      \edef\:temp{\ifx\:temp\empty\else \:temp,\fi#3}
      \def\next:##1/+/-]/[##2/+/-]/[{}
   \else   \comp:r{#1}{#3}
      \ifnum \com:p>0
         \edef\:temp{\ifx\:temp\empty\else \:temp,\fi#3,#1}
         \def\next:##1,,##2/+/-]/[##3/+/-]/[{\edef
                 \:temp{\ifx\:temp\empty\else \:temp,\fi##1}}
      \else \edef\:temp{\ifx\:temp\empty\else \:temp,\fi#1}
          \if :#2:
             \edef\:temp{\ifx\:temp\empty\else \:temp,\fi#3}
             \def\next:##1/+/-]/[##2/+/-]/[{}
          \else
             \let\next:=\next:compare
   \fi\fi \fi
   \next: #2/+/-]/[#3/+/-]/[
}
\def\comp:r#1#2{
  \def\com:p{0}%
  \comp:re#1/+/-]/[#2/+/-]/[%
}
\def\comp:re#1#2/+/-]/[#3#4/+/-]/[{%
   \ifnum `#1<`#3\def\com:p{-1}\let\next:=\relax
   \else \ifnum `#1>`#3\def\com:p{1}\let\next:=\relax
   \else \def\next:{\comp:re#2/+/-]/[#4/+/-]/[}%
         \if !#2!\let\next:=\relax  \fi
         \if !#4!\let\next:=\relax  \fi
         \def\:tempa{#2}\def\:tempb{#4}%
         \ifx \:tempa\space
             \ifx \:tempb\:tempa \else \def\com:p{-1}\fi
             \let\next:=\relax
         \else\ifx \:tempb\space \def\com:p{1}\let\next:=\relax
         \fi\fi
   \fi\fi
   \next:
}
\def\rs:trc#1{}
\def\get:result#1{
   \let\:temp=\empty
   \expandafter\r:app\expandafter#1\arg:one,,/+/-]/[%
   \expandafter\let\csname \result:lst :mkls\endcsname=\:temp}
\def\scr:af#1{%
\expandafter\ifx \csname#1:succe\endcsname\relax\else
   \expandafter\expandafter\expandafter\r:app
   \expandafter\expandafter\expandafter\scr:aff
   \csname #1:succe\endcsname,/+/-]/[
\fi}
\def\scr:aff#1{\edef\:temp{\:temp,#1}}
\def\scr:up#1{%
\expandafter\ifx \csname#1:ancs\endcsname\relax\else
  \expandafter\expandafter\expandafter\r:app
  \expandafter\expandafter\expandafter\scr:aff
  \csname #1:ancs\endcsname,/+/-]/[
\fi}
\def\scr:dw#1{\expandafter\ifx \csname #1:under\endcsname\relax\else
   \edef\:temp{\:temp,\csname #1:under\endcsname}\fi}
\def\scr:be#1{\expandafter\ifx \csname #1:prev\endcsname\relax\else
   \edef\:temp{\:temp,\csname #1:prev\endcsname}\fi}
\def\pre:dup#1{%
   \def\a:temp{#1}\let\c:temp=\empty
   \expandafter\r:app\expandafter\is:dup\:temp,/+/-]/[%
   \ifx \c:temp\empty
      \car:dinality+1;
      \edef\:temp{\:temp\ifx \:temp\empty\else ,\fi#1}\fi}
\def\is:dup#1{\def\b:temp{#1}\ifx \a:temp\b:temp \let\c:temp=\b:temp\fi}
\def\r:app#1#2,#3/+/-]/[{%
   \if !#2!\else #1{#2}\fi
   \if !#3!\expandafter\r:gobble\else \expandafter\r:app\fi
   #1#3/+/-]/[}
\def\r:gobble#1/+/-]/[{}


  \def\prjc:VII#1#2#3#4#5#6#7{
   \gdef\all:prjc{}
   { \contributionsstyle{
      \expandafter \gdef \expandafter\all:prjc
          \expandafter{\all:prjc\add:contrib{##1}{#1}}
     }{}{}
     \contributions{#1}
    }
    \all:prjc
}
\def\gob:V#1#2#3#4#5{}
\def\f:cntr#1{\apply{#1,\gob:V,\findcontribution,\gob:V}}

\IntVar\cntr:N

\def\add:contrib#1#2{
   \let\N:EXT=\empty
   \def\findcontribution##1##2##3##4##5{
     \IF \EqText(##2,#1) \THEN
        \gdef\N:EXT{##1}
     \FI
   }
   \sapply{con.TRIB,\f:cntr}
   \ifx \N:EXT\empty
      \cntr:N+1;
      \sapply{\pc:id.\Val\cntr:N,defproject,{#2},#1,}
      \sapply{con.TRIB,merge,con.TRIB,{\pc:id.\Val\cntr:N}}
   \else
      \sapply{ts.k,down,{\N:EXT}}
      \sapply{ts.k,merge,ts.k,{#2}}
      \expandafter\let\csname\N:EXT :type\endcsname\relax
      \sapply{\N:EXT,defproject,ts.k,#1,}
   \fi
}
\def\contributorsproject#1#2#3#4{
  \push:macro\checkmemb:  \def\checkmemb:##1{}
  \cntr:N=0; \def\pc:id{#1}
  \sapply{con.TRIB,merge,{},{}}
  \sapply{#1,defproject,{#3},,}
  \rapply{#1,\gob:V,\gob:V,\prjc:VII}
  \expandafter\let\csname#1 :type\endcsname\relax
  \sapply{#1,defproject,con.TRIB,#2,#4}
  \pop:macro\checkmemb:
  \sapply{#1,down,{#1}}
\sapply{#1,\connect:up{#1}}
\sapply{#1,merge,{},{}}

  \sapply{con.TRIB,merge,{},{}}
}

  \def\setnumericdate#1#2{{
   \expandafter \ifx \csname maxMM:\endcsname\relax
     \getminmaxdates:1/1/0//31/12/99//
   \fi
   \def\yrS:{0}  \def\moS:{0}  \def\dateS:{0}
   \if /\actual:date #2///+/-]/[/
       \date:Coordinate#1#2,,/+/-]/[
   \else
      \def\real::date##1,##2/+/-]/[{##1}
      \edef\real::date{\real::date #2,/+/-]/[}
      \axisdate:#1{real:}\empty
   \fi
   \edef#1{\def\noexpand#1{#1}}
   \expandafter}#1}

\def\actual:date#1/#2/#3/+/-]/[{#2}
\def\date:Coordinate#1#2,#3,#4/+/-]/[{
  \expandafter \ifx \csname#2 :type\endcsname\relax
      \def#1{0}
      \pwarn:{\noexpand\setnumericdate for\space `#2'?}
  \else\ifnum\csname#2 :type\endcsname=\milestonenode:\relax
      \axisdate:#1{#2}\empty
  \else
      \IF \EqText(start,#3) \THEN
        \axisdate:#1{#2}1
      \ELSE      \IF \EqText(finish,#3) \THEN
        \axisdate:#1{#2}2
      \ELSE
        \def#1{0}
        \pwarn:{\noexpand\setnumericdate for\space `#3'?}
      \FI \FI
   \fi \fi
}
\def\datesproject#1#2#3#4{
  \push:macro\checkmemb:   \def\checkmemb:##1{}   \def\pc:id{#1}
  \let\all:prjc=\empty
  \sapply{#1,defproject,{#3},,}
  \cntr:N=1000;
\bck:N=2;
\rapply{#1,\cnt:V,\cnt:V,\cnt:VII}
\bck:N*2;  \bck:N+1000;

  \rapply{#1,\prjd:V,\prjd:V,\prjd:VII}
  \edef\:temp{\noexpand \sapply{#1,sort,{\all:prjc}}}\:temp
  \let\all:prjc=\empty
  \sapply{#1.m,merge,{},{}}
  \let\prv:=\empty  \cntr:N=0;
  \push:macro\pwarn:   \def\pwarn:##1{}
  \sapply{#1,\set:dateprj}
  \sapply{#1,defproject,#1.m,#2,#4}
  \pop:macro\pwarn:
  \pop:macro\checkmemb:
  \sapply{#1,\cp:dt}

  \sapply{#1,down,{#1}}
\sapply{#1,\connect:up{#1}}
\sapply{#1,merge,{},{}}

  \sapply{#1.m,merge,{},{}}
}
\def\connect:up#1#2{\expandafter \edef \csname #2: ancs\endcsname{#1}}
\def\prjd:VII#1#2#3#4#5#6#7{\prjd:{#1}}
\def\prjd:V#1#2#3#4#5{\prjd:{#1}}
\def\prjd:#1{
  \cntr:N+1; \bck:N-1;
   {\datestyle{
      \setnumericdate\:dateA{#1,start}
\setnumericdate\:dateB{#1,finish}
\I:I=\:dateA; \I:I+1000000000; \edef\:dateA{\Val\I:I}
\I:I=\:dateB; \I:I+1000000000; \edef\:dateB{\Val\I:I}
\def\xx{#1}\ifx \xx\pc:id \else
  \xdef\all:prjc{\ifx \all:prjc\empty \else \all:prjc,\fi}
  \ifnum\csname#1 :type\endcsname=\milestonenode:\relax
     \xdef\all:prjc{\all:prjc \:dateA.\Val\cntr:N.0.#1}
  \else
     \xdef\all:prjc{\all:prjc \:dateA.\Val\cntr:N.1.#1,
            \:dateB.
            \ifnum\csname#1 :type\endcsname=\projectnode:\space
                     \Val\bck:N\else   \Val\cntr:N\fi
             .2.#1}
\fi \fi

      }{}{}
      \def\pwarn:##1{} \start{#1}
    }
}
\def\cp:dt#1{
   \def\:temp##1##2{##2}
   \edef\:tmp{\expandafter\expandafter\expandafter
        \:temp\csname#1 :under\endcsname}
   \ifnum\csname\:tmp :type\endcsname=\milestonenode:\relax
      \edef\:temp{\csname\:tmp :date\endcsname}
   \else
      \edef\:tempa{\noexpand\IF\noexpand\EqText(\csname#1
                                               :desc\endcsname,start)}
      \:tempa
          \edef\:temp{\csname\:tmp :date1\endcsname}
      \ELSE
          \edef\:temp{\csname\:tmp :date2\endcsname}
      \FI
   \fi
   \expandafter\let\csname#1 :date1\endcsname=\:temp
   \expandafter\let\csname#1 :date2\endcsname=\:temp
}
\IntVar\bck:N
\def\cnt:V#1#2#3#4#5{\bck:N+1;}
\def\cnt:VII#1#2#3#4#5#6#7{\bck:N+1;}

  \newif\iftrace: \trace:false
\def\traceon{\trace:true  }
\def\traceoff{\trace:false  }

\def\trace:#1{%
   \iftrace:
      \apply{#1,\traceM:,\traceP:,\traceT:}%
   \fi
}
\def\traceM:#1#2#3#4#5{%
   \immediate\write16{\string\defmilestone{#1}{#2}{#3}{#4}{#5}}}
\def\traceP:#1#2#3#4#5{%
   \immediate\write16{\string\defproject{#1}{#2}{#3}{#4}{#5}}}
\def\traceT:#1#2#3#4#5#6#7{%
   \immediate\write16{\string\deftask{#1}{#2}{#3}{#4}{#5}{#6}{#7}}}
\def\getlist:#1#2#3{
   \def\op:{#3}  \let#3=\relax
   \let~=\space  \let\temp:=\empty  \getlist::#2,,,/+/-]/[    \restoregal:
   \expandafter\let\csname#1\endcsname=\temp:
}
\def\getlist::#1,#2,#3/+/-]/[{
   \def\next:{#1}
   \ifx\next:\empty
      \def\temp::{#3} \ifx\temp::\empty\else  \missingiem:#3// \fi
   \else
      \edef\temp:{\temp: \op:{#1}}
      \def\next:{\getlist::#2,#3/+/-]/[} \expandafter\next:
   \fi
}
\def\missingiem:#1,,,//{
   \pwarn:{missing\space item\space in\space,,#1}
}
\def\setprev:#1#2{
  \def\temp:{#2}
  \ifx\temp:\empty    \expandafter\def\csname#1 :prev\endcsname{}
  \else
     \getlist:{#1 :prev}{#2}\prev:
     \def\prev:##1{\expandafter \edef \csname ##1: succe\endcsname
   {\expandafter \ifx \csname ##1: succe\endcsname\relax\else
    \csname ##1: succe\endcsname ,\fi#1}}
\csname#1: prev\endcsname

  \fi
}
\def\projectid:{0}
\def\setproject:#1#2{
  \traversedo:{#1}\setproject:data

  \def\temp:{#2}
  \ifx\temp:\empty\else  \def\temp:{\setproject:#2}   \fi
  \temp:
}
\def\verify:dates:#1#2{
  \traversedo:{#1}\checknodedates:

  \def\temp:{#2}
  \ifx\temp:\empty\else  \def\temp:{\verify:dates:#2}   \fi
  \temp:
}
\def\traversedo:#1#2{
  \def\utask:##1{
     \expandafter\let\csname##1 :sve\endcsname =\utask:
     \csname##1 :under\endcsname
     #2{##1}
     \def\utask:{\let\utask: =}
     \expandafter\utask:\csname##1 :sve\endcsname
  }
  \csname#1 :under\endcsname     #2{#1}
}
\def\checkmemb:#1{
   \expandafter\ifx\csname#1 :bool\endcsname\relax
      \pwarn:{definition\space for\space '#1'?}
   \fi
}
\def\utask:I#1{
  \ifnum\csname#1 :type\endcsname=\milestonenode:\relax
    \edef\temp:{\csname#1 :date\endcsname}
    \expandafter\maxDate:\temp:/
\else
    \edef\temp:{\csname#1 :date2\endcsname}
    \expandafter\maxDate:\temp:/
    \edef\temp:{\csname#1 :date1\endcsname}
\fi
\expandafter\minDate:\temp:/

}
\def\minDate:#1/#2/#3/{
   \ifnum #3<\minY:\relax      \def\minD:{#1} \def\minM:{#2} \def\minY:{#3}
   \else \ifnum #3=\minY:\relax
      \ifnum #2<\minM:         \def\minD:{#1} \def\minM:{#2}
      \else \ifnum #2=\minM:
         \ifnum #1<\minD:\relax\def\minD:{#1}     \fi
      \fi\fi
   \fi\fi }

\def\maxDate:#1/#2/#3/{
   \ifnum #3>\maxY:\relax      \def\maxD:{#1} \def\maxM:{#2} \def\maxY:{#3}
   \else \ifnum #3=\maxY:\relax
      \ifnum #2>\maxM:         \def\maxD:{#1} \def\maxM:{#2}
      \else \ifnum #2=\maxM:
         \ifnum #1>\maxD:\relax\def\maxD:{#1} \fi
      \fi\fi
   \fi\fi }
\def\getitems:#1#2{
  \def\items:{}   \let\item:=\relax
  \tcount:=#2 \relax     \advance\tcount: by -1\relax
  \let\utask:=\getchi:
  \csname#1 :under\endcsname
  \def\item:##1{    \expandafter\let\csname##1 :bool\endcsname=\UnDef: }
  \items:
}
\def\getchi:#1{
   \expandafter\ifx\csname#1 :bool\endcsname\relax
      \def\next:{  \edef\items:{ \item:{#1} \items: }  }
      \ifnum\csname#1 :type\endcsname=\projectnode:\space
         \ifnum 0<\tcount:
   \def\next:{
      \advance\tcount: by -1 \relax
      \csname#1 :under\endcsname  \relax
      \advance\tcount: by 1 \relax
   }
\fi

      \fi
      \expandafter\next:
   \fi
  }
\newcount\tcount:
\def\checknodedates:#1{
  \def\prev:##1{ \checkafter:{#1}{##1} }
  \csname#1 :prev\endcsname
}
\def\checkafter:#1#2{
   \getdate:\temp:A{#1}1
   \getdate:\temp:B{#2}2
   \edef\temp:{\temp:A/\temp:B/{`#1'\space starts\space
                              before\space `#2'\space ends}}
   \expandafter\checkdates:\temp:
}

\def\getdate:#1#2#3{
   \ifnum\csname#2 :type\endcsname=\milestonenode:\space
              \edef#1{\csname#2 :date\endcsname}
   \else      \edef#1{\csname#2 :date#3\endcsname}
   \fi
}

\def\checkdates:#1/#2/#3/#4/#5/#6/#7{
   \ifnum       #6>#3\space \pwarn:{#7}
   \else \ifnum #6=#3\space
      \ifnum       #5>#2\space \pwarn:{#7}
      \else \ifnum #5=#2\space
        \ifnum       #4>#1\space \pwarn:{#7} \fi
      \fi\fi
   \fi\fi   }
\def\listrsrc:#1{
  \ifnum\csname#1 :type\endcsname=\tasknode:\space
     \csname#1 :eff\endcsname
  \else
     \expandafter\expandafter  \csname#1 :under\endcsname
  \fi
}
\long\def\append:Def#1#2{%
   \def\:temp{\def#1}%
   \expandafter\expandafter\expandafter\:temp\expandafter{#1#2}}
\def\reseffI:#1#2{
   \expandafter\ifx\csname#1 :bool\endcsname\relax
      \sepitems: \append:Def\all:des{#1}
      \expandafter\let\csname#1 :bool\endcsname=\empty
   \fi
}
\def\effortout:{
  \I:I[\Q:Q];
  \IF \EqDec(\I:I,\Q:Q)  \THEN   \edef\temp:{\Val\I:I}
  \ELSE                      \edef\temp:{\Val\Q:Q}      \FI
}
\long\def\contr::#1#2#3{
  \def\contr:##1##2{  \ifnum 0<\tcount:\relax#3\fi #1#2 }
}
\def\contributionsstyle{  \contr::
}
\contributionsstyle{#1}{\space (#2)}{,\space}

\def\findeffort:#1#2{  \ifx#2\empty
  \def\reseff:##1##2{  \Q:Q + ##2; }
\else
  \def\reseff:##1##2{
     \def\temp:{##1}
     \ifx\temp:#2  \Q:Q + ##2;  \fi
  }
\fi
\Q:Q=0;
\ifnum\csname#1 :type\endcsname=\tasknode:\space
    \csname#1 :eff\endcsname
\else
    \getitems:{#1}{999}
    \def\item:##1{ \csname##1 :eff\endcsname }
    \items:
\fi
\effortout:
 }
\def\findthecontri:#1{\def\reseff:##1##2{
   \expandafter\ifx\csname##1 :bool\endcsname\relax
      \expandafter\def\csname##1 :bool\endcsname{##2}
      \edef\alls:{\alls: \all:{##1}}
   \else
      \Q:Q=\csname##1 :bool\endcsname;
      \Q:Q+##2;
      \expandafter\edef\csname##1 :bool\endcsname{\Val\Q:Q}
   \fi
}
\let\alls:=\empty \let\all:=\relax
\ifnum\csname#1 :type\endcsname=\tasknode:\space
   \csname#1 :eff\endcsname
\else
   \getitems:{#1}{999}
   \def\item:##1{ \ifx  \yrS:  \:UnDef  \csname##1 :eff\endcsname
\else
   \edef\svK:K{\Val\K:K}
   \axisdate:\temp:{##1}1 \ifnum \temp:<\dateA:\else
      \axisdate:\temp:{##1}2 \ifnum \temp:>\dateB:\else
         \csname##1 :eff\endcsname
   \fi\fi
   \K:K=\svK:K;
\fi
 }
   \items:
\fi
\tcount:=0
\def\all:##1{
  \Q:Q=\csname##1 :bool\endcsname;
  \contr:{##1}{{\effortout:\temp:}}    
  \tcount:=1
}
\alls:
}
\def\datestyle{\def\showdate:##1/##2/##3/##4//}
\datestyle{#1/#2/#3}
\def\apply:#1,#2,#3,#4,#5//{
   \verify:{#1}    \def\verify:##1{}
   \extract:
   \def\mop:{#2}  \def\pop:{#3}  \def\top:{#4}
   \apply::{#1}
   \let\verify:=\verify::
}
\def\rapply:#1,#2,#3,#4,#5//{
   \verify:{#1}     \def\verify:##1{}
   \def\utask:##1{
     \def\mop:{#2}  \def\pop:{#3}  \def\top:{#4}
     \apply::{##1}
     \I:I=\depth;  \I:I+1;  \edef\depth{\Val\I:I}
     \ifnum\csname#1 :type\endcsname=\projectnode:\space
         \csname##1 :under\endcsname
     \fi
     \I:I=\depth;  \I:I-1;  \edef\depth{\Val\I:I}
   }
   \utask:{#1}   \let\verify:=\verify::
}

\def\depth{0}\def\apply::#1{
   \push:macro\utask:
\push:macro\contr:

   \extract:
   \let\temp:=\empty
   \ifnum \csname#1 :type\endcsname=\milestonenode:\space
      \ifx   \mop:\empty \else
   \edef\temp:{\expandafter\noexpand\mop:{#1}{\csname#1 :title\endcsname}{\csname#1 :date\endcsname}
{\expandafter\ifx\csname#1 :prev\endcsname\empty\else
   \pp:\csname#1 :prev\endcsname
 \fi}
{\expandafter\noexpand\csname#1 :desc\endcsname}
}
\fi

   \else
      \ifnum \csname#1 :type\endcsname=\projectnode:\space
         \ifx   \pop:\empty \else
   \edef\temp:{\expandafter\noexpand\pop:{#1}{\csname#1 :title\endcsname}{
\expandafter\ifx\csname#1 :under\endcsname\relax\else
   \pp:\csname#1 :under\endcsname
\fi}
{\expandafter\ifx\csname#1 :prev\endcsname\empty\else
    \pp:\csname#1 :prev\endcsname
\fi}{\expandafter\noexpand\csname#1 :desc\endcsname}
}
\fi

      \else
         \ifx   \top:\empty \else
   \edef\temp:{\expandafter\noexpand
      \top:{#1}{\csname#1 :title\endcsname}
{\csname#1 :date1\endcsname}
{\csname#1 :date2\endcsname}
{\expandafter\ifx\csname#1 :eff\endcsname\relax\else
   \pp:\csname#1 :eff\endcsname
\fi}
{\expandafter\ifx\csname#1 :prev\endcsname\empty\else
   \pp:\csname#1 :prev\endcsname
\fi}{\expandafter\noexpand\csname#1 :desc\endcsname}
}
\fi

      \fi
   \fi
   \temp:
   \pop:macro\contr:
\pop:macro\utask:

}
\def\extract:{
   \def\pp:{\expandafter\expandafter\expandafter\expandafter\expandafter
            \expandafter\expandafter\ppp:}
   \def\ppp:##1,{}
   \def\prev:##1{,##1}
   \def\utask:##1{,##1}
   \edef\reseff:##1##2{,##1\string :##2}
}
\def\push:macro#1{
   \expandafter\let\csname appl:\Val\s:appN\endcsname#1
   \s:appN+1;
}
\def\pop:macro#1{
   \s:appN-1;
   \expandafter\let\expandafter#1\csname appl:\Val\s:appN\endcsname
}
\def\set:dateprj#1{\set:dtpr#1,}
\def\set:dtpr#1.#2.#3.#4,{
  \I:I=#1; \I:I-1000000000;
  \edef\:temp{\noexpand \sapply{\pc:id.#4\ifcase#3\space\else .#3\fi
       ,defproject,{#4},\Val\I:I,
        \ifcase#3\space \or start\or finish\else \fi}}   \:temp
  \ifx \prv:\empty \else
    \expandafter\edef\csname \pc:id.#4\ifcase#3\space\else .#3\fi
         :prev\endcsname {\noexpand \prev:{\pc:id.\prv:}}
    \expandafter\edef\csname  \pc:id.\prv: :succe\endcsname
         {\pc:id.#4\ifcase#3\space\else .#3\fi}
  \fi
  \edef\prv:{#4\ifcase#3\space\else .#3\fi}
  \edef\all:prjc{\ifx \all:prjc\empty\else \all:prjc,\fi
         \pc:id.#4\ifcase#3\space\else .#3\fi}
  \edef\:temp{\noexpand \sapply{\pc:id.m,merge,
         \pc:id.m,{\pc:id.#4\ifcase#3\space\else .#3\fi}}} \:temp
}
\def\gettree:{
   \let\nextrow:=\empty     \J:J=0;  \row:     \edef\tree:{ \tree: // }
   \ifx\nextrow:\empty \else
      \let\row:=\nextrow:  \K:K-1;
      \expandafter\gettree:
   \fi
}
\def\getnode:#1{
  \I:I=0;  \J:J+1;
  \ifnum\csname#1 :type\endcsname=\projectnode:\space
     \expandafter\expandafter \csname#1 :under\endcsname
  \fi
  \expandafter\ifx\csname#1 :bool\endcsname\relax
   \expandafter\let\csname#1 :bool\endcsname=\empty
\else
   \advance\tcount: by 1\space
   \expandafter\edef\csname##1 :id\endcsname{\the\tcount:}
\fi

  \edef\tree:{  \tree:
     \ifnum\Val\J:J>1\empty~ \fi
     \Val\I:I, \csname#1 :type\endcsname, {\treetext:{#1}}
     \nodeid:{#1}
  }
}
\:DefineExt\treestyle(5){\endgroup
   \def\temp:{#1} \ifx\temp:\empty\else   \let\project:node=#1         \fi
   \def\temp:{#2} \ifx\temp:\empty\else   \let\milestone:node=#2       \fi
   \def\temp:{#3} \ifx\temp:\empty\else   \let\task:node=#3            \fi
   \def\temp:{#4} \ifx\temp:\empty\else   \let\project:edge=#4         \fi
   \def\temp:{#5} \ifx\temp:\empty\else   \def\treenodewidth:{#5pt}    \fi
}
\treestyle(\VRectNode, \RectNode, \SRectNode,\TreeEdge,70)
\def\getparms:#1,#2,#3,#4,#5,#6,#7,#8,#9//{
   \def\first:{#1}   \def\second:{#2}     \def\third:{#3}
   \def\fourth:{#4}  \def\fifth:{#5}      \def\sixth:{#6}
   \def\seventh:{#7} \def\eighth:{#8}            }
\def\axisdate:#1#2#3{
   \breakdate:\DD:\MM:\YY:{#2}#3
   \K:K=\YY:;  \IF \LtInt(\K:K,\yrS:) \THEN \K:K+\maxYY:;  \FI
   \K:K*\maxMM:;  \K:K+\MM:;
   \IF \EqInt(\maxYY:,0)  \THEN
      \IF \LtInt(\K:K,\moS:) \THEN \K:K+\maxMM:;  \FI
   \FI
   \K:K*\maxDD:;  \K:K+\DD:;
   \K:K-\dateS:; \edef#1{\Val\K:K}
}
\def\breakdate:#1#2#3#4#5{
  \expandafter\ifx \csname#4 :date#5\endcsname\relax
     \pwarn:{Dates\space not\space available\space for\space #4}
  \else
     \def\temp:##1/##2/##3/{\def#1{##1}\def#2{##2}\def#3{##3}}
     \expandafter\expandafter
         \expandafter\temp:\csname#4 :date#5\endcsname/
  \fi
}

\def\titletext:#1{
  \Text(--\titletextA:{#1}--)
}

\def\titletextA:#1{\ifdim\nodewidth:>0in
    \vbox\bgroup  \hsize=\nodewidth:
    \leftskip     0pt plus 0.5\hsize
    \rightskip    0pt plus 0.5\hsize
    \parfillskip  0pt                   \fi
    #1                 \ifdim\nodewidth:>0in
         \egroup                         \fi}
\def\treenodestyle{\def\treetext:##1}
\treenodestyle{\csname#1 :title\endcsname}
\def\last:segdraw#1{
   \ifnum \effort:n>1
     \I:I=\effort:n;    \I:I-1; \edef\effort:n{\Val\I:I}
     \I:I=\effort:from; \I:I+\effort:step; \edef\effort:from{\Val\I:I}
     \I:I=\effort:to; \I:I+\effort:step;  \edef\effort:to{\Val\I:I}
     \ifnum \effort:max < \effort:to \let\effort:to=\effort:max \fi
     \expandafter\expandafter\expandafter#1
   \fi
}
\def\doelements:#1{%
   \ifx\fifth:\empty  \def\fifth:{1}\fi
   \IF \EqInt(\fifth:,0)\THEN      \chartelement:{#1}%
   \ELSE       \rapply{#1,\milestonechild:,\projectchild:,\taskchild:}\FI}

\def\milestonechild:#1#2#3#4#5{\child:{#1}}
\def\taskchild:#1#2#3#4#5#6#7{\child:{#1}}
\def\projectchild:#1#2#3#4#5{\IF \EqInt(\depth,\fifth:)\THEN
   \chartelement:{#1}\FI}

\def\child:#1{\IF \GtInt(\depth,\fifth:)\ELSE
   \chartelement:{#1}\FI }
\def\getscale:#1{
   \def\scale:{1}
   \K:K=#1;
   \Do(0,4){ \IF \GtInt(\K:K,1000) \K:K/10;  \edef\scale:{\scale:0}  \FI }
   \R:R=200;    \R:R/\K:K;  \R:R*\:Cons\:Xunits;  \Scale(\Val\R:R,4)
}
\defcom{MINMAXDATES:}#1{
   \expandafter\edef\csname\projectid: :minmax\endcsname{
       \noexpand \getminmaxdates:#1//}
  }
\def\getminmaxdates:#1/#2/#3//#4/#5/#6//{
   \I:I=#4;  \I:I-#1;  \I:I+1;  \edef\maxDD:{\Val\I:I}
   \I:I=#5;  \I:I-#2;  \I:I+1;  \edef\maxMM:{\Val\I:I}
   \I:I=#6;  \I:I-#3;  \I:I+1;  \edef\maxYY:{\Val\I:I}
}
\newif\ifpflag:
\def\cutprojectstasksA:#1{
   \axisdate:\dateA:{#1}1
   \axisdate:\dateB:{#1}2
   \ifnum   \dateB:<0\space        \pflag:false \fi
   \ifnum   \dateA:>\dateF:\space  \pflag:false \fi
   \ifnum   \dateA:<0\space        \def\dateA:{0} \fi
   \ifnum   \dateB:>\dateF:\space  \let\dateB:=\dateF: \fi
   \ifnum   \optt:=\csname#1 :type\endcsname\space   \pflag:false \fi
   \ifnum   \optp:=\csname#1 :type\endcsname\space   \pflag:false \fi
}
\Define\ignoredepth:{
   \let\sv:AddBarDepth=\:AddBarDepth
   \Define\:AddBarDepth(2){\let\:AddBarDepth=\sv:AddBarDepth }
}
\def\movemilestonesym:#1,#2//{\Q:Q=#1;\Q:Q-#2; \Q:Q/2;
   \Move(0,\Val\Q:Q) }
\def\putbartext:{
  \if        E\bareff:     \efforts:(\Val\K:K,\Val\K:K){ \geteff: }
  \else  \if T\bartext:
     \K:K+1;   \names:Tbl:(\Val\K:K,\Val\K:K){ \getname: }
  \else  \let\bareff:=X
  \fi\fi
  \if X\bareff: \else
     \K:K+1;
     \let\nodewidth:=\scnodewidth:   \titletext:{\temp:}
     \MoveToExit(-1.1,1.1)  \MarkLoc(1-:)
     \MoveToExit(1.1,-1.1)  \MarkLoc(2-:)  \CSeg\Clip(2-:,1-:)
  \fi
}
\Define\getname:(1){ \def\temp:{#1} }
\Define\geteff:(1){\findeffort:{#1}\empty}
\def\datesaxis(#1)(#2){ \scheaxis:{#1}{#2}\dates:}
\def\nonamesaxis(#1)(#2){ \scheaxis:{#1}{#2}\nonames:}
\def\namesaxis(#1)(#2){{\let\TicText=\TicName::
    \scheaxis:{#1}{#2}\names: }}
\def\scheaxis:#1#2#3{ \def~{\noexpand&}
    \edef\temp:{\noexpand\Axis(#1)(#2,#3) } \temp: }
\TextPar\Define\TicName::(1){\IF \EqText(,#1) \THEN
   \ELSE      \let\nodewidth:=\scnodewidth:
   \titletext:{#1} \FI}
\:DefineExt\schedulestyle(7){\endgroup
   \def\baropt:##1##2##3##4//{
       \let\baropt:=\empty  \let\txtopt:=\UndDef:
       \baroptA:##1  \baroptA:##2  \baroptA:##3
      }
   \let\baropts:=\empty  \let\bartext:=x  \let\barIIID:=x
   \let\baraxis:=x       \let\bareff:=x
   \def\temp:{#1}   \ifx\temp:\empty\else   \baropt:#1......//     \fi
   \def\temp:{#2#3} \ifx\temp:\empty\else   \def\barloc:{#2,#3}    \fi
   \def\temp:{#4}   \ifx\temp:\empty\else   \def\projectcolor:{#4} \fi
   \def\temp:{#5}   \ifx\temp:\empty\else   \def\taskcolor:{#5}    \fi
   \def\temp:{#6}   \ifx\temp:\empty\else   \def\milestonesym:{#6} \fi
   \def\temp:{#7}   \ifx\temp:\empty\else   \def\scnodewidth:{#7pt} \fi
}
\:DefineExt\schedulelimits(1){\endgroup
   \schedulelimits:#1,,,//
}
\expandafter\long\expandafter\def\csname
    .:\string \schedulelimits\endcsname(#1){\endgroup
   \schedulelimits:#1,,,//
}
\long\def\schedulelimits:#1,#2,#3//{
   \def\temp:{#1}   \ifx\temp:\empty\else   \def\schedulelimit:{#1} \fi
   \def\temp:{#2}   \ifx\temp:\empty\else   \def\schedulecode:{#2}  \fi
}
\schedulelimits(10000,\par)
\def\baroptA:#1{
   \if#1T                               \let\bartext:=T  \fi
   \if#1A                               \let\baraxis:=A  \fi
   \if#1E            \let\bareff:=E     \let\baraxis:=A  \fi
   \if3#1  \let\barIID:=3    \edef\baropts:{\baropts: 3} \fi
}

\schedulestyle(A,2.5,7.5,3,0,$\otimes$,70)
\def\cutoffdates:{
   \def\yrS:{0}  \def\moS:{0}  \def\dateS:{0}
\ifx\second:\empty
   \axisdate:\dateS:{\first:}1
\else
   \let\:date:=\second:
   \axisdate:\dateS:{}:
\fi
\let\dyS:=\DD:   \let\moS:=\MM:   \let\yrS:=\YY:
\ifx\third:\empty
   \axisdate:\dateF:{\first:}2
\else
   \let\:date:=\third:
   \axisdate:\dateF:{}:
\fi
\let\dyF:=\DD:   \let\moF:=\MM:   \let\yrF:=\YY:

}
\def\cutofftypes:{
  \def\optm:{-1}   \def\optt:{-1}   \def\optp:{-1}
  \expandafter\cutofftypesA:\fourth:....//
}
\def\cutofftypesA:#1#2#3#4//{
   \chkop:#1  \chkop:#2  \chkop:#3
}
\def\chkop:#1{
   \if M#1 \let\optm:=\milestonenode:   \fi
   \if T#1 \let\optt:=\tasknode:        \fi
   \if P#1 \let\optp:=\projectnode:     \fi
}
\def\getint:#1.#2.#3//{ \K:K=#1; \def\frac:{0.#2} }
\def\utaskII:#1{
  \ifnum \csname#1 :type\endcsname=\milestonenode:\space \else
    \pflag:true
    \edef\svK:K{\Val\K:K}   \cutprojectstasks:{#1}    \K:K=\svK:K;
    \ifpflag:   \ifnum \csname#1 :type\endcsname=\projectnode:\space
       \J:J=0; \contributionsstyle{}{}{}  \findthecontri:{#1}
\def\all:##1{ \reseffII:{##1}{\csname##1 :bool\endcsname}
              \expandafter\let\csname##1 :bool\endcsname=\:UnDef
 }
\alls:

\else  \J:J=0;
\let\reseff:=\reseffII:
\csname#1 :eff\endcsname
       \fi
\R:R=\J:J;   \R:R/2;   \R:R+\K:K;   \K:K+\J:J;
\edef\names:{   \names:   \ifx\names:  \empty\else ~ \fi
                \Val\R:R,\csname#1 :title\endcsname    }
\edef\nonames:{ \nonames: \ifx\nonames:\empty\else ~ \fi
                 \Val\K:K,\relax
                  }
\edef\lastnames:{ \Val\K:K }

   \fi
  \fi
}
\def\reseffII:#1#2{  \J:J+1;
\IF \GtDec(#2,\maxeffort:) \edef\maxeffort:{#2} \fi
\edef\bars:{  #2,#1  \ifx\bars:\empty\else ~ \fi   \bars:  }
  }
\def\dec:dim#1{%
   \def~{\noexpand&} \edef\tmp:i{\bars:}
   \expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
   \Define\tmp:ii(1){} \I:I=0;  \tmp:i(0,999){\I:I+1; \tmp:ii}
   \edef\effort:max{\Val\I:I} \I:I+#1; \I:I-1;
   \I:I / #1;
   \edef\effort:n{\Val\I:I}  \J:J=\effort:max; \J:J/\effort:n;
   \I:I=\J:J; \I:I*\effort:n; \IF \LtInt(\I:I,\effort:max) \J:J+1;\FI
   \def\effort:from{1} \edef\effort:to{\Val\J:J}
   \let\effort:step=\effort:to
}
\def\cnd:starts#1{
   \aft:edraw

   \df:bfs

   \snd:bxo #1
   \global \expandafter\setbox
           \csname dra:bx\effort:n\endcsname=\hbox
}
\def\aft:edraw{
  \ifx \effort:boxes\:Undef
     \gdef\effort:boxes{\global\let\effort:boxes=\:Undef}
     \global\let\ef:EndDraw=\EndDraw
     \gdef\EndDraw{\ef:EndDraw \global\let\EndDraw=\:UnDef \effort:boxes }
  \fi
}
\def\df:bfs{
   \expandafter\ifx \csname dra:bx\effort:n\endcsname\relax
      \global\csname newbox\expandafter
          \endcsname \csname dra:bx\effort:n\endcsname \fi
}
\def\snd:bxo#1{
   \expandafter\ifx \csname right:mrk\endcsname\relax
   \tmp:dim=\:RBorder
   \advance\tmp:dim by -\:LBorder
\else
   \tmp:dim=\right:mrk pt \advance\tmp:dim by - \left:mrk pt
   \global\let\right:mrk\:UnDef
\fi

   \expandafter\tmp:toks\expandafter{\effort:boxes}
   \expandafter\expandafter\expandafter\tmp:toks
      \expandafter\expandafter\expandafter{\expandafter
      \the\expandafter\tmp:toks  #1}
   \xdef\effort:boxes{\the\tmp:toks \noexpand\Draw
   \noexpand\Text(--\noexpand  \hbox to\the\tmp:dim{
\hss

      \box \csname dra:bx\effort:n\endcsname
   }

   --)\noexpand\EndDraw }
}
\ifx \tmp:toks\:UnDef \csname newtoks\endcsname \tmp:toks \fi
\def\sv:forchart{
   \let\sv:bars=\bars:
   \let\sv:names=\names:
   \let\sv:nonames=\nonames:
   \let\gall:=~
}
\def\recall:forchart{
   \let\bars:=\sv:bars
   \let\names:=\sv:names
   \let\nonames:=\sv:nonames
   \let~=\gall:
}
\TextPar\Define\EffortBarText:(1){
   \MoveToLoc(BarBot)  \Move(5pt\du,0)
   \EntryExit(-1,0,0,0) \Text(--#1--)
     \MoveToExit(-1.1,1.1)  \MarkLoc(1-:)
     \MoveToExit(1.1,-1.1)  \MarkLoc(2-:)  \CSeg\Clip(2-:,1-:)
}
\:DefineExt\effortstyle(1){\endgroup\effortstyle:(#1,,,)}
\Define\effortstyle:(6){
   \def\baropt:##1##2##3##4//{
       \effortbaroptA:##1  \effortbaroptA:##2   \effortbaroptA:##3
      }
   \let\effortbaropts:=\empty     \let\effortbaraxis:=x
   \let\effortbartext:=x          \let\effortbarIIID:=x
   \def\temp:{#1}   \ifx\temp:\empty\else   \baropt:#1......//  \fi
   \def\temp:{#2#3} \ifx\temp:\empty\else   \def\effortbarloc:{#2,#3} \fi
   \def\temp:{#4}   \ifx\temp:\empty\else   \def\effortcolor:{#4}     \fi
   \def\temp:{#5}   \ifx\temp:\empty\else   \def\efftextwidth:{#5pt}  \fi
}
\:DefineExt\effortlimits(1){\endgroup
   \effortlimits:#1,,,//
}
\expandafter\long\expandafter\def\csname
    .:\string \effortlimits\endcsname(#1){\endgroup
   \effortlimits:#1,,,//
}
\long\def\effortlimits:#1,#2,#3//{
   \def\temp:{#1}   \ifx\temp:\empty\else   \def\effortlimit:{#1} \fi
   \def\temp:{#2}   \ifx\temp:\empty\else   \def\effortcode:{#2}  \fi
}
\effortlimits(10000,\par)
\def\effortbaroptA:#1{
   \if#1A  \let\effortbaraxis:=A                      \fi
   \if#1T  \let\effortbartext:=T                      \fi
   \if3#1  \let\effortbarIIID:=3
           \edef\effortbaropts:{\effortbaropts: 3}    \fi
}

\effortstyle(A,2.5,7.5,1,70)
\let\effortaxis=\datesaxis
\TextPar\Define\TicName:(1){ \IF \EqText(,#1) \THEN
                     \ELSE \let\nodewidth:=\efftextwidth:
                             \titletext:{#1} \FI}
\def\sort:{
  \let\sorted:=\empty
  \pflag:false
  \expandafter\sortA:\dates:{}
  \let\dates:=\sorted:
  \ifpflag: \expandafter\sort: \fi}
\def\sortA:#1#2{
  \def\temp:{#2}
  \ifx\temp:\empty  \edef\sorted:{\sorted: {#1}}   \let\next:=\relax
  \else
     \ifnum #1>#2\space
         \pflag:true
         \edef\sorted:{\sorted: {#2}}   \def\next:{\sortA:{#1}}
     \else
         \edef\sorted:{\sorted: {#1}}   \def\next:{\sortA:{#2}}
     \fi
  \fi
  \next:
}
\def\indexIII:#1{
   \Q:Q = 0;  \I:I = 0;
   \csname#1 :prev\endcsname
   \IF  \GtInt(\I:I,0)  \THEN  \Q:Q / \I:I;  \FI
   \def\entry:{#1}  \let\next:=\empty
   \expandafter\addtocurrow:\currow:{}{}
}
\def\prevI:#1{
  \expandafter\ifx\csname#1  : in/cl: \endcsname\relax \else
     \Q:Q + \csname#1  : in/cl: \endcsname;
     \I:I + 1;
  \fi
}
\def\addtocurrow:#1#2{
   \def\temp:{#1}
   \ifx\temp:\empty
      \edef\next:{\next:{\Val\Q:Q}{\entry:}}   \let\currow:=\next:
   \else
      \IF \GtDec(#1,\Q:Q)  \THEN
         \edef\next:{\next:{\Val\Q:Q}{\entry:}}
         \Q=#1; \def\entry:{#2}
      \ELSE
         \edef\next:{\next:{#1}{#2}}
      \FI
      \expandafter\addtocurrow:
   \fi    }
\def\inserttocol:#1#2{
   \def\temp:{#1}  \ifx\temp:\empty  \else
      \expandafter\edef\csname \the\tcount: :nodes\endcsname{
         \csname\the\tcount: :nodes\endcsname
         \node:{#2} }
      \expandafter\edef\csname#2  : in/cl: \endcsname{\the\tcount:}
      \advance\tcount: by 1\relax
      \expandafter\inserttocol:
   \fi
}
\def\pertnodestyle{\def\perttext:##1}
\pertnodestyle{\csname#1 :title\endcsname}
\def\subsort:{
   \pflag:false
   \expandafter\subsortA:\elms:{}
   \ifpflag:  \expandafter\subsort: \fi
}

\def\subsortA:#1{
   \def\cur:{#1}
   \ifx\cur:\empty      \else
      \csname#1 :prev\endcsname
      \expandafter\subsortA:
   \fi
}

\def\compr:#1{
   \def\temp:{#1}
   \ifx\temp:\bef:
      \I:I=\csname#1 :boolA\endcsname;  \I:I+1;
      \IF  \GtInt(\I:I,\csname\cur: :boolA\endcsname) \THEN
          \pflag:true
          \expandafter\edef\csname\cur: :boolA\endcsname{\Val\I:I}
          \IF \GtInt(\I:I,\maxsub:) \THEN  \edef\maxsub:{\Val\I:I}  \FI
      \FI
   \fi
   \ifx\temp:\empty\else  \expandafter\compr:\fi
}
\def\indexII:#1{
   \ifnum\csname#1 :boolA\endcsname=\DoReg
         \I:I=\csname#1 : in/cl:\endcsname;
   \CSeg\:GetXY(origin:,col.\Val\I:I)
   \def\adjprt:{0}
\ifx\prtadjtbl:\empty\else
  \Define\searchadj:(2){ \IF \EqText(##1,#1) \THEN \def\adjprt:{##2}\FI}
  \prtadjtbl:(0,999){\searchadj:}
\fi

   \if H\hpert:
      \IF \LtDec(\Va,\T:T) \THEN \Va=\T:T; \FI
      \IF \LtDec(\R:R,\Va) \THEN \R:R=\Va; \FI
      \Vb+\adjprt:;

   \else
      \IF \GtDec(\Vb,\T:T) \THEN \Vb=\T:T; \FI
      \IF \GtDec(\R:R,\Vb) \THEN \R:R=\Vb; \FI
      \Va+\adjprt:;

   \fi
   \MoveTo(\Val\Va,\Val\Vb)
\seg:prt

\ifx \:tmp\def
  \if H\hpert:
   \IF \LtInt(\I:I,\u:pert) \THEN
     \sapply{up,merge,up,{#1}}

   \ELSE    \IF \GtInt(\I:I,\d:pert) \THEN
     \sapply{down,merge,down,{#1}}

   \ELSE    \IF \LtInt(\DoReg,\l:pert) \THEN
     \sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\sapply{left,merge,left,{#1}}

   \ELSE    \IF \GtInt(\DoReg,\r:pert) \THEN
     \MarkLoc(here)  \CSeg\:GetY(col.maxY,here)
\IF  \LtDec(\Vb,0)  \THEN \MarkLoc(col.maxY) \FI
\CSeg\:GetX(col.maxX,here)
\IF  \LtDec(\Va,0)  \THEN
   \CSeg\:GetX(origin:,here)
   \Va/\node:wh;  \Va+\l:pert; \Va-1;
   \IF \LtDec(\Va,\r:pert)  \Va=-1; \FI
\FI
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\IF \LtDec(\Va,0)  \THEN
   \Va=-1;
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\IF \LtDec(\Va,0) \THEN
   \IF \GtInt(\DoReg,\r:pert) \THEN \ELSE
   \MarkLoc(.) \CSeg\:GetX(origin:,.)
   \Va/\node:wh; \Va/\step:right;
% \immediate\write16{..(\the\DoReg,\Val\I:I).......\Val\Vb....\step:down}
   \IF \GtDec(\Va,1.3) \THEN
      \gdef\overflow:col{Y}
   \ELSE
       \Va=-1;
   \FI
\FI

\FI
\IF \LtDec(\Va,0) \THEN
  \MarkLoc(before)  \PutNode(#1)   \MarkLoc(here)
\CSeg\:GetX(before,here)
\IF  \LtDec(\Va,\node:wh)  \THEN
   \edef\node:wh{\Val\Va}
\FI
\sapply{in,merge,in,{#1}}

  \Move(\openpertH:,-\adjprt:)
\ELSE
  \sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\sapply{left,merge,left,{#1}}

\FI

\ELSE
   \sapply{right,merge,right,{#1}}
\FI

   \ELSE  \Va=-1;
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\IF \LtDec(\Va,0) \THEN
   \IF \GtInt(\DoReg,\r:pert) \THEN \ELSE
   \MarkLoc(.) \CSeg\:GetX(origin:,.)
   \Va/\node:wh; \Va/\step:right;
% \immediate\write16{..(\the\DoReg,\Val\I:I).......\Val\Vb....\step:down}
   \IF \GtDec(\Va,1.3) \THEN
      \gdef\overflow:col{Y}
   \ELSE
       \Va=-1;
   \FI
\FI

\FI
\IF \LtDec(\Va,0) \THEN
  \MarkLoc(before)  \PutNode(#1)   \MarkLoc(here)
\CSeg\:GetX(before,here)
\IF  \LtDec(\Va,\node:wh)  \THEN
   \edef\node:wh{\Val\Va}
\FI
\sapply{in,merge,in,{#1}}

  \Move(\openpertH:,-\adjprt:)
\ELSE
  \sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\sapply{left,merge,left,{#1}}

\FI

   \FI \FI \FI \FI
\else
   \IF \LtInt(\I:I,\l:pert) \THEN
     \sapply{left,merge,left,{#1}}

   \ELSE    \IF \GtInt(\I:I,\r:pert) \THEN
     \sapply{right,merge,right,{#1}}

   \ELSE   \IF \LtInt(\DoReg,\u:pert) \THEN
     \sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\sapply{up,merge,up,{#1}}

   \ELSE    \IF \GtInt(\DoReg,\d:pert) \THEN
     \MarkLoc(here)  \CSeg\:GetY(here,col.maxY)
\IF  \LtDec(\Vb,0)  \THEN
   \CSeg\:GetY(here,origin:)
   \Vb/\node:wh;  \Vb+\u:pert; \Vb-1;
   \IF \LtDec(\Vb,\d:pert)  \Vb=-1; \FI
\FI
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Vb=1;\gob:I}
\IF \LtDec(\Vb,0)  \THEN
   \Va=-1;
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\IF \LtDec(\Va,0) \THEN
  \IF \GtInt(\DoReg,\d:pert) \THEN \ELSE
   \MarkLoc(.) \CSeg\:GetY(.,origin:)
   \Vb/\node:wh; \Vb/\step:down;
% \immediate\write16{..(\the\DoReg,\Val\I:I).......\Val\Vb....\step:down}
   \IF \GtDec(\Vb,1.2) \THEN
      \gdef\overflow:col{Y} \Va=1;
   \FI
\FI

\FI
\IF \LtDec(\Va,0) \THEN
  \MarkLoc(before)     \PutNode(#1)
\MarkLoc(here)
\CSeg\:GetY(here,before)
\IF  \LtDec(\Vb,\node:wh)  \THEN
   \edef\node:wh{\Val\Vb}
\FI
\CSeg\:GetY(here,col.maxY)
\IF  \GtDec(\Vb,0)  \THEN  \MarkLoc(col.maxY)  \FI
\sapply{in,merge,in,{#1}}

  \Move(-\adjprt:,-\openpertV:)
\ELSE
   \sapply{down,merge,down,{#1}}
\FI

\ELSE
   \sapply{down,merge,down,{#1}}

\FI

   \ELSE  \Va=-1;
\sapply{temp,intersect,done,{#1}}
\sapply{temp,\Va=1;\gob:I}
\IF \LtDec(\Va,0) \THEN
  \IF \GtInt(\DoReg,\d:pert) \THEN \ELSE
   \MarkLoc(.) \CSeg\:GetY(.,origin:)
   \Vb/\node:wh; \Vb/\step:down;
% \immediate\write16{..(\the\DoReg,\Val\I:I).......\Val\Vb....\step:down}
   \IF \GtDec(\Vb,1.2) \THEN
      \gdef\overflow:col{Y} \Va=1;
   \FI
\FI

\FI
\IF \LtDec(\Va,0) \THEN
  \MarkLoc(before)     \PutNode(#1)
\MarkLoc(here)
\CSeg\:GetY(here,before)
\IF  \LtDec(\Vb,\node:wh)  \THEN
   \edef\node:wh{\Val\Vb}
\FI
\CSeg\:GetY(here,col.maxY)
\IF  \GtDec(\Vb,0)  \THEN  \MarkLoc(col.maxY)  \FI
\sapply{in,merge,in,{#1}}

  \Move(-\adjprt:,-\openpertV:)
\ELSE
   \sapply{down,merge,down,{#1}}
\FI

   \FI \FI \FI \FI
\fi

\else
     \PutNode(#1)
   \if H\hpert:    \Move(\openpertH:,-\adjprt:)
   \else           \Move(-\adjprt:,-\openpertV:)  \fi

\fi
\MarkLoc(col.\Val\I:I)
\MoveToNode(#1,1,1)  \MarkLoc(.)
\CSeg\:GetX(col.maxX,.)
\IF  \GtDec(\Va,0)  \THEN    \MarkLoc(col.maxX)  \FI


   \fi
}
\Define\adjustpert(1){
   \def\prtadjtbl:{#1}
   \ifx\prtadjtbl:\empty \else  \Table\prtadjtbl:{#1}  \fi
}
\adjustpert()
\def\utaskIV:#1{ \def\cur:{#1}  \csname#1 :prev\endcsname }
\def\clipper:#1{
   \pflag:true
   \seg:prt

\ifx \:tmp\def  \pflag:false \fi
\sapply{temp,merge,in,left}
\sapply{temp,merge,right,temp}
\sapply{temp,merge,up,temp}
\sapply{temp,merge,down,temp}
\sapply{temp,intersect,temp,{#1}}
\sapply{temp,\pflag:true \gob:I}

   \ifpflag:
     \def\temp::{#1}
\ifx     \temp::\cur:   \pflag:false
\else\ifx\temp::\from:  \pflag:false
     \else       \MoveToLoc(\cur:)  \CSeg[0.5]\Move(\cur:,\from:)   \MarkLoc(:=center=:)
\CSeg\:GetXY(\cur:,:=center=:)
\IF  \LtDec(\Va,0)  \THEN  \Va=-\Va;  \FI      \edef\HH:{\Val\Va}
\IF  \LtDec(\Vb,0)  \THEN  \Vb=-\Vb;  \FI      \edef\VV:{\Val\Vb}

                 \MoveToNode(#1,0,-1) \MarkLoc(:=loc=:)
\CSeg\:GetY(:=center=:,:=loc=:)
\IF  \GtDec(\Vb,\VV:)  \THEN  \pflag:false   \ELSE
  \MoveToNode(#1,0,1) \MarkLoc(:=loc=:)
  \CSeg\:GetY(:=loc=:,:=center=:)
  \IF  \GtDec(\Vb,\VV:)  \THEN  \pflag:false  \ELSE
    \MoveToNode(#1,1,0) \MarkLoc(:=loc=:)
    \CSeg\:GetX(:=loc=:,:=center=:)
    \IF  \GtDec(\Va,\HH:)  \THEN  \pflag:false \ELSE
      \MoveToNode(#1,-1,0) \MarkLoc(:=loc=:)
      \CSeg\:GetX(:=center=:,:=loc=:)
      \IF  \GtDec(\Va,\HH:)  \THEN  \pflag:false  \FI
    \FI
  \FI
\FI

\fi  \fi

   \fi
   \ifpflag:
      \MoveToNode(#1,1,1)    \MarkLoc(b:)
      \MoveToNode(#1,-1,-1)  \MarkLoc(a:)  \CSeg\Clip(a:,b:)
   \fi
}
\:DefineExt\pertstyle(7){\endgroup
   \def\baropt:##1##2//{
       \pertoptA:##1
      }
   \let\hpert:=x
   \def\temp:{#1}   \ifx\temp:\empty\else   \baropt:#1......//    \fi
   \def\temp:{#2}   \ifx\temp:\empty\else   \def\openpertH:{#2}   \fi
   \def\temp:{#3}   \ifx\temp:\empty\else   \def\openpertV:{#3}   \fi
   \def\temp:{#4}   \ifx\temp:\empty\else   \let\MilestoneNode:=#4\fi
   \def\temp:{#5}   \ifx\temp:\empty\else   \let\ProjectNode:=#5  \fi
   \def\temp:{#6}   \ifx\temp:\empty\else   \let\TaskNode:=#6     \fi
   \def\temp:{#7}   \ifx\temp:\empty\else   \def\pertw:{#7pt}     \fi
}
\def\pertoptA:#1{
   \if#1H  \let\hpert:=H                         \fi
}

\pertstyle(,30,20,\RectNode,\VRectNode,\SRectNode,70)  

  \def\treediagram(#1){{ \getparms:#1,,,,,,,,,//
   \verify:{\first:}      \def\verify:##1{}
   \ifx\EndDraw\UnDef:
      \pwarn:{\string\treediagram\space not\space within\space
                              \string\Draw...\string\EndDraw}
   \fi
   \ifx\second:\empty  \def\second:{999} \fi    \K:K=\second:;
   \ifnum\csname\first: :type\endcsname=\projectnode:\space
   \else  \K:K=0; \fi
   \IF \EqInt(\K:K,0)  \THEN
      \ifnum\csname\first: type\endcsname=\projectnode:\space
          \let\temp:=\projectnode
\else
   \ifnum\csname\first: type\endcsname=\tasknode:\space
          \let\temp:=\tasknode
   \else  \let\temp:=\milestonenode
   \fi
\fi
\temp:()(--{\treetext:{\first:}}--)

   \ELSE
     \tcount: = 0   \let\nodeid: = \relax

\let\node:=\getnode:
\def\row:{ \node:{\first:} }
\let~=\relax
\let\tree:=\empty
\def\utask:##1{
     \IF \GtInt(\K:K,0) \THEN
        \I:I+1;
        \let\node:=\relax
        \edef\nextrow:{ \nextrow: \node:{##1} }
        \let\node:=\getnode:
     \FI
 }

     \TextNode(1){  \titletext:{##1}  }
\let\nodewidth:=\treenodewidth:
\def\temp:{\noexpand&}
\edef\temp:{
  \noexpand\TreeSpec
         (\projectnode:  ,\noexpand\project:node   \temp:
          \tasknode:     ,\noexpand\task:node      \temp:
          \milestonenode:,\noexpand
                            \milestone:node)()(\noexpand\project:edge)
}   \temp:

     \gettree:   \def~{\noexpand&}
     \def\nodeid:##1{
   \expandafter\ifx\csname##1 :id\endcsname\relax \else
      ${}^{\csname##1 :id\endcsname}$
   \fi  }

     \edef~{\noexpand\Tree()(\tree:)}  ~
   \FI     
}}

\def\schedulechart(#1){    \getparms:#1,,,,,,,,,//
  \verify:{\first:}     \def\verify:##1{}
  \def\efforts:##1{}

  \let\gal:=~
  \let~=\relax
  \let\cutprojectstasks:=\cutprojectstasksA:
  \cutoffdates:   \getscale:\dateF:
  \I:I=\K:K;
\IF  \LtInt(\I:I,3)  \THEN   \I:I=3;
\ELSE
  \I:I=\yrF:;  \I:I-\yrS:;   \IF  \LtInt(\I:I,0)  \I:I+\maxYY:;  \FI
  \IF  \LtInt(\I:I,2)  \THEN
    \I:I*\maxMM:;  \I:I+\moF:;  \I:I-\moS:;
  \FI
\FI
\let\nodates:=\empty
\Do(1,\Val\I:I){ \edef\nodates:{\nodates: ~} }

\edef\dates:{\showdate:\dyS:/\moS:/\yrS:/0// \nodates:
             \showdate:\dyF:/\moF:/\yrF:/0//}

  \cutofftypes:
  \let\bars:=\empty    \let\names:=\empty    \let\nonames:=\empty
\def\chartelement:##1{ \pflag:true
\ifnum \csname##1 :type\endcsname=\milestonenode:\space
  \axisdate:\dateA:{##1}\empty
\I:I=\dateA:;   \def\temp:{-1} \J:J=0;    \K:K=0;
\ifnum   \dateA:<0\space                           \pflag:false \fi
\ifnum   \dateA:>\dateF:\space                     \pflag:false \fi
\ifnum   \optm:=\csname##1 :type\endcsname\space   \pflag:false \fi

\else
  \cutprojectstasks:{##1}
\def\temp:{0}
\ifnum \csname##1 :type\endcsname=\projectnode:\space
           \I:I=\dateA:;  \J:J=\dateB:;  \K:K=0;         \J:J-\I:I;
\else      \I:I=\dateA:;  \J:J=0;        \K:K=\dateB:;   \K:K-\I:I;
\fi

\fi
\I:I/\scale:;  \J:J/\scale:;    \K:K/\scale:;
\ifpflag:
  \edef\bars:{ \bars:  \ifx\bars:\empty\else ~ \fi
               \Val\I:I,\temp:,\Val\J:J,\Val\K:K  }
  \edef\names:{ ~  \csname##1 :title\endcsname   ~  \names:}
\edef\nonames:{\nonames:~}
\edef\efforts:{\efforts: ~ ##1 }

\fi
  }
\doelements:{\first:}

  \Define\DrawBar(2){
\IF  \GtInt(\J:J,0)  \THEN
  \IF \EqInt(\J:J,1)  \THEN
    \IF \EqInt(##1,-1)  \THEN
       \EntryExit(0,0,0,0)  \expandafter\movemilestonesym:\barloc://
       \Text(--\milestonesym:--)
       \MoveToExit(0,1) \Move(0,5pt\du)    \EntryExit(0,-1,0,0)  \putbartext:

       \ignoredepth:
    \FI
  \ELSE
    \IF \GtDec(##1,0)  \THEN
       \MarkLoc(o)    \R:R=##1;   \R:R/2;  \Q:Q=##2;  \Q:Q/2;
\Move(\Val\R:R,\Val\Q:Q)
\EntryExit(0,0,0,0)  \putbartext:  \MoveToLoc(o)

       \DrawRect(##1,##2)
    \FI
  \FI
\ELSE \ignoredepth: \FI
\J:J+1;  \IF  \EqInt(\J:J,4)  \THEN  \J:J=0;  \FI
}
\edef\temp:{\noexpand\BarChartSpec(HS\baropts:,\barloc: \noexpand &
          \barloc:  \noexpand & \barloc:  \noexpand & \barloc:)
      (0 \noexpand& 0 \noexpand& \projectcolor: \noexpand& \taskcolor:)}
\temp:

  \let~=\gal:
  \sv:forchart

  \ifnum \schedulelimit:=10000 \else
     \ifnum \schedulelimit:=10000 \else
   \def~{\noexpand&}   \edef\tmp:i{\bars:}  \let~=\relax
   \expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
   \def\maxeffort:{0}
   \Define\tmp:ii(4){
     \K:K=##1; \K:K+##4;
     \IF \GtInt(\K:K,\maxeffort:) \THEN \edef\maxeffort:{\Val\K:K}\FI
   }
   \tmp:i(0,999){\tmp:ii}
\fi

     \dec:dim\schedulelimit:

  \fi
  \put:schedulechart
  \let~=\gal:
  \let\verify:=\verify::
}
\Define\put:schedulechart{
   \ifnum \schedulelimit:=10000 \else
     \I:I=\effort:from;  \J:J=\effort:to;  \let~=\relax
\I:I-1; \J:J-1;
\def~{\noexpand&}   \edef\tmp:i{\bars:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\bars:=\empty
\Define\tmp:ii(1){\edef\bars:{\ifx\bars:\empty\else\bars:~\fi##1}}
\tmp:i(\Val\I:I,\Val\J:J){\tmp:ii}

     \def~{\noexpand&}   \edef\tmp:i{\names:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\names:=\empty
\Define\tmp:ii(1){
   \IF \GtDec(\K:K,\min:sg) \THEN
   \IF \LtDec(\K:K,\max:sg) \THEN
      \edef\names:{\names:~ ##1}
   \FI \FI
   \K:K+1;
}
\K:K=\effort:max; \K:K-\effort:to;  \K:K*2;   \edef\min:sg{\Val\K:K}
\K:K=\effort:max; \K:K-\effort:from; \K:K+1;
               \K:K*2;  \K:K+1; \edef\max:sg{\Val\K:K}
\K:K=0;  \tmp:i(0,9999){\tmp:ii}

     \def~{\noexpand&}   \edef\tmp:i{\nonames:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\nonames:=\empty
\Define\tmp:ii(1){
   \IF \GtDec(\K:K,\min:sg) \THEN
   \IF \LtDec(\K:K,\max:sg) \THEN
      \edef\nonames:{\nonames:~##1}
   \FI \FI
   \K:K+1;
}
\K:K=\effort:from; \K:K-2; \edef\min:sg{\Val\K:K}
\K:K=\effort:to;            \edef\max:sg{\Val\K:K}
\K:K=0; \tmp:i(0,9999){\tmp:ii}

     \ifnum \effort:from>1
       \cnd:starts \schedulecode:
     \fi
     \bgroup
   \fi
   \def~{\noexpand&}      \pflag:true
\edef\temp:{ \noexpand\Table\noexpand\efforts:{ \efforts: }   }
\temp:
\if T\bartext:
   \edef\temp:{ \noexpand\Table\noexpand\names:Tbl:{ \names: }   }
   \temp:
   \let~=\relax
\Define\temp:(1){\edef\names:{##1~\names:}}
\let\names:=\empty
\names:Tbl:(0,99){\temp:}
\def~{\noexpand&}
\edef\temp:{ \noexpand\Table\noexpand\names:Tbl:{ \names: }   }
\temp:

\fi
   \J:J=0;  \K:K=0;
\edef\temp:{  \noexpand\BarChart( \bars: )  }             \temp:

   \ifnum \schedulelimit:=10000 \else
     \MoveToLoc(Origin) \Move(\maxeffort:,0)
\MarkLoc(NE)  \CSeg\Move(NW,SW)  \MarkLoc(SE)
\MoveToLoc(NE) \Text(----)


   \fi
   \let\nodewidth:=\scnodewidth:
\if A\baraxis:     \datesaxis(SW,NE)(S-1)

  \MoveToLoc(NE)  {\Text(--\phantom{\showdate:00/00/00/0//}--)
\MoveToExit(1,0) \Text(----)}


  \if T\bartext:   
  \else            \MoveToLoc(SW)  \Move(-5pt\du,0) \MarkLoc(sw:)
\MoveToLoc(NE)  \Move(5pt\du,0)  \MarkLoc(ne:)
\CSeg\DrawRect(ne:,sw:)
\namesaxis(sw:,ne:)(W-0)
\nonamesaxis(sw:,ne:)(W-1)
\MoveToLoc(ne:) {\Text(--\phantom{\showdate:00/00/00/0//}--)
\MoveToExit(1,0) \Text(----)}



  \fi
\fi

   \ifnum \schedulelimit:=10000 \else
   \egroup
     \recall:forchart

     \last:segdraw\put:schedulechart

   \fi
}

\def\effortchart(#1){   \getparms:#1,,,,,,,,,//
  \verify:{\first:}      \def\verify:##1{}
  \ifnum\csname\first: :type\endcsname= \milestonenode: \space
     \pwarn:{\string\effortchart{\first:}?\space `\first:'\space is
          \space a\space milestone}
  \else
     \let\gal:=~
     \let~=\relax
     \edef\temp:{\second:\third:\fourth:}
\ifx\temp:\empty        \def\cutprojectstasks:##1{}
\else       \cutoffdates:  \cutofftypes:
                        \let\cutprojectstasks:=\cutprojectstasksA:
\fi

     \let\bars:=\empty    \let\names:=\empty    \let\nonames:=\empty
\def\maxeffort:{0}   \K:K=0;
\let\chartelement:=\utaskII:
\doelements:{\first:}

     \IF \EqInt(\K:K,0)  \THEN
        \pwarn:{empty\space effort\space chart\space for\space `#1'}
     \ELSE
        \expandafter\getint:\maxeffort:.0.0//  \getscale:\K:K
        \IF \GtInt(\scale:,1) \THEN
  \def~{\noexpand&}
  \edef\temp:{\noexpand\Table\noexpand\temp:{\bars:}}
  \temp:
  \let~=\relax
  \def\bars:##1{}
  \Define\tempa:(2){ \Q:Q=##1;
     \Q:Q/\scale:;  \edef\bars:{\bars: ~ \Val\Q:Q,##2}  }
  \temp:(0,99){\tempa:}
\FI

        \let\BarText=\EffortBarText:

\edef\temp:{\noexpand\BarChartSpec( HT\effortbaropts: , \effortbarloc: )
                                  ( \effortcolor: ) }
\temp:
\if A\effortbaraxis:   \if 3\effortbarIIID:  \BarGrid(0,,)  \FI\FI


        \edef\dates:{\maxeffort:}
\expandafter\getint:\maxeffort:.0.0//
\I:I=\K:K;  \I:I/2;  \K:K-\I:I; \K:K-\I:I;
\Q:Q=\frac:;  \Q:Q+\K:K; \Q:Q/2;
\IF \EqDec(\Q:Q,0)
       \edef\dates:{0 ~ \Val\I:I        ~ \dates:}
\ELSE  \Q:Q*10; \J:J[\Q:Q]; \edef\dates:{0 ~ \Val\I:I.\Val\J:J ~ \dates:}
\FI

        \edef\names:{0,\lastnames:~\names:}
\edef\nonames:{0,\lastnames: ~0,\relax~ \nonames:}

        \sv:forchart

        \ifnum \effortlimit:=10000 \else
           \dec:dim\effortlimit:

        \fi
        \put:effortchart
     \FI
     \let~=\gal:
  \fi
  \let\verify:=\verify::
}
\Define\put:effortchart{
   \ifnum \effortlimit:=10000 \else
     \I:I=\effort:from;  \J:J=\effort:to;  \let~=\relax
\I:I-1; \J:J-1;
\def~{\noexpand&}   \edef\tmp:i{\bars:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\bars:=\empty
\Define\tmp:ii(1){\edef\bars:{\ifx\bars:\empty\else\bars:~\fi##1}}
\tmp:i(\Val\I:I,\Val\J:J){\tmp:ii}

     \def~{\noexpand&}   \edef\tmp:i{\names:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\names:=\empty
\Define\tmp:ii(2){
   \T:T=\effort:max; \T:T-##1;
   \IF \GtDec(\T:T,\I:I) \THEN
   \IF \GtDec(\T:T,\effort:to) \THEN\ELSE
      \T:T=##1; \T:T-\effort:max;  \T:T+\effort:to;
      \IF \EqDec(\T:T,0.0) \THEN \T:T=0.25; \FI
      \edef\names:{\ifx\names:\empty\else\names:~\fi \Val\T:T,##2}
   \FI \FI
}
\tmp:i(1,9999){\tmp:ii}
\K:K=\effort:to; \K:K-\I:I;
\edef\names:{0,\Val\K:K\ifx \names:\empty\else ~\names:\fi}

     \def~{\noexpand&}   \edef\tmp:i{\nonames:}  \let~=\relax
\expandafter\Table\expandafter\tmp:i\expandafter{\tmp:i}
\let\nonames:=\empty
\Define\tmp:ii(2){
   \T:T=\effort:max; \T:T-##1;
   \IF \LtDec(\T:T,\I:I) \THEN \ELSE
   \IF \GtDec(\T:T,\effort:to) \THEN\ELSE
      \T:T=##1; \T:T-\effort:max;  \T:T+\effort:to;
      \edef\nonames:{\ifx\nonames:\empty\else\nonames:~\fi \Val\T:T,##2}
   \FI \FI
}
\tmp:i(1,9999){\tmp:ii}
\K:K=\effort:to; \K:K-\I:I;
\edef\nonames:{0,\Val\K:K\ifx \nonames:\empty\else ~\nonames:\fi}

     \ifnum \effort:from>1
       \cnd:starts \effortcode:
     \fi
     \bgroup
   \fi
   \def~{\noexpand&}
\edef\temp:{  \noexpand\BarChart( \bars: )  }        \temp:

   \ifnum \effortlimit:=10000 \else
     \MoveToLoc(Origin) \Move(\maxeffort:,0)
\MarkLoc(NE)  \CSeg\Move(NW,SW)  \MarkLoc(SE)
\MoveToLoc(NE) \Text(----)


   \fi
   \if A\effortbaraxis:
  \MoveToLoc(NE)  \Move(5pt\du,0)  \MarkLoc(ne:)
  \if 3\effortbarIIID:
     {\CSeg\Line(ne:,NW) } \CSeg\Line(NW,SW)   \CSeg\Line(ne:,NW)
  \else       \CSeg\DrawRect(ne:,SW)   \fi
  \effortaxis(SW,NE)(S-1)
  \namesaxis(SW,NE)(W5)
  \nonamesaxis(SW,ne:)(W8)
  \ifnum \effortlimit:=10000 \else
     \nonamesaxis(SW,ne:)(W-6)

  \fi
  \MoveToLoc(ne:) \Text(----)

\fi

   \ifnum \effortlimit:=10000 \else
     \egroup
     \recall:forchart

     \last:segdraw\put:effortchart

   \fi
}
\def\pertdiagram{\futurelet\:temp\pertd:ag}
\def\pertd:ag{\ifx \:temp*
      \def\date:less{\def\dateA:{0}}
      \def\:temp##1{\pertdiagram:}
   \else
      \let\date:less=\empty
      \let\:temp=\pertdiagram:
  \fi
  \:temp}
\def\pertdiagram:(#1){    \getparms:#1,,,,,,,,,//
  \verify:{\first:}     \def\verify:##1{}
  \ifnum\csname\first: :type\endcsname= \projectnode: \space
     \let\gal:=~
     \let~=\relax
     \cutoffdates:
     \cutofftypes:
     \let\index:=\relax  \let\dates:=\empty
\def\utask:##1{
   \expandafter\def\csname##1 :bool\endcsname{0}
   \ifnum\csname##1 :type\endcsname=\milestonenode:\space
      \axisdate:\dateA:{##1}\empty
   \else
      \axisdate:\dateA:{##1}1
   \fi
   \date:less
   \expandafter\ifx\csname -\dateA:-:\endcsname\relax
      \edef\dates:{  \dates: {\dateA:} }
   \fi
   \expandafter\edef\csname -\dateA:-:\endcsname{
       \expandafter\ifx\csname -\dateA:-:\endcsname\relax  \else
          \csname -\dateA:-:\endcsname
       \fi
       \index:{##1} }
 }
\csname\first: :under\endcsname
\sort:
\def\prev:##1{
   \expandafter\ifx\csname##1 :bool\endcsname\relax
      
   \else
      \J:J=\csname##1 :bool\endcsname;  \J:J+1;
\IF  \GtInt(\J:J,\csname\cur: :bool\endcsname)  \THEN
   \pflag:true
   \expandafter\edef\csname\cur: :bool\endcsname{\Val\J:J}
\FI

   \fi  }
\def\utask:##1{
   \def\cur:{##1}
   \csname##1 :prev\endcsname   }
\def\setrows:{        \pflag:false
   \csname\first: :under\endcsname
   \ifpflag:
      \expandafter\setrows:
   \fi  }
\setrows:

     \J:J=-1;
\def\colsno:{0}  \expandafter\let\csname 0 :nodes\endcsname=\empty
\def\utask:##1{ \tcount:=\csname##1 :bool\endcsname\space
\expandafter\ifx\csname  col-:\the\tcount:\endcsname\relax
      \expandafter
  \def\csname  col-:\the\tcount: :+\endcsname{ \index:{##1} }

      \expandafter\def\csname  col-:\the\tcount:\endcsname{0}
      \tcount:=0\space  \J:J+1;
\else
      \expandafter\edef\csname  col-:\the\tcount: :+\endcsname{
   \csname  col-:\the\tcount: :+\endcsname \index:{##1} }

      \I:I=\csname  col-:\the\tcount:\endcsname;   \I:I+1;
      \expandafter\edef\csname  col-:\the\tcount:\endcsname{ \Val\I:I }
      \tcount:=\Val\I:I\space
      \ifnum \tcount:>\colsno:\space
   \expandafter\let\csname \the\tcount: :nodes\endcsname=\empty
   \edef\colsno:{\the\tcount:}
\fi

\fi
 }
\csname\first: :under\endcsname

\Do(0,\Val\J:J){
   \J:J=\colsno:;  \J:J-\csname  col-:\the\DoReg\endcsname;   \J:J/2;
   \let\node:=\relax
\let\currow:=\empty
\let\index:=\indexIII:
\let\prev:=\prevI:
\csname col-:\the\DoReg :+\endcsname

\tcount:=\Val\J:J
\expandafter\inserttocol:\currow:{}{}


}




     \let\nodewidth:=\pertw:   \MarkLoc(origin:)  \edef\rowsno:{0}
\sapply{all,merge,{},{}}
\def\node:##1{
  \IF \GtInt(\I:I,\rowsno:) \edef\rowsno:{\Val\I:I} \FI  \I:I+1;
  \ifnum\csname##1 :type\endcsname=\milestonenode:\space
       \let\PertNode:=\MilestoneNode:
\else
   \ifnum\csname##1 :type\endcsname=\projectnode:\space
       \let\PertNode:=\ProjectNode:
   \else
       \let\PertNode:=\TaskNode:
   \fi
\fi

\DefNode\PertNode:(##1)(--\titletextA:{\perttext:{##1}}--)
\sapply{all,merge,all,{##1}}

  \AddNodeDim(##1)
}
\sapply{MaxXYI,merge,{},{}}
\Do(0,\colsno:){
  \I:I=0;
  \ZeroNodesDim
  \csname \the\DoReg :nodes\endcsname
  \sapply{MaxXYI,merge,MaxXYI,{\if H\hpert:  \MaxY
                                     \else \MaxX\fi :\the\DoReg}}

}

     \def\l:pert{0}  \def\u:pert{0}
\if H\hpert:
   \grps:ns\step:right\colsno:\pert:cols
   \grps:ns\step:down\rowsno:\pert:rows
\else
   \grps:ns\step:right\colsno:\pert:cols
   \grps:ns\step:down\rowsno:\pert:rows
\fi
\I:I=\step:right;  \I:I-1; \edef\r:pert{\Val\I:I}
\I:I=\step:down;   \I:I-1; \edef\d:pert{\Val\I:I}
\sapply{in,merge,{},{}}
\sapply{done,merge,{},{}}
\def\overflow:col{N}
\MoveToLoc(origin:)  \MarkLoc(col.minX)    \MarkLoc(col.maxX)
\MarkLoc(col.maxY)  \edef\node:wh{1000}

     \def\:temp{    \def\effort:n{-1}  \pert:diag{#1}
 }
     \let~=\gal:
  \else    \pwarn:{\string\pertdiagram{\first:}?\space
                       not \space a \space project}
      \let\:temp\empty
  \fi
  \let\verify:=\verify::
  \:temp
}
\def\getnodesbydate:#1{
   \def\temp:{#1}
   \ifx \temp:\empty  \else
      \def\temp:{
         \let\index:=\indexI:
\Q:Q=0; \R:R=0;
\csname -#1-:\endcsname

         \let\elms:=\empty
\def\index:####1{
  \edef\elms:{\elms: {####1}}
  \expandafter\def\csname####1 :boolA\endcsname{0}
  }
\csname -#1-:\endcsname
\def\maxsub:{0}
\def\prev:####1{
   \def\bef:{####1}
   \expandafter\compr:\elms:{}
}
\subsort:

         \let\index:=\indexII:    \T:T=\prevstart:;
\Do(0,\maxsub:){
  \R:R=0;
  \csname -#1-:\endcsname
  \IF \GtDec(\R:R,\T:T)
     \T:T=\R:R;
     \if H\hpert:    \T:T+\openpertH:;  \else  \T:T-\openpertV:;  \fi
  \FI
}

         \getnodesbydate: }
      \expandafter\temp:
   \fi
}
\def\indexI:#1{
   \I:I=\csname#1 : in/cl:\endcsname;
   \CSeg\:GetXY(origin:,col.\Val\I:I)
   \if H\hpert:
     \IF \GtDec(\Va,\Q:Q)  \THEN  \Q:Q=\Va;  \FI
     \IF \GtDec(\prevstart:,\Q:Q)  \THEN  \Q:Q=\prevstart:;
     \Q:Q+\openpertH:;  \FI
   \else
     \IF \GtDec(\Q:Q,\Vb)  \THEN  \Q:Q=\Vb;  \FI
     \IF \GtDec(\Q:Q,\prevstart:)  \THEN  \Q:Q=\prevstart:;
         \Q:Q-\openpertV:;  \FI
   \fi
   \edef\prevstart:{\Val\Q:Q}
}
\def\pert:diag#1{
   \seg:prt

\ifx \:tmp\def
   \ifnum \effort:n>-1
      \sapply{prevdone,merge,done,{}}
      \global \expandafter\setbox
              \csname dra:bx\effort:n\endcsname=\hbox
   \fi
   \bgroup
\fi

   \def\MaxX##1{\MaxY##1/+/-]/[}
\def\MaxY##1:##2/+/-]/[{
   \def\:tmp####1{
   \ifnum \csname####1 : in/cl:\endcsname=##2
      \sapply{used,merge,used,{####1}}
   \fi
}
\sapply{used,merge,{},{}}
\sapply{all,\:tmp}
\sapply{used,subtract,used,done}
\let\:tmp=\relax
\sapply{used,\let\:tmp=\def\gob:I}

   \if H\hpert:
   \IF \LtInt(##2,\u:pert) \THEN           \let\:tmp=\relax
   \ELSE    \IF \GtInt(##2,\d:pert) \THEN  \let\:tmp=\relax
   \FI \FI
\else
   \IF \LtInt(##2,\l:pert) \THEN           \let\:tmp=\relax
   \ELSE    \IF \GtInt(##2,\r:pert) \THEN  \let\:tmp=\relax
   \FI \FI
\fi

   \ifx \:tmp\def
      \if H\hpert:
         \Move(0,-##1)   \MarkLoc(col.##2)     \Move(0,-##1)
         \Move(0,-\openpertV:)
      \else
         \Move(##1,0)    \MarkLoc(col.##2)     \Move(##1,0)
         \Move(\openpertH:,0)
      \fi
   \else \ifnum ##2>0
   \MarkLoc(.) \I:I=##2; \I:I-1; \MoveToLoc(col.\Val\I:I)
   \MarkLoc(col.##2)   \MoveToLoc(.)
\else  \MarkLoc(col.##2)  \fi
 \fi
}
\sapply{MaxXYI,\MaxX}

\sapply{in,merge,{},{}}
\sapply{up,merge,{},{}}
\sapply{down,merge,{},{}}
\sapply{left,merge,{},{}}
\sapply{right,merge,{},{}}
\let\M:N\empty
\let\M:X\empty

   \if H\hpert:  \EntryExit(-1,0,1,0)  \def\prevstart:{-10}
\else         \EntryExit(0,1,0,-1)  \def\prevstart:{10}   \fi
\expandafter\getnodesbydate:\dates:{}

   \sapply{edges,merge,{},{}}
\def\prev:##1{ \sapply{temp,intersect,in,{##1,\cur:}}
\sapply{temp,\sapply{edges,merge,edges,{##1,\cur:}}\gob:I}
 }
\let\utask:=\utaskIV:
\csname\first: :under\endcsname
\sapply{edges,subtract,edges,in}
\sapply{up,intersect,up,edges}
\sapply{down,intersect,down,edges}
\sapply{left,intersect,left,edges}
\sapply{right,intersect,right,edges}

\MoveToLoc(origin:) \Move(10,0) \MarkLoc(.)
\MoveToLoc(col.maxX) \Move(0,10) \MarkLoc(..)
\MoveToLL(origin:,.)(col.maxX,..)  \Move(0,5) \MarkLoc(col.maxX)
\MoveToLoc(col.minX)  \Move(0,5) \MarkLoc(col.minX)

\K:K=0;
\sapply{left,\K:K+1;\gob:I}  \J:J=\K:K;
\sapply{right,\K:K+1;\gob:I}
\sapply{down,\K:K+1;\gob:I}
\sapply{up,\K:K+1;\gob:I}
\CSeg\:GetY(col.maxY,origin:)  \Vb/\node:wh; \Vb*0.7;
\IF \GtDec(\Vb,\K:K)  \K:K*2;
   \IF \EqInt(\J:J,0) \K:K=-\K:K; \FI
\ELSE                 \K:K/2; \K:K-1; \FI

\sapply{up,\put:nd}
\sapply{left,\put:nd}
\sapply{right,\put:nd}
\sapply{down,\put:nd}

   \def\prev:##1{ \expandafter\ifx\csname##1 :bool\endcsname\relax
   
\else
   \def\from:{##1}
\let\utask:=\clipper:
\csname\first: :under\endcsname
\seg:prt

\ifx \:tmp\def
  \sapply{do,merge,{},{}}
\sapply{temp,intersect,in,{##1,\cur:}}
\sapply{temp,\sapply{do,merge,{##1},{}}\gob:I}
\sapply{do,\ifx\M:N\empty \edef\M:N{##1}\edef\M:X{##1}\fi
\def\:temp{
   \CSeg\:GetX(##1,\M:N)    \IF \GtDec(\Va,0) \edef\M:N{##1}\FI
   \CSeg\:GetX(\cur:,\M:N)  \IF \GtDec(\Va,0) \edef\M:N{\cur:}\FI
   \CSeg\:GetX(\M:X,##1)    \IF \GtDec(\Va,0) \edef\M:X{##1}\FI
   \CSeg\:GetX(\M:X,\cur:)  \IF \GtDec(\Va,0) \edef\M:X{\cur:}\FI
}
\:temp
{\Edge(##1,\cur:)}\gob:I}

\else
  \Edge(##1,\cur:)

\fi

\fi
\Clip()
\let\utask:=\utaskIV:
 }
\let\utask:=\utaskIV:
\csname\first: :under\endcsname

   \sapply{in,\extrm:in}
\ifx \M:N\empty\else
   \MoveToNode(\M:N,-1,0) \MarkLoc(.\M:N)
   \MoveToNode(\M:X,1,0) \MarkLoc(.\M:X)
   {\Text(----)}

   \CSeg\:GetX(origin:,.\M:N)  \xdef\left:mrk{\Val\Va}
   \CSeg\:GetX(origin:,.\M:X)  \xdef\right:mrk{\Val\Va}
\fi

   \seg:prt

\ifx \:tmp\def
      \sapply{done,merge,done,in}
\edef\:temp{\noexpand \sapply{done,merge,{\csname
       done:mkls\endcsname},{}}}
\expandafter

   \egroup \:temp
   \ifnum \effort:n>-1
   \sapply{leftover,subtract,done,prevdone}
   \let\:tmp=\relax
   \sapply{leftover,\let\:tmp=\def\gob:I}
   \ifx \:tmp\def
      \snd:bxo \pertcode:
   \else
      \global \expandafter\setbox
           \csname dra:bx\effort:n\endcsname=\hbox{}
      \I:I=\effort:n; \I:I-1; \edef\effort:n{\Val\I:I}
   \fi
\fi

   \sapply{leftover,subtract,all,done}
   \let\:tmp=\relax
   \sapply{leftover,\let\:tmp=\def\gob:I}
   \ifx \:tmp\def
     \I:I=\effort:n; \I:I+1; \edef\effort:n{\Val\I:I}
     \if Y\overflow:col
  \def\overflow:col{N}
\else
   \I:I=\r:pert; \I:I+1;           \edef\l:pert{\Val\I:I}
   \I:I=\r:pert; \I:I+\step:right; \edef\r:pert{\Val\I:I}
   \ifnum \l:pert >     \if H\hpert:  \rowsno:    \else   \colsno: \fi
      \I:I=\d:pert; \I:I+1;          \edef\u:pert{\Val\I:I}
      \I:I=\d:pert; \I:I+\step:down; \edef\d:pert{\Val\I:I}
      \def\l:pert{0}  \I:I=\step:right;  \I:I-1; \edef\r:pert{\Val\I:I}
   \fi
\fi
\if H\hpert: \else
   \I:I=\l:pert; \I:I+7;
   \Do(\l:pert,\Val\I:I){
     \def\:tmp####1{
   \ifnum \csname####1 : in/cl:\endcsname=\DoReg
      \sapply{used,merge,used,{####1}}
   \fi
}
\sapply{used,merge,{},{}}
\sapply{all,\:tmp}
\sapply{used,subtract,used,done}
\let\:tmp=\relax
\sapply{used,\let\:tmp=\def\gob:I}
\ifx \:tmp\relax
    \I:I=\r:pert; \I:I+1; \edef\r:pert{\Val\I:I}
\fi

   }
\fi


     \aft:edraw

\df:bfs


     \expandafter\expandafter\expandafter\pert:diag
   \else
     \expandafter\expandafter\expandafter\gob:I
   \fi
\else
   \expandafter\gob:I
\fi {#1}

}
\def\seg:prt{
   \let\:tmp=\def
   \ifnum \pert:rows=10000
     \ifnum \pert:cols=10000
        \let\:tmp=\relax
   \fi \fi
}
\def\grps:ns#1#2#3{{
  \ifnum #3>#2
      \I:I=#3; \I:I+1;
  \else
      \R=#2; \R+1;  \R/#3;  \R+0.49999;  \J:J[\R];
      \R=#2; \R+1;  \R/\J:J;   \I:I[\R];
  \fi
  \edef#1{\def\noexpand#1{\Val\I:I}}
  \expandafter}#1}
\def\put:nd#1{
   \let\sv:EntryExit\:InOut
   \IF \LtInt(\K:K,0)
      \EntryExit(-1,1,-1,-1)
\MoveToLoc(col.maxX)  \Move(\openpertH:,0)
\FcNode(#1) \pert:bnode(#1)
\MoveToExit(0,1) \MarkLoc(from)   \MoveToExit(0,-1) \MarkLoc(to)
\MoveToLoc(col.maxX)  \CSeg\Move(from,to)
\Move(0,-\openpertV:)  \MarkLoc(col.maxX)

   \ELSE
      \EntryExit(1,1,1,-1)
\MoveToLoc(col.minX)  \Move(-\openpertH:,0)
\FcNode(#1)  \pert:bnode(#1)
\MoveToExit(0,1) \MarkLoc(from)   \MoveToExit(0,-1) \MarkLoc(to)
\MoveToLoc(col.minX)  \CSeg\Move(from,to)
\Move(0,-\openpertV:)  \MarkLoc(col.minX)

   \FI
   \K:K-1;
   \let\:InOut\sv:EntryExit
}
\def\gob:I#1{}
\:DefineExt\pertlimits(1){\endgroup
   \pertlimits:#1,,,,,//
}
\expandafter\long\expandafter\def\csname
    .:\string \pertlimits\endcsname(#1){\endgroup
   \pertlimits:#1,,,,,//
}
\long\def\pertlimits:#1,#2,#3,#4,#5//{
   \def\temp:{#1}   \ifx\temp:\empty\else   \def\pert:rows{#1} \fi
   \def\temp:{#2}   \ifx\temp:\empty\else   \def\pert:cols{#2} \fi
   \def\temp:{#3}   \ifx\temp:\empty\else   \def\pert:bnode{#3}  \fi
   \def\temp:{#3}   \ifx\temp:\empty\else   \def\pertcode:{#4}  \fi
}
\pertlimits(10000,10000,\ExtNode,\par)
\Define\ExtNode(1){
   \filtercommand\name{#1}
   \OvalNode(#1)(--\putcommand--)}
\def\extrm:in#1{\ifx\M:N\empty \edef\M:N{#1}\edef\M:X{#1}\fi
\def\:temp{
   \CSeg\:GetX(#1,\M:N)  \IF \GtDec(\Va,0) \edef\M:N{#1}\FI
   \CSeg\:GetX(\M:X,#1)  \IF \GtDec(\Va,0) \edef\M:X{#1}\FI
}
\:temp
}
\expandafter \ifx  \csname tmp:dim\endcsname \relax
   \csname newdimen\endcsname \tmp:dim
\fi

               
\:RestoreCatcodes    \endinput



.
