/* Created by Language version: 7.7.0 */
/* VECTORIZED */
#define NRN_VECTORIZED 1
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mech_api.h"
#undef PI
#define nil 0
#include "md1redef.h"
#include "section.h"
#include "nrniv_mf.h"
#include "md2redef.h"
 
#if METHOD3
extern int _method3;
#endif

#if !NRNGPU
#undef exp
#define exp hoc_Exp
extern double hoc_Exp(double);
#endif
 
#define nrn_init _nrn_init__skkin
#define _nrn_initial _nrn_initial__skkin
#define nrn_cur _nrn_cur__skkin
#define _nrn_current _nrn_current__skkin
#define nrn_jacob _nrn_jacob__skkin
#define nrn_state _nrn_state__skkin
#define _net_receive _net_receive__skkin 
#define kin kin__skkin 
 
#define _threadargscomma_ _p, _ppvar, _thread, _nt,
#define _threadargsprotocomma_ double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt,
#define _threadargs_ _p, _ppvar, _thread, _nt
#define _threadargsproto_ double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt
 	/*SUPPRESS 761*/
	/*SUPPRESS 762*/
	/*SUPPRESS 763*/
	/*SUPPRESS 765*/
	 extern double *getarg();
 /* Thread safe. No static _p or _ppvar. */
 
#define t _nt->_t
#define dt _nt->_dt
#define gbar _p[0]
#define gbar_columnindex 0
#define g _p[1]
#define g_columnindex 1
#define c _p[2]
#define c_columnindex 2
#define cac _p[3]
#define cac_columnindex 3
#define ca2c _p[4]
#define ca2c_columnindex 4
#define ca3c _p[5]
#define ca3c_columnindex 5
#define ca4c _p[6]
#define ca4c_columnindex 6
#define o _p[7]
#define o_columnindex 7
#define calcm _p[8]
#define calcm_columnindex 8
#define ek _p[9]
#define ek_columnindex 9
#define ik _p[10]
#define ik_columnindex 10
#define cai _p[11]
#define cai_columnindex 11
#define Dc _p[12]
#define Dc_columnindex 12
#define Dcac _p[13]
#define Dcac_columnindex 13
#define Dca2c _p[14]
#define Dca2c_columnindex 14
#define Dca3c _p[15]
#define Dca3c_columnindex 15
#define Dca4c _p[16]
#define Dca4c_columnindex 16
#define Do _p[17]
#define Do_columnindex 17
#define Dcalcm _p[18]
#define Dcalcm_columnindex 18
#define v _p[19]
#define v_columnindex 19
#define _g _p[20]
#define _g_columnindex 20
#define _ion_ek	*_ppvar[0]._pval
#define _ion_ik	*_ppvar[1]._pval
#define _ion_dikdv	*_ppvar[2]._pval
#define _ion_cai	*_ppvar[3]._pval
 
#if MAC
#if !defined(v)
#define v _mlhv
#endif
#if !defined(h)
#define h _mlhh
#endif
#endif
 
