/* This file is part of the Neper software package. */
/* Copyright (C) 2003-2014, Romain Quey. */
/* See the COPYING file in the top-level directory. */

#include"net_flatten_ver_.h"

void
net_flatten_ver_init_fvertessver (struct MTESS MTess, struct TESS *Tess,
				  struct TESS *pFTess, struct TESSE *TessE,
				  struct FLATTEN *pFlatten)
{
  int i, j, fver;

  // Testing whether TessE[].VerFVer is fully filled
  for (i = 1; i <= MTess.TessQty; i++)
    for (j = 1; j <= Tess[i].VerQty; j++)
      if (TessE[i].VerFVer[j] == 0)
	ut_error_reportbug ();

  // Init VerTessVerQty and VerTessVerNb from TessE[].VerFVer
  (*pFlatten).VerTessVerQty = ut_alloc_1d_int ((*pFTess).VerQty + 1);
  (*pFlatten).VerTessVerNb = ut_alloc_1d_ppint ((*pFTess).VerQty + 1);
  for (i = 2; i <= MTess.TessQty; i++)
    for (j = 1; j <= Tess[i].VerQty; j++)
    {
      fver = TessE[i].VerFVer[j];
      (*pFlatten).VerTessVerQty[fver]++;
      (*pFlatten).VerTessVerNb[fver]
	= ut_realloc_2d_int_addline ((*pFlatten).VerTessVerNb[fver],
				     (*pFlatten).VerTessVerQty[fver], 2);
      (*pFlatten).VerTessVerNb[fver][(*pFlatten).VerTessVerQty[fver] - 1][0] =
	i;
      (*pFlatten).VerTessVerNb[fver][(*pFlatten).VerTessVerQty[fver] - 1][1] =
	j;
    }

  return;
}
