#include <cstdlib>

#include "vertint_util.h"
#include "cdo_output.h"

bool
getenv_extrapolate(void)
{
  auto extrapolate = false;
  const auto envstr = getenv("EXTRAPOLATE");
  if (envstr && std::isdigit((int) envstr[0]))
  {
    if (std::atoi(envstr) == 1) { extrapolate = true; }
    if (extrapolate) cdo_print("Extrapolation of missing values enabled!");
  }

  return extrapolate;
}

void
check_range(std::string_view txt, MinMax mm, double rmin, double rmax, int stepNum)
{
  if (mm.min < rmin || mm.max > rmax) cdo_warning("%s out of range (min=%g max=%g)[step:%d]!", txt, mm.min, mm.max, stepNum);
}

void
check_range(std::string_view txt, MinMax mm, double rmin, double rmax, int stepNum, int layer)
{
  if (mm.min < rmin || mm.max > rmax)
    cdo_warning("%s at layer %d out of range (min=%g max=%g)[step:%d]!", txt, layer, mm.min, mm.max, stepNum);
}