#if defined(__cplusplus)
extern "C" {
#endif
 static int hoc_nrnpointerindex =  -1;
 static Datum* _extcall_thread;
 static Prop* _extcall_prop;
 /* external NEURON variables */
 /* declaration of user functions */
 static int _mechtype;
extern void _nrn_cacheloop_reg(int, int);
extern void hoc_register_prop_size(int, int, int);
extern void hoc_register_limits(int, HocParmLimits*);
extern void hoc_register_units(int, HocParmUnits*);
extern void nrn_promote(Prop*, int, int);
extern Memb_func* memb_func;
 
#define NMODL_TEXT 1
#if NMODL_TEXT
static const char* nmodl_file_text;
static const char* nmodl_filename;
extern void hoc_reg_nmodl_text(int, const char*);
extern void hoc_reg_nmodl_filename(int, const char*);
#endif

 extern void _nrn_setdata_reg(int, void(*)(Prop*));
 static void _setdata(Prop* _prop) {
 _extcall_prop = _prop;
 }
 static void _hoc_setdata() {
 Prop *_prop, *hoc_getdata_range(int);
 _prop = hoc_getdata_range(_mechtype);
   _setdata(_prop);
 hoc_retpushx(1.);
}
 /* connect user functions to hoc names */
 static VoidFunc hoc_intfunc[] = {
 "setdata_skkin", _hoc_setdata,
 0, 0
};
 /* declare global and static user variables */
#define cai0 cai0_skkin
 double cai0 = 5e-05;
#define kbo kbo_skkin
 double kbo = 0.4;
#define kfo kfo_skkin
 double kfo = 0.6;
#define kb kb_skkin
 double kb = 0.0005;
#define kf kf_skkin
 double kf = 1e-05;
 /* some parameters have upper and lower limits */
 static HocParmLimits _hoc_parm_limits[] = {
 0,0,0
};
 static HocParmUnits _hoc_parm_units[] = {
 "cai0_skkin", "mM",
 "kf_skkin", "mM/ms",
 "kb_skkin", "/ms",
 "kfo_skkin", "/ms",
 "kbo_skkin", "/ms",
 "gbar_skkin", "mho/cm2",
 "g_skkin", "mho/cm2",
 0,0
};
 static double calcm0 = 0;
 static double ca4c0 = 0;
 static double ca3c0 = 0;
 static double ca2c0 = 0;
 static double cac0 = 0;
 static double c0 = 0;
 static double delta_t = 0.01;
 static double o0 = 0;
 /* connect global user variables to hoc */
 static DoubScal hoc_scdoub[] = {
 "cai0_skkin", &cai0_skkin,
 "kf_skkin", &kf_skkin,
 "kb_skkin", &kb_skkin,
 "kfo_skkin", &kfo_skkin,
 "kbo_skkin", &kbo_skkin,
 0,0
};
 static DoubVec hoc_vdoub[] = {
 0,0,0
};
 static double _sav_indep;
 static void nrn_alloc(Prop*);
static void  nrn_init(NrnThread*, _Memb_list*, int);
static void nrn_state(NrnThread*, _Memb_list*, int);
 static void nrn_cur(NrnThread*, _Memb_list*, int);
static void  nrn_jacob(NrnThread*, _Memb_list*, int);
 
static int _ode_count(int);
static void _ode_map(int, double**, double**, double*, Datum*, double*, int);
static void _ode_spec(NrnThread*, _Memb_list*, int);
static void _ode_matsol(NrnThread*, _Memb_list*, int);
 
#define _cvode_ieq _ppvar[4]._i
 static void _ode_matsol_instance1(_threadargsproto_);
 /* connect range variables in _p that hoc is supposed to know about */
 static const char *_mechanism[] = {
 "7.7.0",
"skkin",
 "gbar_skkin",
 0,
 "g_skkin",
 0,
 "c_skkin",
 "cac_skkin",
 "ca2c_skkin",
 "ca3c_skkin",
 "ca4c_skkin",
 "o_skkin",
 "calcm_skkin",
 0,
 0};
 static Symbol* _k_sym;
 static Symbol* _ca_sym;
 
extern Prop* need_memb(Symbol*);

static void nrn_alloc(Prop* _prop) {
	Prop *prop_ion;
	double *_p; Datum *_ppvar;
 	_p = nrn_prop_data_alloc(_mechtype, 21, _prop);
 	/*initialize range parameters*/
 	gbar = 33;
 	_prop->param = _p;
 	_prop->param_size = 21;
 	_ppvar = nrn_prop_datum_alloc(_mechtype, 5, _prop);
 	_prop->dparam = _ppvar;
 	/*connect ionic variables to this model*/
 prop_ion = need_memb(_k_sym);
 nrn_promote(prop_ion, 0, 1);
 	_ppvar[0]._pval = &prop_ion->param[0]; /* ek */
 	_ppvar[1]._pval = &prop_ion->param[3]; /* ik */
 	_ppvar[2]._pval = &prop_ion->param[4]; /* _ion_dikdv */
 prop_ion = need_memb(_ca_sym);
 nrn_promote(prop_ion, 1, 0);
 	_ppvar[3]._pval = &prop_ion->param[1]; /* cai */
 
}
 static void _initlists();
  /* some states have an absolute tolerance */
 static Symbol** _atollist;
 static HocStateTolerance _hoc_state_tol[] = {
 0,0
};
 static void _thread_cleanup(Datum*);
 static void _update_ion_pointer(Datum*);
 extern Symbol* hoc_lookup(const char*);
extern void _nrn_thread_reg(int, int, void(*)(Datum*));
extern void _nrn_thread_table_reg(int, void(*)(double*, Datum*, Datum*, NrnThread*, int));
extern void hoc_register_tolerance(int, HocStateTolerance*, Symbol***);
extern void _cvode_abstol( Symbol**, double*, int);

 void _skkin_reg() {
	int _vectorized = 1;
  _initlists();
 	ion_reg("k", -10000.);
 	ion_reg("ca", -10000.);
 	_k_sym = hoc_lookup("k_ion");
 	_ca_sym = hoc_lookup("ca_ion");
 	register_mech(_mechanism, nrn_alloc,nrn_cur, nrn_jacob, nrn_state, nrn_init, hoc_nrnpointerindex, 3);
  _extcall_thread = (Datum*)ecalloc(2, sizeof(Datum));
 _mechtype = nrn_get_mechtype(_mechanism[1]);
     _nrn_setdata_reg(_mechtype, _setdata);
     _nrn_thread_reg(_mechtype, 0, _thread_cleanup);
     _nrn_thread_reg(_mechtype, 2, _update_ion_pointer);
 #if NMODL_TEXT
  hoc_reg_nmodl_text(_mechtype, nmodl_file_text);
  hoc_reg_nmodl_filename(_mechtype, nmodl_filename);
#endif
  hoc_register_prop_size(_mechtype, 21, 5);
  hoc_register_dparam_semantics(_mechtype, 0, "k_ion");
  hoc_register_dparam_semantics(_mechtype, 1, "k_ion");
  hoc_register_dparam_semantics(_mechtype, 2, "k_ion");
  hoc_register_dparam_semantics(_mechtype, 3, "ca_ion");
  hoc_register_dparam_semantics(_mechtype, 4, "cvodeieq");
 	hoc_register_cvode(_mechtype, _ode_count, _ode_map, _ode_spec, _ode_matsol);
 	hoc_register_tolerance(_mechtype, _hoc_state_tol, &_atollist);
 	hoc_register_var(hoc_scdoub, hoc_vdoub, hoc_intfunc);
 	ivoc_help("help ?1 skkin /Users/rishi/OneDrive - Indian Institute of Science/Work/PlaceCellInformation/All codes/Mod Files/skkin.mod\n");
 hoc_register_limits(_mechtype, _hoc_parm_limits);
 hoc_register_units(_mechtype, _hoc_parm_units);
 }
static int _reset;
static char *modelname = "";

static int error;
static int _ninits = 0;
static int _match_recurse=1;
static void _modl_cleanup(){ _match_recurse=1;}
 
#define _MATELM1(_row,_col) *(_nrn_thread_getelm(_so, _row + 1, _col + 1))
 
#define _RHS1(_arg) _rhs[_arg+1]
  static int _cvspth1 = 1;
 
static int _ode_spec1(_threadargsproto_);
/*static int _ode_matsol1(_threadargsproto_);*/
 extern double *_nrn_thread_getelm(SparseObj*, int, int);
 
#define _MATELM1(_row,_col) *(_nrn_thread_getelm(_so, _row + 1, _col + 1))
 
#define _RHS1(_arg) _rhs[_arg+1]
  
#define _linmat1  0
 static int _spth1 = 0;
 static int _slist1[7], _dlist1[7]; static double *_temp1;
 static int kin();
 
static int kin (void* _so, double* _rhs, double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt)
 {int _reset=0;
 {
   double b_flux, f_flux, _term; int _i;
 {int _i; double _dt1 = 1.0/dt;
for(_i=1;_i<7;_i++){
  	_RHS1(_i) = -_dt1*(_p[_slist1[_i]] - _p[_dlist1[_i]]);
	_MATELM1(_i, _i) = _dt1;
      
} }
 /* ~ c + calcm <-> cac ( 4.0 * kf , kb )*/
 f_flux =  4.0 * kf * calcm * c ;
 b_flux =  kb * cac ;
 _RHS1( 1) -= (f_flux - b_flux);
 _RHS1( 6) -= (f_flux - b_flux);
 _RHS1( 5) += (f_flux - b_flux);
 
 _term =  4.0 * kf * c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 6 ,1)  += _term;
 _MATELM1( 5 ,1)  -= _term;
 _term =  4.0 * kf * calcm ;
 _MATELM1( 1 ,6)  += _term;
 _MATELM1( 6 ,6)  += _term;
 _MATELM1( 5 ,6)  -= _term;
 _term =  kb ;
 _MATELM1( 1 ,5)  -= _term;
 _MATELM1( 6 ,5)  -= _term;
 _MATELM1( 5 ,5)  += _term;
 /*REACTION*/
  /* ~ cac + calcm <-> ca2c ( 3.0 * kf , 2.0 * kb )*/
 f_flux =  3.0 * kf * calcm * cac ;
 b_flux =  2.0 * kb * ca2c ;
 _RHS1( 1) -= (f_flux - b_flux);
 _RHS1( 5) -= (f_flux - b_flux);
 _RHS1( 4) += (f_flux - b_flux);
 
 _term =  3.0 * kf * cac ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 5 ,1)  += _term;
 _MATELM1( 4 ,1)  -= _term;
 _term =  3.0 * kf * calcm ;
 _MATELM1( 1 ,5)  += _term;
 _MATELM1( 5 ,5)  += _term;
 _MATELM1( 4 ,5)  -= _term;
 _term =  2.0 * kb ;
 _MATELM1( 1 ,4)  -= _term;
 _MATELM1( 5 ,4)  -= _term;
 _MATELM1( 4 ,4)  += _term;
 /*REACTION*/
  /* ~ ca2c + calcm <-> ca3c ( 2.0 * kf , 3.0 * kb )*/
 f_flux =  2.0 * kf * calcm * ca2c ;
 b_flux =  3.0 * kb * ca3c ;
 _RHS1( 1) -= (f_flux - b_flux);
 _RHS1( 4) -= (f_flux - b_flux);
 _RHS1( 3) += (f_flux - b_flux);
 
 _term =  2.0 * kf * ca2c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 4 ,1)  += _term;
 _MATELM1( 3 ,1)  -= _term;
 _term =  2.0 * kf * calcm ;
 _MATELM1( 1 ,4)  += _term;
 _MATELM1( 4 ,4)  += _term;
 _MATELM1( 3 ,4)  -= _term;
 _term =  3.0 * kb ;
 _MATELM1( 1 ,3)  -= _term;
 _MATELM1( 4 ,3)  -= _term;
 _MATELM1( 3 ,3)  += _term;
 /*REACTION*/
  /* ~ ca3c + calcm <-> ca4c ( kf , 4.0 * kb )*/
 f_flux =  kf * calcm * ca3c ;
 b_flux =  4.0 * kb * ca4c ;
 _RHS1( 1) -= (f_flux - b_flux);
 _RHS1( 3) -= (f_flux - b_flux);
 _RHS1( 2) += (f_flux - b_flux);
 
 _term =  kf * ca3c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 3 ,1)  += _term;
 _MATELM1( 2 ,1)  -= _term;
 _term =  kf * calcm ;
 _MATELM1( 1 ,3)  += _term;
 _MATELM1( 3 ,3)  += _term;
 _MATELM1( 2 ,3)  -= _term;
 _term =  4.0 * kb ;
 _MATELM1( 1 ,2)  -= _term;
 _MATELM1( 3 ,2)  -= _term;
 _MATELM1( 2 ,2)  += _term;
 /*REACTION*/
  /* ~ ca4c <-> o ( kfo , kbo )*/
 f_flux =  kfo * ca4c ;
 b_flux =  kbo * o ;
 _RHS1( 2) -= (f_flux - b_flux);
 
 _term =  kfo ;
 _MATELM1( 2 ,2)  += _term;
 _term =  kbo ;
 _MATELM1( 2 ,0)  -= _term;
 /*REACTION*/
   /* c + cac + ca2c + ca3c + ca4c + o = 1.0 */
 _RHS1(0) =  1.0;
 _MATELM1(0, 0) = 1;
 _RHS1(0) -= o ;
 _MATELM1(0, 2) = 1;
 _RHS1(0) -= ca4c ;
 _MATELM1(0, 3) = 1;
 _RHS1(0) -= ca3c ;
 _MATELM1(0, 4) = 1;
 _RHS1(0) -= ca2c ;
 _MATELM1(0, 5) = 1;
 _RHS1(0) -= cac ;
 _MATELM1(0, 6) = 1;
 _RHS1(0) -= c ;
 /*CONSERVATION*/
   } return _reset;
 }
 
