/* 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 "neut_seedset_.h"

void
neut_seedset_set_zero (struct SEEDSET *pSeedSet)
{
  (*pSeedSet).N = 0;
  (*pSeedSet).N1d = 0;
  (*pSeedSet).Id = 0;
  (*pSeedSet).Dim = 3;
  (*pSeedSet).weight = NULL;
  (*pSeedSet).morpho = NULL;
  (*pSeedSet).Random = 0;
  (*pSeedSet).SeedCoo = NULL;
  (*pSeedSet).SeedWeight = NULL;
  (*pSeedSet).NDensity = 0;
  (*pSeedSet).LamEq = NULL;
  (*pSeedSet).LamWidth = 0;

  (*pSeedSet).rngid = NULL;
  (*pSeedSet).q = NULL;

  // Domain neighbourhood info
  (*pSeedSet).Size = NULL;
  (*pSeedSet).nN = 0;
  (*pSeedSet).nSize = NULL;
  (*pSeedSet).nVol = 0;
  (*pSeedSet).nSeedCoo = NULL;
  (*pSeedSet).nSeedRandId = NULL;
  (*pSeedSet).nMaster = NULL;

  return;
}

void
neut_seedset_free (struct SEEDSET *pSeedSet)
{
  ut_free_1d_char ((*pSeedSet).weight);
  ut_free_1d_char ((*pSeedSet).morpho);
  ut_free_2d ((*pSeedSet).SeedCoo, (*pSeedSet).N + 1);
  ut_free_1d ((*pSeedSet).SeedWeight);
  ut_free_1d ((*pSeedSet).LamEq);

  ut_free_1d_int ((*pSeedSet).rngid);
  ut_free_2d ((*pSeedSet).q, (*pSeedSet).N + 1);

  // Domain neighbourhood info
  ut_free_2d ((*pSeedSet).Size, 3);
  ut_free_2d ((*pSeedSet).nSize, 3);
  ut_free_2d ((*pSeedSet).nSeedCoo, (*pSeedSet).nN);
  ut_free_1d_int ((*pSeedSet).nSeedRandId);
  ut_free_1d_int ((*pSeedSet).nMaster);

  neut_seedset_set_zero (pSeedSet);

  return;
}

int
neut_seedset_seed_master (struct SEEDSET GSet, int seed)
{
  if (seed <= GSet.N)
    return seed;
  else
    return GSet.nMaster[seed - GSet.N];
}
