#ifdef ADIC_DENSE
#include "ad_types.h"
#include "ad_grad_saxpy-n_dense.h"
#endif
#ifdef ADIC_DENSE_REVERSE
#include "ad_types.hpp"
#include "ad_grad_saxpy-n_dense.h"
#endif
#ifdef ADIC_DENSE_SEED
#include "ad_types.h"
#include "ad_grad_saxpy-n_dense.h"
#endif
#ifdef ADIC_GRAD_LENGTH
#include "ad_grad_length_types.h"
#include "ad_grad_saxpy-n_dense.h"
#endif
#ifdef ADIC_SPARSE_NO_GRAD
#include "noderiv_sparslinc.h"
#include "ad_grad_saxpy-n_sparse.h"
#endif
#ifdef ADIC_SPARSE
#include "sparslinc.h"
#include "ad_grad_saxpy-n_sparse.h"
#endif
#include <stdlib.h>

int ad_o_fcn(DERIV_TYPE *obj,DERIV_TYPE x[6UL]);


int g_fcn(double *obj, double g_obj[6], const double x[6])
{
DERIV_TYPE ad_obj,ad_x[6];
 int i;
 int retval;

  ADIC_Init();
  ADIC_SetForwardMode();

  for(i=0;i<6;i++) {
    DERIV_val(ad_x[i]) = x[i];
    ADIC_SetIndep((ad_x)[i]);
  }
  /* ADIC_SetDep(ad_obj); */
  ADIC_SetIndepDone();

  retval = ad_o_fcn(&ad_obj,ad_x);
  /* ad_AD_ExtractVal(*obj,&ad_obj); */
  *obj = DERIV_val(ad_obj);
  /*  ad_AD_ExtractGrad(g_obj,&ad_obj); */
  for(i=0;i<6;i++) g_obj[i] = DERIV_grad(ad_obj)[i];
  return retval;
}