/*CVODE ode begin*/
 static int _ode_spec1(double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt) {int _reset=0;{
 double b_flux, f_flux, _term; int _i;
 {int _i; for(_i=0;_i<7;_i++) _p[_dlist1[_i]] = 0.0;}
 /* ~ c + calcm <-> cac ( 4.0 * kf , kb )*/
 f_flux =  4.0 * kf * calcm * c ;
 b_flux =  kb * cac ;
 Dcalcm -= (f_flux - b_flux);
 Dc -= (f_flux - b_flux);
 Dcac += (f_flux - b_flux);
 
 /*REACTION*/
  /* ~ cac + calcm <-> ca2c ( 3.0 * kf , 2.0 * kb )*/
 f_flux =  3.0 * kf * calcm * cac ;
 b_flux =  2.0 * kb * ca2c ;
 Dcalcm -= (f_flux - b_flux);
 Dcac -= (f_flux - b_flux);
 Dca2c += (f_flux - b_flux);
 
 /*REACTION*/
  /* ~ ca2c + calcm <-> ca3c ( 2.0 * kf , 3.0 * kb )*/
 f_flux =  2.0 * kf * calcm * ca2c ;
 b_flux =  3.0 * kb * ca3c ;
 Dcalcm -= (f_flux - b_flux);
 Dca2c -= (f_flux - b_flux);
 Dca3c += (f_flux - b_flux);
 
 /*REACTION*/
  /* ~ ca3c + calcm <-> ca4c ( kf , 4.0 * kb )*/
 f_flux =  kf * calcm * ca3c ;
 b_flux =  4.0 * kb * ca4c ;
 Dcalcm -= (f_flux - b_flux);
 Dca3c -= (f_flux - b_flux);
 Dca4c += (f_flux - b_flux);
 
 /*REACTION*/
  /* ~ ca4c <-> o ( kfo , kbo )*/
 f_flux =  kfo * ca4c ;
 b_flux =  kbo * o ;
 Dca4c -= (f_flux - b_flux);
 Do += (f_flux - b_flux);
 
 /*REACTION*/
   /* c + cac + ca2c + ca3c + ca4c + o = 1.0 */
 /*CONSERVATION*/
   } return _reset;
 }
 
