// genesis

int number_of_neurons
int msgcount 
int i, j, nsynapses
str list, name, PF_sender, grating_sender, indexstr 
str output 


// plots for each stc how many of its PF synapses are stimulated by the stimulus

  number_of_neurons = 10 // 3 // 1 // 10 //  800 // 2000 // 1200 // 800 // 400 // 500 // 840 // 84 // 50 // 84 // 50 
  list = ""
  output = "PC-ONbeamPFsynapses.dat"


  for (i = 1; {i <= number_of_neurons}; i = i + 1)

       nsynapses = 0
//       foreach name ({el /molecular_layer/Stellate[{i-1}]/##[][TYPE=compartment]/pf_AMPA})
       foreach name ({el /Purkinje_layer/Purkinje[{i-1}]/##[][TYPE=compartment]/par})
             msgcount = {getsyncount {name}}  
             echo {i} {name} {msgcount}

             for (j = 0; {j < msgcount}; j = j + 1)
//                 echo {j}

                 PF_sender = {getsynsrc {name} {j}}
//                 echo {sender}
//                 if ({{{getfield  {sender} y} >= {195e-6 + 100e-6}} && \
//                      {{getfield  {sender} y} <= {205e-6 + 100e-6}} && \
//                      {{getfield  {sender} z} >= 100e-6}} )

// next question: does this parallel fibre receive a msg from /rectangulargrating[32]?

                 grating_sender = {getmsg {PF_sender} -incoming -source 0}

//                 echo   {grating_sender}

                 if ({{strlen {grating_sender}} > 20})
                        indexstr = {substring {grating_sender} 20 {{strlen {grating_sender}} - 2}}
                        echo {indexstr}
                 end // if


//                   if ((! {strcmp  {indexstr}  "32"}) || \
//                       (! {strcmp  {indexstr}  "33"}) || \
//                       (! {strcmp  {indexstr}  "31"}) || \
//                       (! {strcmp  {indexstr}  "30"}) || \
//                       (! {strcmp  {indexstr}  "34"}))
                 if ((! {strcmp  {indexstr}  "54"}) || \ 
                     (! {strcmp  {indexstr}  "55"}) )
//                     (! {strcmp  {indexstr}  "82"}) || \ 
//                     (! {strcmp  {indexstr}  "83"}) )

//                 if ((! {strcmp  {indexstr}  "54"}))
                    nsynapses = {nsynapses} + 1
                    echo {i} {grating_sender} {indexstr}
                 end // if
             end // for

       end // foreach

       list = (list) @ {i} @ " " @ {nsynapses} @ " " @ {chr 10}
//           echo {i} {j} {sum}

  end
  echo {list}  > {output} 











