/*
  This file is part of CDO. CDO is a collection of Operators to manipulate and analyse Climate model Data.

  Author: Uwe Schulzweida

*/
#ifndef REMAP_STORE_LINK_H
#define REMAP_STORE_LINK_H

#include <array>
#include <vector>

using BicubicWeights = std::array<std::array<double, 4>, 4>;

// Predeclarations
struct RemapVars;

struct IndexWeight
{
  size_t index{ 0 };
  double weight{ 0 };
};

struct IndexWeightBicubic
{
  size_t index{ 0 };
  std::array<double, 4> weight{};
};

struct WeightLinks
{
  size_t nlinks{ 0 };
  std::vector<IndexWeight> indexWeights;
};

struct WeightLinks1
{
  size_t nlinks{ 0 };
  IndexWeight indexWeights;
};

struct WeightLinksBilinear
{
  size_t nlinks{ 0 };
  std::array<IndexWeight, 4> indexWeights;
};

struct WeightLinksBicubic
{
  size_t nlinks{ 0 };
  std::array<IndexWeightBicubic, 4> indexWeights;
};

void store_weightLinks(size_t numWeights, std::vector<size_t> const &indices, std::vector<double> const &weights,
                       WeightLinks &weightLinks);
void store_weightLinks(size_t index, double weight, WeightLinks1 &weightLinks);
void store_weightLinks(std::array<size_t, 4> const &indices, std::array<double, 4> const &weights,
                       WeightLinksBilinear &weightLinks);
void store_weightLinks(std::array<size_t, 4> const &indices, BicubicWeights const &weights, WeightLinksBicubic &weightLinks);
void weightLinks_to_remapLinks(size_t gridSize, std::vector<WeightLinks> const &weightLinksList, RemapVars &rv);
void weightLinks_to_remapLinks(size_t gridSize, std::vector<WeightLinks1> const &weightLinksList, RemapVars &rv);
void weightLinks_to_remapLinks(size_t gridSize, std::vector<WeightLinksBilinear> const &weightLinksList, RemapVars &rv);
void weightLinks_to_remapLinks(size_t gridSize, std::vector<WeightLinksBicubic> const &weightLinksList, RemapVars &rv);

void set_numLinksPerValue(long &numLinksPerValue, long numWeights);
void check_numLinksPerValue(std::vector<long> &numLinksPerValueList);

#endif /* REMAP_STORE_LINK */