/*CVODE matsol*/
 static int _ode_matsol1(void* _so, double* _rhs, double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt) {int _reset=0;{
 double b_flux, f_flux, _term; int _i;
   b_flux = f_flux = 0.;
 {int _i; double _dt1 = 1.0/dt;
for(_i=0;_i<7;_i++){
  	_RHS1(_i) = _dt1*(_p[_dlist1[_i]]);
	_MATELM1(_i, _i) = _dt1;
      
} }
 /* ~ c + calcm <-> cac ( 4.0 * kf , kb )*/
 _term =  4.0 * kf * c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 6 ,1)  += _term;
 _MATELM1( 5 ,1)  -= _term;
 _term =  4.0 * kf * calcm ;
 _MATELM1( 1 ,6)  += _term;
 _MATELM1( 6 ,6)  += _term;
 _MATELM1( 5 ,6)  -= _term;
 _term =  kb ;
 _MATELM1( 1 ,5)  -= _term;
 _MATELM1( 6 ,5)  -= _term;
 _MATELM1( 5 ,5)  += _term;
 /*REACTION*/
  /* ~ cac + calcm <-> ca2c ( 3.0 * kf , 2.0 * kb )*/
 _term =  3.0 * kf * cac ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 5 ,1)  += _term;
 _MATELM1( 4 ,1)  -= _term;
 _term =  3.0 * kf * calcm ;
 _MATELM1( 1 ,5)  += _term;
 _MATELM1( 5 ,5)  += _term;
 _MATELM1( 4 ,5)  -= _term;
 _term =  2.0 * kb ;
 _MATELM1( 1 ,4)  -= _term;
 _MATELM1( 5 ,4)  -= _term;
 _MATELM1( 4 ,4)  += _term;
 /*REACTION*/
  /* ~ ca2c + calcm <-> ca3c ( 2.0 * kf , 3.0 * kb )*/
 _term =  2.0 * kf * ca2c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 4 ,1)  += _term;
 _MATELM1( 3 ,1)  -= _term;
 _term =  2.0 * kf * calcm ;
 _MATELM1( 1 ,4)  += _term;
 _MATELM1( 4 ,4)  += _term;
 _MATELM1( 3 ,4)  -= _term;
 _term =  3.0 * kb ;
 _MATELM1( 1 ,3)  -= _term;
 _MATELM1( 4 ,3)  -= _term;
 _MATELM1( 3 ,3)  += _term;
 /*REACTION*/
  /* ~ ca3c + calcm <-> ca4c ( kf , 4.0 * kb )*/
 _term =  kf * ca3c ;
 _MATELM1( 1 ,1)  += _term;
 _MATELM1( 3 ,1)  += _term;
 _MATELM1( 2 ,1)  -= _term;
 _term =  kf * calcm ;
 _MATELM1( 1 ,3)  += _term;
 _MATELM1( 3 ,3)  += _term;
 _MATELM1( 2 ,3)  -= _term;
 _term =  4.0 * kb ;
 _MATELM1( 1 ,2)  -= _term;
 _MATELM1( 3 ,2)  -= _term;
 _MATELM1( 2 ,2)  += _term;
 /*REACTION*/
  /* ~ ca4c <-> o ( kfo , kbo )*/
 _term =  kfo ;
 _MATELM1( 2 ,2)  += _term;
 _MATELM1( 0 ,2)  -= _term;
 _term =  kbo ;
 _MATELM1( 2 ,0)  -= _term;
 _MATELM1( 0 ,0)  += _term;
 /*REACTION*/
   /* c + cac + ca2c + ca3c + ca4c + o = 1.0 */
 /*CONSERVATION*/
   } return _reset;
 }
 
