% All macros commented                %  1
\newcommand{\paperpdf}{}              %  2
\newcommand{\papertex}{}              %  3
\newcommand{\projecttex}{}            %  4
\newcommand{\verifytex}{}             %  5
\newcommand{\initializetex}{}         %  6
\newcommand{\demoplottex}{}           %  7
\newcommand{\toolsperyear}{}          %  8
\newcommand{\tablethree}{}            %  9
\newcommand{\menkexlsx}{}             % 10
\newcommand{\inputsconf}{}            % 11
\newcommand{\downloadtex}{}           % 12
\newcommand{\formattex}{}             % 13
\newcommand{\demoyearconf}{}          % 14
\newcommand{\expandingproject}{}      % 15





%% Start the TiKZ picture environment.
\begin{tikzpicture}[
  line width=1.5pt,
  black!50,
  text=black,
]

  %% Use small fonts
  \footnotesize

  %% These white lines are only relevant when we want to add boxes in
  %% multiple figures (for example to build slides). They are used to fix
  %% the vertical position of the boxs in the figure so it doesn't change
  %% as we add more boxes.
  \draw [white] (-7.6,0) -- (7.5,0);
  \draw [white] (0,-4.5) -- (0,4.9);

  %% top-make.mk
  \node [at={(-0.05cm,2mm)},
         rectangle,
         very thick,
         text centered,
         font=\ttfamily,
         text width=2.8cm,
         minimum width=15cm,
         minimum height=7.8cm,
         draw=green!50!black!50,
         fill=black!10!green!2!white,
         label={[shift={(0,-5mm)}]\texttt{top-make.mk}}] {};

  %% Work-horse Makefiles. -5.6 -> -5.73 = -0.13
  \node (initializemk) [node-makefile, at={(-5.73cm,-1.3cm)},
    label={[shift={(0,-5mm)}]\texttt{initialize.mk}}] {};
  \node (downloadmk)   [node-makefile, at={(-2.93cm,-1.3cm)},
    label={[shift={(0,-5mm)}]\texttt{download.mk}}] {};
  \node (analysis1mk)  [node-makefile, at={(-0.13cm,-1.3cm)},
    label={[shift={(0,-5mm)}]\texttt{format.mk}}] {};
  \node (analysis2mk)  [node-makefile, at={(2.67cm,-1.3cm)},
    label={[shift={(0,-5mm)}]\texttt{demo-plot.mk}}] {};

  %% verify.mk
  \node [at={(-5.3cm,-2.8cm)},
         thick,
         rectangle,
         text centered,
         font=\ttfamily,
         text width=2.45cm,
         minimum width=3.5cm,
         minimum height=1.3cm,
         draw=green!50!black!50,
         fill=black!10!green!12!white,
         label={[shift={(1cm,-5mm)}]\texttt{verify.mk}}] {};

  %% Paper.mk
  \node [at={(2.67cm,-2.8cm)},
         thick,
         rectangle,
         text centered,
         text width=2.8cm,
         minimum width=8.5cm,
         minimum height=1.3cm,
         draw=green!50!black!50,
         fill=black!10!green!12!white,
         font=\ttfamily,
         label={[shift={(0,-5mm)}]\texttt{paper.mk}}] {};

  %% paper.pdf
  \ifdefined\paperpdf
  \node (paperpdf) [node-terminal, at={(5.47cm,-2.9cm)}] {paper.pdf};
  \fi

  %% paper.tex
  \ifdefined\papertex
  \node (reftex) [node-nonterminal, at={(2.67cm,-4.2cm)}] {references.tex};
  \node (papertex) [node-nonterminal, at={(5.47cm,-4.2cm)}] {paper.tex};
  \node (papertex-north) [node-point, at={(5.47cm,-3.58cm)}] {};
  \draw [rounded corners] (reftex) |- (papertex-north);
  \draw [->] (papertex) -- (paperpdf);
  \fi

  %% project.tex
  \ifdefined\projecttex
  \node (projecttex) [node-terminal, at={(-0.13cm,-2.9cm)}] {project.tex};
  \draw [->] (projecttex) -- (paperpdf);
  \fi

  %% verify.tex
  \ifdefined\verifytex
  \node (verifytex) [node-terminal, at={(-5.73cm,-2.9cm)}] {verify.tex};
  \draw [->] (verifytex) -- (projecttex);
  \fi

  %% Initialize.tex
  \ifdefined\initializetex
  \node (initializetex) [node-terminal, at={(-5.73cm,-0.8cm)}] {initialize.tex};
  \node (initialize-south) [node-point, at={(-5.73cm,-1.5cm)}] {};
  \draw [->] (initializetex) -- (verifytex);
  \node [anchor=west, at={(-7.05cm,2.30cm)}] {Basic project info};
  \node [anchor=west, at={(-7.05cm,1.95cm)}] {(e.g., Git commit).};
  \node [anchor=west, at={(-7.05cm,1.10cm)}] {Also defines};
  \node [anchor=west, at={(-7.05cm,0.75cm)}] {project structure};
  \node [anchor=west, at={(-7.05cm,0.40cm)}] {(for \texttt{*.mk} files).};
  \fi

  %% demo-plot.tex
  \ifdefined\demoplottex
  \node (dptex) [node-terminal, at={(2.67cm,-0.8cm)}] {demo-plot.tex};
  \draw [rounded corners, -] (dptex) |- (initialize-south);
  \fi

  %% tools-per-year.txt
  \ifdefined\toolsperyear
  \node (tpyear) [node-terminal, at={(2.67cm,0.3cm)}] {tools-per-\\year.txt};
  \draw [->] (tpyear) -- (dptex);
  \fi

  %% table-3.txt
  \ifdefined\tablethree
  \node (tabthree) [node-terminal, at={(-0.13cm,1.1cm)}] {table-3.txt};
  \draw [rounded corners, ->] (tabthree) |- (tpyear);
  \fi

  %% menkexlsx
  \ifdefined\menkexlsx
  \node (xlsx) [node-terminal, at={(-2.93cm,1.9cm)}] {menke20.xlsx};
  \draw [->, rounded corners] (xlsx) |- (tabthree);
  \fi

  %% INPUTS.conf
  \ifdefined\inputsconf
  \node (INPUTS) [node-nonterminal, at={(-2.93cm,4.6cm)}] {INPUTS.conf};
  \node (xlsx-west) [node-point, at={(-4.33cm,1.9cm)}] {};
  \draw [->,rounded corners] (INPUTS.west) -| (xlsx-west) |- (xlsx);
  \fi

  %% download.tex
  \ifdefined\downloadtex
  \node (downloadtex) [node-terminal, at={(-2.93cm,-0.8cm)}] {download.tex};
  \node (downloadtex-west) [node-point, at={(-4.33cm,-0.8cm)}] {};
  \draw [->,rounded corners] (INPUTS.west) -| (downloadtex-west)
                             |- (downloadtex);
  \draw [rounded corners, -] (downloadtex) |- (initialize-south);
  \fi

  %% format.tex
  \ifdefined\formattex
  \node (fmttex) [node-terminal, at={(-0.13cm,-0.8cm)}] {format.tex};
  \draw [->] (tabthree) -- (fmttex);
  \draw [rounded corners, -] (fmttex) |- (initialize-south);
  \fi

  %% demo-year.conf
  \ifdefined\demoyearconf
  \node (dyearconf) [node-nonterminal, at={(2.67cm,4.6cm)}] {demo-year.conf};
  \node (dptex-west) [node-point, at={(1.27cm,-0.8cm)}] {};
  \draw [->,rounded corners] (dyearconf.west) -| (dptex-west) |- (dptex);
  \fi

  %% Expanding project
  \ifdefined\expandingproject

    %% The Makefile.
    \node [opacity=0.7, dashed] (analysis3mk)  [node-makefile, at={(5.47cm,-1.3cm)},
      label={[shift={(0,-5mm)}, opacity=0.7]\texttt{next-step.mk}}] {};

    %% next-step.tex
    \node [opacity=0.7, dashed] (a3tex) [node-terminal, at={(5.47cm,-0.8cm)}] {next-step.tex};
    \draw [opacity=0.7, rounded corners, -, dashed] (a3tex) |- (initialize-south);

    % out-3a.dat and out-3b.dat
    \node [opacity=0.7, dashed] (out3a) [node-terminal, at={(5.47cm,2.7cm)}] {out-a.dat};
    \node [opacity=0.7, dashed] (out3b) [node-terminal, at={(5.47cm,1.1cm)}] {out-b.dat};
    \node (a3tex-east) [node-point, at={(6.87cm,-0.8cm)}] {};
    \draw [opacity=0.7, ->,rounded corners, dashed] (out3a.east) -| (a3tex-east) |- (a3tex);
    \draw [opacity=0.7, ->, dashed] (out3b) -- (a3tex);

    %% demo-out.dat
    \node [opacity=0.7, dashed] (dout) [node-terminal, at={(2.67cm,1.9cm)}] {demo-out.dat};
    \draw [opacity=0.7, ->, rounded corners, dashed] (dout.south) |- (out3b);

    %% links
    \node (dout-west) [node-point, at={(1.27cm,1.9cm)}] {};
    \draw [opacity=0.7, ->, dashed] (xlsx) -- (dout);
    \node [opacity=0.7] (out3a-west) [node-point, at={(4.07cm,2.7cm)}] {};
    \draw [opacity=0.7, ->,rounded corners, dashed] (xlsx) |- (out3a);
    \node [opacity=0.7, dashed] (a3conf1) [node-nonterminal, at={(5.47cm,4.6cm)}]  {param.conf};
    \draw [opacity=0.7, rounded corners, dashed] (a3conf1.west) -| (out3a-west) |- (out3a);
  \fi
\end{tikzpicture}
