text: // Automatically generated by odin 1.1.1 - do not edit
  #include <R.h>
  #include <Rmath.h>
  #include <Rinternals.h>
  #include <stdbool.h>
  #include <R_ext/Rdynload.h>
  typedef struct cyst_generator_internal {
    double alpha;
    double bH;
    double bP;
    double CCC0;
    double chi;
    double CTC0;
    double dE;
    double delta;
    double dH;
    double dP;
    double E0;
    double epsilon;
    double eta;
    double HPS;
    double IH0;
    double IHC0;
    double initial_CCC;
    double initial_CTC;
    double initial_E;
    double initial_IH;
    double initial_IHC;
    double initial_IPH;
    double initial_IPL;
    double initial_RP;
    double initial_SH;
    double initial_SHC;
    double initial_SP;
    double initial_VP;
    double IPH0;
    double IPL0;
    double phi;
    double pih;
    double pil;
    double PPS;
    double RP0;
    double RR_cysticercosis;
    double SH0;
    double SHC0;
    double SP0;
    double tau;
    double theta;
    double VP0;
  } cyst_generator_internal;
  cyst_generator_internal* cyst_generator_get_internal(SEXP internal_p, int closed_error);
  static void cyst_generator_finalise(SEXP internal_p);
  SEXP cyst_generator_create(SEXP user);
  void cyst_generator_initmod_desolve(void(* odeparms) (int *, double *));
  SEXP cyst_generator_contents(SEXP internal_p);
  SEXP cyst_generator_set_user(SEXP internal_p, SEXP user);
  SEXP cyst_generator_set_initial(SEXP internal_p, SEXP t_ptr, SEXP state_ptr, SEXP cyst_generator_use_dde_ptr);
  SEXP cyst_generator_metadata(SEXP internal_p);
  SEXP cyst_generator_initial_conditions(SEXP internal_p, SEXP t_ptr);
  void cyst_generator_rhs(cyst_generator_internal* internal, double t, double * state, double * dstatedt, double * output);
  void cyst_generator_rhs_dde(size_t neq, double t, double * state, double * dstatedt, void * internal);
  void cyst_generator_rhs_desolve(int * neq, double * t, double * state, double * dstatedt, double * output, int * np);
  void cyst_generator_output_dde(size_t n_eq, double t, double * state, size_t n_output, double * output, void * internal_p);
  SEXP cyst_generator_rhs_r(SEXP internal_p, SEXP t, SEXP state);
  double user_get_scalar_double(SEXP user, const char *name,
                                double default_value, double min, double max);
  int user_get_scalar_int(SEXP user, const char *name,
                          int default_value, double min, double max);
  void user_check_values_double(double * value, size_t len,
                                    double min, double max, const char *name);
  void user_check_values_int(int * value, size_t len,
                                 double min, double max, const char *name);
  void user_check_values(SEXP value, double min, double max,
                             const char *name);
  SEXP user_list_element(SEXP list, const char *name);
  double scalar_real(SEXP x, const char * name);
  cyst_generator_internal* cyst_generator_get_internal(SEXP internal_p, int closed_error) {
    cyst_generator_internal *internal = NULL;
    if (TYPEOF(internal_p) != EXTPTRSXP) {
      Rf_error("Expected an external pointer");
    }
    internal = (cyst_generator_internal*) R_ExternalPtrAddr(internal_p);
    if (!internal && closed_error) {
      Rf_error("Pointer has been invalidated");
    }
    return internal;
  }
  void cyst_generator_finalise(SEXP internal_p) {
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 0);
    if (internal_p) {
      Free(internal);
      R_ClearExternalPtr(internal_p);
    }
  }
  SEXP cyst_generator_create(SEXP user) {
    cyst_generator_internal *internal = (cyst_generator_internal*) Calloc(1, cyst_generator_internal);
    internal->alpha = NA_REAL;
    internal->bH = NA_REAL;
    internal->bP = NA_REAL;
    internal->CCC0 = NA_REAL;
    internal->chi = NA_REAL;
    internal->CTC0 = NA_REAL;
    internal->dE = NA_REAL;
    internal->delta = NA_REAL;
    internal->dH = NA_REAL;
    internal->dP = NA_REAL;
    internal->E0 = NA_REAL;
    internal->epsilon = NA_REAL;
    internal->eta = NA_REAL;
    internal->HPS = NA_REAL;
    internal->IH0 = NA_REAL;
    internal->IHC0 = NA_REAL;
    internal->IPH0 = NA_REAL;
    internal->IPL0 = NA_REAL;
    internal->phi = NA_REAL;
    internal->pih = NA_REAL;
    internal->pil = NA_REAL;
    internal->PPS = NA_REAL;
    internal->RP0 = NA_REAL;
    internal->RR_cysticercosis = NA_REAL;
    internal->SH0 = NA_REAL;
    internal->SHC0 = NA_REAL;
    internal->SP0 = NA_REAL;
    internal->tau = NA_REAL;
    internal->theta = NA_REAL;
    internal->VP0 = NA_REAL;
    SEXP ptr = PROTECT(R_MakeExternalPtr(internal, R_NilValue, R_NilValue));
    R_RegisterCFinalizer(ptr, cyst_generator_finalise);
    UNPROTECT(1);
    return ptr;
  }
  static cyst_generator_internal *cyst_generator_internal_ds;
  void cyst_generator_initmod_desolve(void(* odeparms) (int *, double *)) {
    static DL_FUNC get_desolve_gparms = NULL;
    if (get_desolve_gparms == NULL) {
      get_desolve_gparms =
        R_GetCCallable("deSolve", "get_deSolve_gparms");
    }
    cyst_generator_internal_ds = cyst_generator_get_internal(get_desolve_gparms(), 1);
  }
  SEXP cyst_generator_contents(SEXP internal_p) {
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 1);
    SEXP contents = PROTECT(allocVector(VECSXP, 42));
    SET_VECTOR_ELT(contents, 0, ScalarReal(internal->alpha));
    SET_VECTOR_ELT(contents, 1, ScalarReal(internal->bH));
    SET_VECTOR_ELT(contents, 2, ScalarReal(internal->bP));
    SET_VECTOR_ELT(contents, 3, ScalarReal(internal->CCC0));
    SET_VECTOR_ELT(contents, 4, ScalarReal(internal->chi));
    SET_VECTOR_ELT(contents, 5, ScalarReal(internal->CTC0));
    SET_VECTOR_ELT(contents, 6, ScalarReal(internal->dE));
    SET_VECTOR_ELT(contents, 7, ScalarReal(internal->delta));
    SET_VECTOR_ELT(contents, 8, ScalarReal(internal->dH));
    SET_VECTOR_ELT(contents, 9, ScalarReal(internal->dP));
    SET_VECTOR_ELT(contents, 10, ScalarReal(internal->E0));
    SET_VECTOR_ELT(contents, 11, ScalarReal(internal->epsilon));
    SET_VECTOR_ELT(contents, 12, ScalarReal(internal->eta));
    SET_VECTOR_ELT(contents, 13, ScalarReal(internal->HPS));
    SET_VECTOR_ELT(contents, 14, ScalarReal(internal->IH0));
    SET_VECTOR_ELT(contents, 15, ScalarReal(internal->IHC0));
    SET_VECTOR_ELT(contents, 16, ScalarReal(internal->initial_CCC));
    SET_VECTOR_ELT(contents, 17, ScalarReal(internal->initial_CTC));
    SET_VECTOR_ELT(contents, 18, ScalarReal(internal->initial_E));
    SET_VECTOR_ELT(contents, 19, ScalarReal(internal->initial_IH));
    SET_VECTOR_ELT(contents, 20, ScalarReal(internal->initial_IHC));
    SET_VECTOR_ELT(contents, 21, ScalarReal(internal->initial_IPH));
    SET_VECTOR_ELT(contents, 22, ScalarReal(internal->initial_IPL));
    SET_VECTOR_ELT(contents, 23, ScalarReal(internal->initial_RP));
    SET_VECTOR_ELT(contents, 24, ScalarReal(internal->initial_SH));
    SET_VECTOR_ELT(contents, 25, ScalarReal(internal->initial_SHC));
    SET_VECTOR_ELT(contents, 26, ScalarReal(internal->initial_SP));
    SET_VECTOR_ELT(contents, 27, ScalarReal(internal->initial_VP));
    SET_VECTOR_ELT(contents, 28, ScalarReal(internal->IPH0));
    SET_VECTOR_ELT(contents, 29, ScalarReal(internal->IPL0));
    SET_VECTOR_ELT(contents, 30, ScalarReal(internal->phi));
    SET_VECTOR_ELT(contents, 31, ScalarReal(internal->pih));
    SET_VECTOR_ELT(contents, 32, ScalarReal(internal->pil));
    SET_VECTOR_ELT(contents, 33, ScalarReal(internal->PPS));
    SET_VECTOR_ELT(contents, 34, ScalarReal(internal->RP0));
    SET_VECTOR_ELT(contents, 35, ScalarReal(internal->RR_cysticercosis));
    SET_VECTOR_ELT(contents, 36, ScalarReal(internal->SH0));
    SET_VECTOR_ELT(contents, 37, ScalarReal(internal->SHC0));
    SET_VECTOR_ELT(contents, 38, ScalarReal(internal->SP0));
    SET_VECTOR_ELT(contents, 39, ScalarReal(internal->tau));
    SET_VECTOR_ELT(contents, 40, ScalarReal(internal->theta));
    SET_VECTOR_ELT(contents, 41, ScalarReal(internal->VP0));
    SEXP nms = PROTECT(allocVector(STRSXP, 42));
    SET_STRING_ELT(nms, 0, mkChar("alpha"));
    SET_STRING_ELT(nms, 1, mkChar("bH"));
    SET_STRING_ELT(nms, 2, mkChar("bP"));
    SET_STRING_ELT(nms, 3, mkChar("CCC0"));
    SET_STRING_ELT(nms, 4, mkChar("chi"));
    SET_STRING_ELT(nms, 5, mkChar("CTC0"));
    SET_STRING_ELT(nms, 6, mkChar("dE"));
    SET_STRING_ELT(nms, 7, mkChar("delta"));
    SET_STRING_ELT(nms, 8, mkChar("dH"));
    SET_STRING_ELT(nms, 9, mkChar("dP"));
    SET_STRING_ELT(nms, 10, mkChar("E0"));
    SET_STRING_ELT(nms, 11, mkChar("epsilon"));
    SET_STRING_ELT(nms, 12, mkChar("eta"));
    SET_STRING_ELT(nms, 13, mkChar("HPS"));
    SET_STRING_ELT(nms, 14, mkChar("IH0"));
    SET_STRING_ELT(nms, 15, mkChar("IHC0"));
    SET_STRING_ELT(nms, 16, mkChar("initial_CCC"));
    SET_STRING_ELT(nms, 17, mkChar("initial_CTC"));
    SET_STRING_ELT(nms, 18, mkChar("initial_E"));
    SET_STRING_ELT(nms, 19, mkChar("initial_IH"));
    SET_STRING_ELT(nms, 20, mkChar("initial_IHC"));
    SET_STRING_ELT(nms, 21, mkChar("initial_IPH"));
    SET_STRING_ELT(nms, 22, mkChar("initial_IPL"));
    SET_STRING_ELT(nms, 23, mkChar("initial_RP"));
    SET_STRING_ELT(nms, 24, mkChar("initial_SH"));
    SET_STRING_ELT(nms, 25, mkChar("initial_SHC"));
    SET_STRING_ELT(nms, 26, mkChar("initial_SP"));
    SET_STRING_ELT(nms, 27, mkChar("initial_VP"));
    SET_STRING_ELT(nms, 28, mkChar("IPH0"));
    SET_STRING_ELT(nms, 29, mkChar("IPL0"));
    SET_STRING_ELT(nms, 30, mkChar("phi"));
    SET_STRING_ELT(nms, 31, mkChar("pih"));
    SET_STRING_ELT(nms, 32, mkChar("pil"));
    SET_STRING_ELT(nms, 33, mkChar("PPS"));
    SET_STRING_ELT(nms, 34, mkChar("RP0"));
    SET_STRING_ELT(nms, 35, mkChar("RR_cysticercosis"));
    SET_STRING_ELT(nms, 36, mkChar("SH0"));
    SET_STRING_ELT(nms, 37, mkChar("SHC0"));
    SET_STRING_ELT(nms, 38, mkChar("SP0"));
    SET_STRING_ELT(nms, 39, mkChar("tau"));
    SET_STRING_ELT(nms, 40, mkChar("theta"));
    SET_STRING_ELT(nms, 41, mkChar("VP0"));
    setAttrib(contents, R_NamesSymbol, nms);
    UNPROTECT(2);
    return contents;
  }
  SEXP cyst_generator_set_user(SEXP internal_p, SEXP user) {
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 1);
    internal->alpha = user_get_scalar_double(user, "alpha", internal->alpha, NA_REAL, NA_REAL);
    internal->bH = user_get_scalar_double(user, "bH", internal->bH, NA_REAL, NA_REAL);
    internal->bP = user_get_scalar_double(user, "bP", internal->bP, NA_REAL, NA_REAL);
    internal->CCC0 = user_get_scalar_double(user, "CCC0", internal->CCC0, NA_REAL, NA_REAL);
    internal->chi = user_get_scalar_double(user, "chi", internal->chi, NA_REAL, NA_REAL);
    internal->CTC0 = user_get_scalar_double(user, "CTC0", internal->CTC0, NA_REAL, NA_REAL);
    internal->dE = user_get_scalar_double(user, "dE", internal->dE, NA_REAL, NA_REAL);
    internal->delta = user_get_scalar_double(user, "delta", internal->delta, NA_REAL, NA_REAL);
    internal->dH = user_get_scalar_double(user, "dH", internal->dH, NA_REAL, NA_REAL);
    internal->dP = user_get_scalar_double(user, "dP", internal->dP, NA_REAL, NA_REAL);
    internal->E0 = user_get_scalar_double(user, "E0", internal->E0, NA_REAL, NA_REAL);
    internal->epsilon = user_get_scalar_double(user, "epsilon", internal->epsilon, NA_REAL, NA_REAL);
    internal->eta = user_get_scalar_double(user, "eta", internal->eta, NA_REAL, NA_REAL);
    internal->HPS = user_get_scalar_double(user, "HPS", internal->HPS, NA_REAL, NA_REAL);
    internal->IH0 = user_get_scalar_double(user, "IH0", internal->IH0, NA_REAL, NA_REAL);
    internal->IHC0 = user_get_scalar_double(user, "IHC0", internal->IHC0, NA_REAL, NA_REAL);
    internal->IPH0 = user_get_scalar_double(user, "IPH0", internal->IPH0, NA_REAL, NA_REAL);
    internal->IPL0 = user_get_scalar_double(user, "IPL0", internal->IPL0, NA_REAL, NA_REAL);
    internal->phi = user_get_scalar_double(user, "phi", internal->phi, NA_REAL, NA_REAL);
    internal->pih = user_get_scalar_double(user, "pih", internal->pih, NA_REAL, NA_REAL);
    internal->pil = user_get_scalar_double(user, "pil", internal->pil, NA_REAL, NA_REAL);
    internal->PPS = user_get_scalar_double(user, "PPS", internal->PPS, NA_REAL, NA_REAL);
    internal->RP0 = user_get_scalar_double(user, "RP0", internal->RP0, NA_REAL, NA_REAL);
    internal->RR_cysticercosis = user_get_scalar_double(user, "RR_cysticercosis", internal->RR_cysticercosis, NA_REAL, NA_REAL);
    internal->SH0 = user_get_scalar_double(user, "SH0", internal->SH0, NA_REAL, NA_REAL);
    internal->SHC0 = user_get_scalar_double(user, "SHC0", internal->SHC0, NA_REAL, NA_REAL);
    internal->SP0 = user_get_scalar_double(user, "SP0", internal->SP0, NA_REAL, NA_REAL);
    internal->tau = user_get_scalar_double(user, "tau", internal->tau, NA_REAL, NA_REAL);
    internal->theta = user_get_scalar_double(user, "theta", internal->theta, NA_REAL, NA_REAL);
    internal->VP0 = user_get_scalar_double(user, "VP0", internal->VP0, NA_REAL, NA_REAL);
    internal->initial_CCC = internal->CCC0;
    internal->initial_CTC = internal->CTC0;
    internal->initial_E = internal->E0;
    internal->initial_IH = internal->IH0;
    internal->initial_IHC = internal->IHC0;
    internal->initial_IPH = internal->IPH0;
    internal->initial_IPL = internal->IPL0;
    internal->initial_RP = internal->RP0;
    internal->initial_SH = internal->SH0;
    internal->initial_SHC = internal->SHC0;
    internal->initial_SP = internal->SP0;
    internal->initial_VP = internal->VP0;
    return R_NilValue;
  }
  SEXP cyst_generator_set_initial(SEXP internal_p, SEXP t_ptr, SEXP state_ptr, SEXP cyst_generator_use_dde_ptr) {
    return R_NilValue;
  }
  SEXP cyst_generator_metadata(SEXP internal_p) {
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 1);
    SEXP ret = PROTECT(allocVector(VECSXP, 4));
    SEXP nms = PROTECT(allocVector(STRSXP, 4));
    SET_STRING_ELT(nms, 0, mkChar("variable_order"));
    SET_STRING_ELT(nms, 1, mkChar("output_order"));
    SET_STRING_ELT(nms, 2, mkChar("n_out"));
    SET_STRING_ELT(nms, 3, mkChar("interpolate_t"));
    setAttrib(ret, R_NamesSymbol, nms);
    SEXP variable_length = PROTECT(allocVector(VECSXP, 12));
    SEXP variable_names = PROTECT(allocVector(STRSXP, 12));
    setAttrib(variable_length, R_NamesSymbol, variable_names);
    SET_VECTOR_ELT(variable_length, 0, R_NilValue);
    SET_VECTOR_ELT(variable_length, 1, R_NilValue);
    SET_VECTOR_ELT(variable_length, 2, R_NilValue);
    SET_VECTOR_ELT(variable_length, 3, R_NilValue);
    SET_VECTOR_ELT(variable_length, 4, R_NilValue);
    SET_VECTOR_ELT(variable_length, 5, R_NilValue);
    SET_VECTOR_ELT(variable_length, 6, R_NilValue);
    SET_VECTOR_ELT(variable_length, 7, R_NilValue);
    SET_VECTOR_ELT(variable_length, 8, R_NilValue);
    SET_VECTOR_ELT(variable_length, 9, R_NilValue);
    SET_VECTOR_ELT(variable_length, 10, R_NilValue);
    SET_VECTOR_ELT(variable_length, 11, R_NilValue);
    SET_STRING_ELT(variable_names, 0, mkChar("SH"));
    SET_STRING_ELT(variable_names, 1, mkChar("IH"));
    SET_STRING_ELT(variable_names, 2, mkChar("SHC"));
    SET_STRING_ELT(variable_names, 3, mkChar("IHC"));
    SET_STRING_ELT(variable_names, 4, mkChar("E"));
    SET_STRING_ELT(variable_names, 5, mkChar("SP"));
    SET_STRING_ELT(variable_names, 6, mkChar("IPL"));
    SET_STRING_ELT(variable_names, 7, mkChar("IPH"));
    SET_STRING_ELT(variable_names, 8, mkChar("RP"));
    SET_STRING_ELT(variable_names, 9, mkChar("VP"));
    SET_STRING_ELT(variable_names, 10, mkChar("CCC"));
    SET_STRING_ELT(variable_names, 11, mkChar("CTC"));
    SET_VECTOR_ELT(ret, 0, variable_length);
    UNPROTECT(2);
    SEXP output_length = PROTECT(allocVector(VECSXP, 6));
    SEXP output_names = PROTECT(allocVector(STRSXP, 6));
    setAttrib(output_length, R_NamesSymbol, output_names);
    SET_VECTOR_ELT(output_length, 0, R_NilValue);
    SET_VECTOR_ELT(output_length, 1, R_NilValue);
    SET_VECTOR_ELT(output_length, 2, R_NilValue);
    SET_VECTOR_ELT(output_length, 3, R_NilValue);
    SET_VECTOR_ELT(output_length, 4, R_NilValue);
    SET_VECTOR_ELT(output_length, 5, R_NilValue);
    SET_STRING_ELT(output_names, 0, mkChar("Humans_Taeniasis"));
    SET_STRING_ELT(output_names, 1, mkChar("Humans_Cysticercosis"));
    SET_STRING_ELT(output_names, 2, mkChar("Pigs_Cysticercosis"));
    SET_STRING_ELT(output_names, 3, mkChar("Human_Taeniasis_prev"));
    SET_STRING_ELT(output_names, 4, mkChar("Human_Cysticercosis_prev"));
    SET_STRING_ELT(output_names, 5, mkChar("Pig_Cysticercosis_prev"));
    SET_VECTOR_ELT(ret, 1, output_length);
    UNPROTECT(2);
    SET_VECTOR_ELT(ret, 2, ScalarInteger(6));
    UNPROTECT(2);
    return ret;
  }
  SEXP cyst_generator_initial_conditions(SEXP internal_p, SEXP t_ptr) {
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 1);
    SEXP r_state = PROTECT(allocVector(REALSXP, 12));
    double * state = REAL(r_state);
    state[0] = internal->initial_SH;
    state[1] = internal->initial_IH;
    state[2] = internal->initial_SHC;
    state[3] = internal->initial_IHC;
    state[4] = internal->initial_E;
    state[5] = internal->initial_SP;
    state[6] = internal->initial_IPL;
    state[7] = internal->initial_IPH;
    state[8] = internal->initial_RP;
    state[9] = internal->initial_VP;
    state[10] = internal->initial_CCC;
    state[11] = internal->initial_CTC;
    UNPROTECT(1);
    return r_state;
  }
  void cyst_generator_rhs(cyst_generator_internal* internal, double t, double * state, double * dstatedt, double * output) {
    double SH = state[0];
    double IH = state[1];
    double SHC = state[2];
    double IHC = state[3];
    double E = state[4];
    double SP = state[5];
    double IPL = state[6];
    double IPH = state[7];
    double RP = state[8];
    double VP = state[9];
    dstatedt[10] = internal->theta * (1 + internal->RR_cysticercosis) * IH * E + internal->theta * SH * E;
    dstatedt[11] = (internal->pil * internal->chi) * SH * IPL / (double) internal->PPS + (internal->pil * internal->chi) * SHC * IPL / (double) internal->PPS + (internal->pih * internal->chi) * SH * IPH / (double) internal->PPS + (internal->pih * internal->chi) * SHC * IPH / (double) internal->PPS;
    dstatedt[4] = internal->delta * IH + internal->delta * IHC - internal->dE * E;
    dstatedt[1] = (internal->pil * internal->chi) * SH * IPL / (double) internal->PPS + (internal->pih * internal->chi) * SH * IPH / (double) internal->PPS - internal->alpha * IH - internal->theta * (1 + internal->RR_cysticercosis) * IH * E - internal->dH * IH;
    dstatedt[3] = (internal->pil * internal->chi) * SHC * IPL / (double) internal->PPS + (internal->pih * internal->chi) * SHC * IPH / (double) internal->PPS + internal->theta * (1 + internal->RR_cysticercosis) * IH * E - internal->alpha * IHC - internal->eta * IHC - internal->dH * IHC;
    dstatedt[7] = (1 - internal->phi) * internal->tau * SP * E - internal->dP * IPH;
    dstatedt[6] = internal->phi * internal->tau * SP * E - internal->dP * IPL;
    dstatedt[8] = -(internal->epsilon) * RP - internal->dP * RP;
    dstatedt[0] = internal->bH + internal->alpha * IH + internal->eta * SHC + internal->eta * IHC - (internal->pil * internal->chi) * SH * IPL / (double) internal->PPS - (internal->pih * internal->chi) * SH * IPH / (double) internal->PPS - internal->theta * SH * E - internal->dH * SH;
    dstatedt[2] = internal->theta * SH * E + internal->alpha * IHC - (internal->pil * internal->chi) * SHC * IPL / (double) internal->PPS - (internal->pih * internal->chi) * SHC * IPH / (double) internal->PPS - internal->eta * SHC - internal->dH * SHC;
    dstatedt[5] = internal->bP + internal->epsilon * RP - internal->phi * internal->tau * SP * E - (1 - internal->phi) * internal->tau * SP * E - internal->dP * SP;
    dstatedt[9] = -(internal->dP) * VP;
    if (output) {
      output[4] = (SHC + IHC) / (double) internal->HPS;
      output[3] = (IH + IHC) / (double) internal->HPS;
      output[1] = SHC + IHC;
      output[0] = IH + IHC;
      output[5] = (IPH + IPL) / (double) internal->PPS;
      output[2] = IPH + IPL;
    }
  }
  void cyst_generator_rhs_dde(size_t neq, double t, double * state, double * dstatedt, void * internal) {
    cyst_generator_rhs((cyst_generator_internal*)internal, t, state, dstatedt, NULL);
  }
  void cyst_generator_rhs_desolve(int * neq, double * t, double * state, double * dstatedt, double * output, int * np) {
    cyst_generator_rhs(cyst_generator_internal_ds, *t, state, dstatedt, output);
  }
  void cyst_generator_output_dde(size_t n_eq, double t, double * state, size_t n_output, double * output, void * internal_p) {
    cyst_generator_internal *internal = (cyst_generator_internal*) internal_p;
    double IH = state[1];
    double SHC = state[2];
    double IHC = state[3];
    double IPL = state[6];
    double IPH = state[7];
    output[4] = (SHC + IHC) / (double) internal->HPS;
    output[3] = (IH + IHC) / (double) internal->HPS;
    output[1] = SHC + IHC;
    output[0] = IH + IHC;
    output[5] = (IPH + IPL) / (double) internal->PPS;
    output[2] = IPH + IPL;
  }
  SEXP cyst_generator_rhs_r(SEXP internal_p, SEXP t, SEXP state) {
    SEXP dstatedt = PROTECT(allocVector(REALSXP, LENGTH(state)));
    cyst_generator_internal *internal = cyst_generator_get_internal(internal_p, 1);
    SEXP output_ptr = PROTECT(allocVector(REALSXP, 6));
    setAttrib(dstatedt, install("output"), output_ptr);
    UNPROTECT(1);
    double *output = REAL(output_ptr);
    cyst_generator_rhs(internal, scalar_real(t, "t"), REAL(state), REAL(dstatedt), output);
    UNPROTECT(1);
    return dstatedt;
  }
  double user_get_scalar_double(SEXP user, const char *name,
                                double default_value, double min, double max) {
    double ret = default_value;
    SEXP el = user_list_element(user, name);
    if (el != R_NilValue) {
      if (length(el) != 1) {
        Rf_error("Expected a scalar numeric for '%s'", name);
      }
      if (TYPEOF(el) == REALSXP) {
        ret = REAL(el)[0];
      } else if (TYPEOF(el) == INTSXP) {
        ret = INTEGER(el)[0];
      } else {
        Rf_error("Expected a numeric value for %s", name);
      }
    }
    if (ISNA(ret)) {
      Rf_error("Expected a value for '%s'", name);
    }
    user_check_values_double(&ret, 1, min, max, name);
    return ret;
  }
  int user_get_scalar_int(SEXP user, const char *name,
                          int default_value, double min, double max) {
    int ret = default_value;
    SEXP el = user_list_element(user, name);
    if (el != R_NilValue) {
      if (length(el) != 1) {
        Rf_error("Expected scalar integer for %d", name);
      }
      if (TYPEOF(el) == REALSXP) {
        double tmp = REAL(el)[0];
        if (fabs(tmp - round(tmp)) > 2e-8) {
          Rf_error("Expected '%s' to be integer-like", name);
        }
      }
      ret = INTEGER(coerceVector(el, INTSXP))[0];
    }
    if (ret == NA_INTEGER) {
      Rf_error("Expected a value for '%s'", name);
    }
    user_check_values_int(&ret, 1, min, max, name);
    return ret;
  }
  void user_check_values_double(double * value, size_t len,
                                    double min, double max, const char *name) {
    for (size_t i = 0; i < len; ++i) {
      if (ISNA(value[i])) {
        Rf_error("'%s' must not contain any NA values", name);
      }
    }
    if (min != NA_REAL) {
      for (size_t i = 0; i < len; ++i) {
        if (value[i] < min) {
          Rf_error("Expected '%s' to be at least %g", name, min);
        }
      }
    }
    if (max != NA_REAL) {
      for (size_t i = 0; i < len; ++i) {
        if (value[i] > max) {
          Rf_error("Expected '%s' to be at most %g", name, max);
        }
      }
    }
  }
  void user_check_values_int(int * value, size_t len,
                                 double min, double max, const char *name) {
    for (size_t i = 0; i < len; ++i) {
      if (ISNA(value[i])) {
        Rf_error("'%s' must not contain any NA values", name);
      }
    }
    if (min != NA_REAL) {
      for (size_t i = 0; i < len; ++i) {
        if (value[i] < min) {
          Rf_error("Expected '%s' to be at least %g", name, min);
        }
      }
    }
    if (max != NA_REAL) {
      for (size_t i = 0; i < len; ++i) {
        if (value[i] > max) {
          Rf_error("Expected '%s' to be at most %g", name, max);
        }
      }
    }
  }
  void user_check_values(SEXP value, double min, double max,
                             const char *name) {
    size_t len = (size_t)length(value);
    if (TYPEOF(value) == INTSXP) {
      user_check_values_int(INTEGER(value), len, min, max, name);
    } else {
      user_check_values_double(REAL(value), len, min, max, name);
    }
  }
  SEXP user_list_element(SEXP list, const char *name) {
    SEXP ret = R_NilValue, names = getAttrib(list, R_NamesSymbol);
    for (int i = 0; i < length(list); ++i) {
      if (strcmp(CHAR(STRING_ELT(names, i)), name) == 0) {
        ret = VECTOR_ELT(list, i);
        break;
      }
    }
    return ret;
  }
  double scalar_real(SEXP x, const char * name) {
    if (Rf_length(x) != 1) {
      Rf_error("Expected a scalar for %s", name);
    }
    double ret = 0.0;
    if (TYPEOF(x) == INTSXP) {
      ret = INTEGER(x)[0];
    } else if (TYPEOF(x) == REALSXP) {
      ret = REAL(x)[0];
    } else {
      Rf_error("Expected a numeric value for %s", name);
    }
    return ret;
  }
  