/*CVODE end*/
 
static int _ode_count(int _type){ return 7;}
 
static void _ode_spec(NrnThread* _nt, _Memb_list* _ml, int _type) {
   double* _p; Datum* _ppvar; Datum* _thread;
   Node* _nd; double _v; int _iml, _cntml;
  _cntml = _ml->_nodecount;
  _thread = _ml->_thread;
  for (_iml = 0; _iml < _cntml; ++_iml) {
    _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
    _nd = _ml->_nodelist[_iml];
    v = NODEV(_nd);
  ek = _ion_ek;
  cai = _ion_cai;
     _ode_spec1 (_p, _ppvar, _thread, _nt);
  }}
 
static void _ode_map(int _ieq, double** _pv, double** _pvdot, double* _pp, Datum* _ppd, double* _atol, int _type) { 
	double* _p; Datum* _ppvar;
 	int _i; _p = _pp; _ppvar = _ppd;
	_cvode_ieq = _ieq;
	for (_i=0; _i < 7; ++_i) {
		_pv[_i] = _pp + _slist1[_i];  _pvdot[_i] = _pp + _dlist1[_i];
		_cvode_abstol(_atollist, _atol, _i);
	}
 }
 
static void _ode_matsol_instance1(_threadargsproto_) {
 _cvode_sparse_thread(&_thread[_cvspth1]._pvoid, 7, _dlist1, _p, _ode_matsol1, _ppvar, _thread, _nt);
 }
 
