{% if ((ODEmethod == "cvode") or (ODEmethod == "ida")) %} /* * Check function return value. * opt == 0 means SUNDIALS function allocates memory so check if * returned NULL pointer * opt == 1 means SUNDIALS function returns a flag so check if * flag >= 0 * opt == 2 means function allocates memory so check if returned * NULL pointer */ static int check_flag(void *flagvalue, const char *funcname, int opt) { int *errflag; /* Check if CVode/IDA function returned NULL pointer - no memory allocated */ if (opt == 0 && flagvalue == NULL) { fprintf(stderr, "\nCVode/IDA error: %s() failed - returned NULL pointer\n\n", funcname); return(1); } /* Check if flag < 0 */ else if (opt == 1) { errflag = (int *) flagvalue; if (*errflag < 0) { fprintf(stderr, "\nCVode/IDA error: %s() failed with flag = %d\n\n", funcname, *errflag); return(1); } } /* Check if function returned NULL pointer - no memory allocated */ else if (opt == 2 && flagvalue == NULL) { fprintf(stderr, "\nMemory error: %s() failed - returned NULL pointer\n\n", funcname); return(1); } return(0); } void adjust_zero_crossings (N_Vector v, double abstol) { int i; for (i = 0; i < NV_LENGTH_S(v); i++) { if (fabs(NV_Ith_S(v,i)) < abstol) NV_Ith_S(v,i) = 0; } return; } {% endif %}