//genesis - Purkinje cell M9 genesis2 script
// modified from Purk_chansave.g

include defaults.g
include Purk_const
include Purk_chansave.g

float Ishift = 0.01 // -0.003 // 0 // - 0.001 // 0 // 0.001
float Ashift = 0 // 0.001 // 0 // 0.001

str label = "I+10"
str Amaxfile = {"Purk_CaTshift" @ label @ "mV_a_max_37.test"} 
str Ataufile = {"Purk_CaTshift" @ label @ "mV_a_tau_37.test"}
str Imaxfile = {"Purk_CaTshift" @ label @ "mV_i_max_37.test"}
str Itaufile = {"Purk_CaTshift" @ label @ "mV_i_tau_37.test"}


    make_chan Purk_CaT {ECa} {GCa} \ 
              1  2.60e3   0.0 1.0 {0.021   - Ashift}   -8.0e-3  \
                 0.180e3  0.0 1.0 {0.040   - Ashift}    4.0e-3  \
              1  0.0025e3 0.0 1.0 {0.040   - Ishift}    8.0e-3  \
                 0.190e3  0.0 1.0 {0.050   - Ishift}  -10.0e-3  \
              0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
    call Purk_CaT TABSAVE {"Purk_CaTshift" @ label @ "mV.tab"}


    float x, dx, a, b
    int i

        x = {tab_xmin}
//        dx = ({tab_xmax} - {tab_xmin})/{tab_xdivs + 1}
        dx = ({tab_xmax} - {tab_xmin})/{tab_xdivs}

        openfile {Amaxfile}  w
        openfile {Ataufile}  w
        openfile {Imaxfile}  w
        openfile {Itaufile}  w

//        for (i = 0; i <= {tab_xfills}; i = {i + 20})
        for (i = 0; i <= {tab_xfills}; i = {i + 1})

                a = {getfield Purk_CaT X_A->table[{i}]}
                b = {getfield Purk_CaT X_B->table[{i}]}

                writefile {Amaxfile}  {x} {a / b}
                writefile {Ataufile}  {x} {1 / b}

                a = {getfield Purk_CaT Y_A->table[{i}]}
                b = {getfield Purk_CaT Y_B->table[{i}]}

                writefile {Imaxfile}  {x} {a / b}
                writefile {Itaufile}  {x} {1 / b}

                x = {x + dx}
        end

        closefile {Amaxfile}
        closefile {Ataufile}
        closefile {Imaxfile}
        closefile {Itaufile}