static void _ode_matsol(NrnThread* _nt, _Memb_list* _ml, int _type) {
   double* _p; Datum* _ppvar; Datum* _thread;
   Node* _nd; double _v; int _iml, _cntml;
  _cntml = _ml->_nodecount;
  _thread = _ml->_thread;
  for (_iml = 0; _iml < _cntml; ++_iml) {
    _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
    _nd = _ml->_nodelist[_iml];
    v = NODEV(_nd);
  ek = _ion_ek;
  cai = _ion_cai;
 _ode_matsol_instance1(_threadargs_);
 }}
 
static void _thread_cleanup(Datum* _thread) {
   _nrn_destroy_sparseobj_thread(_thread[_spth1]._pvoid);
   _nrn_destroy_sparseobj_thread(_thread[_cvspth1]._pvoid);
 }
 extern void nrn_update_ion_pointer(Symbol*, Datum*, int, int);
 static void _update_ion_pointer(Datum* _ppvar) {
   nrn_update_ion_pointer(_k_sym, _ppvar, 0, 0);
   nrn_update_ion_pointer(_k_sym, _ppvar, 1, 3);
   nrn_update_ion_pointer(_k_sym, _ppvar, 2, 4);
   nrn_update_ion_pointer(_ca_sym, _ppvar, 3, 1);
 }

static void initmodel(double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt) {
  int _i; double _save;{
  calcm = calcm0;
  ca4c = ca4c0;
  ca3c = ca3c0;
  ca2c = ca2c0;
  cac = cac0;
  c = c0;
  o = o0;
 {
   calcm = cai0 * 1e6 ;
    _ss_sparse_thread(&_thread[_spth1]._pvoid, 7, _slist1, _dlist1, _p, &t, dt, kin, _linmat1, _ppvar, _thread, _nt);
     if (secondorder) {
    int _i;
    for (_i = 0; _i < 7; ++_i) {
      _p[_slist1[_i]] += dt*_p[_dlist1[_i]];
    }}
 }
 
}
}

static void nrn_init(NrnThread* _nt, _Memb_list* _ml, int _type){
double* _p; Datum* _ppvar; Datum* _thread;
Node *_nd; double _v; int* _ni; int _iml, _cntml;
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
_thread = _ml->_thread;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
#if CACHEVEC
  if (use_cachevec) {
    _v = VEC_V(_ni[_iml]);
  }else
#endif
  {
    _nd = _ml->_nodelist[_iml];
    _v = NODEV(_nd);
  }
 v = _v;
  ek = _ion_ek;
  cai = _ion_cai;
 initmodel(_p, _ppvar, _thread, _nt);
 }
}

static double _nrn_current(double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt, double _v){double _current=0.;v=_v;{ {
   calcm = cai * 1e6 ;
   g = gbar * o ;
   ik = g * ( v - ek ) ;
   }
 _current += ik;

} return _current;
}

static void nrn_cur(NrnThread* _nt, _Memb_list* _ml, int _type) {
double* _p; Datum* _ppvar; Datum* _thread;
Node *_nd; int* _ni; double _rhs, _v; int _iml, _cntml;
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
_thread = _ml->_thread;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
#if CACHEVEC
  if (use_cachevec) {
    _v = VEC_V(_ni[_iml]);
  }else
#endif
  {
    _nd = _ml->_nodelist[_iml];
    _v = NODEV(_nd);
  }
  ek = _ion_ek;
  cai = _ion_cai;
 _g = _nrn_current(_p, _ppvar, _thread, _nt, _v + .001);
 	{ double _dik;
  _dik = ik;
 _rhs = _nrn_current(_p, _ppvar, _thread, _nt, _v);
  _ion_dikdv += (_dik - ik)/.001 ;
 	}
 _g = (_g - _rhs)/.001;
  _ion_ik += ik ;
#if CACHEVEC
  if (use_cachevec) {
	VEC_RHS(_ni[_iml]) -= _rhs;
  }else
#endif
  {
	NODERHS(_nd) -= _rhs;
  }
 
}
 
}

static void nrn_jacob(NrnThread* _nt, _Memb_list* _ml, int _type) {
double* _p; Datum* _ppvar; Datum* _thread;
Node *_nd; int* _ni; int _iml, _cntml;
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
_thread = _ml->_thread;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml];
#if CACHEVEC
  if (use_cachevec) {
	VEC_D(_ni[_iml]) += _g;
  }else
#endif
  {
     _nd = _ml->_nodelist[_iml];
	NODED(_nd) += _g;
  }
 
}
 
}

static void nrn_state(NrnThread* _nt, _Memb_list* _ml, int _type) {
double* _p; Datum* _ppvar; Datum* _thread;
Node *_nd; double _v = 0.0; int* _ni; int _iml, _cntml;
double _dtsav = dt;
if (secondorder) { dt *= 0.5; }
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
_thread = _ml->_thread;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
 _nd = _ml->_nodelist[_iml];
#if CACHEVEC
  if (use_cachevec) {
    _v = VEC_V(_ni[_iml]);
  }else
#endif
  {
    _nd = _ml->_nodelist[_iml];
    _v = NODEV(_nd);
  }
 v=_v;
{
  ek = _ion_ek;
  cai = _ion_cai;
 {  sparse_thread(&_thread[_spth1]._pvoid, 7, _slist1, _dlist1, _p, &t, dt, kin, _linmat1, _ppvar, _thread, _nt);
     if (secondorder) {
    int _i;
    for (_i = 0; _i < 7; ++_i) {
      _p[_slist1[_i]] += dt*_p[_dlist1[_i]];
    }}
 } }}
 dt = _dtsav;
}

static void terminal(){}

static void _initlists(){
 double _x; double* _p = &_x;
 int _i; static int _first = 1;
  if (!_first) return;
 _slist1[0] = o_columnindex;  _dlist1[0] = Do_columnindex;
 _slist1[1] = calcm_columnindex;  _dlist1[1] = Dcalcm_columnindex;
 _slist1[2] = ca4c_columnindex;  _dlist1[2] = Dca4c_columnindex;
 _slist1[3] = ca3c_columnindex;  _dlist1[3] = Dca3c_columnindex;
 _slist1[4] = ca2c_columnindex;  _dlist1[4] = Dca2c_columnindex;
 _slist1[5] = cac_columnindex;  _dlist1[5] = Dcac_columnindex;
 _slist1[6] = c_columnindex;  _dlist1[6] = Dc_columnindex;
_first = 0;
}

#if defined(__cplusplus)
} /* extern "C" */
#endif

#if NMODL_TEXT
static const char* nmodl_filename = "/Users/rishi/OneDrive - Indian Institute of Science/Work/PlaceCellInformation/All codes/Mod Files/skkin.mod";
static const char* nmodl_file_text = 
  ": Sah P, Clements JD (1999) Photolytic manipulation of [Ca2+]i \n"
  ": reveals slow kinetics of potassium channels underlying the \n"
  ": afterhyperpolarization in hippocampal pyramidal neurons. \n"
  ": J  Neurosci 19:3657-3664.\n"
  "\n"
  ": Sah P, Isaacson JS (1995) Channels underlying the slow \n"
  ": afterhyperpolarization in hippocampal pyramidal neurons: \n"
  ": neurotransmitters modulate the open probability. Neuron 15:435-441.\n"
  "\n"
  "NEURON {\n"
  "	SUFFIX skkin\n"
  "	USEION k READ ek WRITE ik\n"
  "    USEION ca READ cai\n"
  "	RANGE g, gbar\n"
  "}\n"
  "\n"
  "UNITS { \n"
  "	(mA) = (milliamp)\n"
  "	(mV) = (millivolt)\n"
  " 	(molar) = (1/liter)\n"
  "  	(uM)    = (micromolar)\n"
  "  	(mM)    = (millimolar)\n"
  "}\n"
  "\n"
  "PARAMETER {\n"
  "	cai0 = 50e-6  (mM)\n"
  "	gbar = 33     (mho/cm2)\n"
  "	kf   = 10e-6  (mM/ms) : 10 microM/s = 10e-6 mM/ms\n"
  "	kb   = 0.5e-3 (/ms)   : 0.5 /s = 0.5e-3 /ms\n"
  "	kfo  = 600e-3 (/ms)   : 600 /s = 600e-3 /ms\n"
  "	kbo  = 400e-3 (/ms)   : 400 /s = 400e-3 /ms\n"
  "}\n"
  "\n"
  "ASSIGNED {\n"
  "	v    (mV)\n"
  "	ek   (mV)\n"
  "	g    (mho/cm2)\n"
  "	ik   (amp/cm2)\n"
  "	cai  (mM)\n"
  "}\n"
  "\n"
  "STATE { \n"
  "	c cac ca2c ca3c ca4c o calcm\n"
  "}\n"
  "\n"
  "INITIAL { \n"
  "	calcm=cai0 * 1e6\n"
  "	SOLVE kin STEADYSTATE sparse \n"
  "}\n"
  "\n"
  "BREAKPOINT {\n"
  "	calcm=cai * 1e6\n"
  "	SOLVE kin METHOD sparse\n"
  "	g = gbar*o\n"
  "	ik = g*(v - ek)\n"
  "}\n"
  "\n"
  "\n"
  "KINETIC kin {\n"
  "	~ c + calcm 	<-> cac  (4*kf, kb)\n"
  "	~ cac + calcm 	<-> ca2c (3*kf, 2*kb)\n"
  "	~ ca2c + calcm 	<-> ca3c (2*kf, 3*kb)\n"
  "	~ ca3c + calcm 	<-> ca4c (kf, 4*kb)\n"
  "	~ ca4c 		<-> o	 (kfo, kbo)\n"
  "	CONSERVE c + cac + ca2c + ca3c + ca4c + o = 1\n"
  "}\n"
  "\n"
  ;
#endif
