// genesis

int number_of_neurons, lb, ub
int msgcount 
int i, j, nsynapses, GABAsender_index
str list, name, GABAsender, indexstr 
str output
int startchar, endchar


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

  number_of_neurons =  800 // 400 // 500 // 840 // 84 // 50 // 84 // 50 
  lb = 361 // 441
  ub = 380 // 460

  list = ""
  output = "stc-AffGABAsynapses_" @ {lb} @ "-" @ {ub} @ ".dat"
  echo {output}

  create neutral /library/Aff_innervation_array
  createmap /library/Aff_innervation_array / {number_of_neurons} 1

  setfield /Aff_innervation_array[] x 0

  for (i = {lb}; {i <= ub}; i = i + 1)

       foreach name ({el /molecular_layer/Stellate[{i-1}]/##[][TYPE=compartment]/GABAA})

             msgcount = {getsyncount {name}}  
             echo {i} {name} {msgcount}

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

                 GABAsender = {getsynsrc {name} {j}}

                 startchar = {findchar {GABAsender} [}
                 endchar = {findchar {GABAsender} ]}

    echo   {GABAsender} {startchar} {endchar}

                 if ({startchar > 0})
                           GABAsender_index = {{substring {GABAsender} {startchar + 1} {endchar - 1}}}
                 else GABAsender_index = 0
                 end // if
                 echo GABAsenser_index {GABAsender_index}

                 echo old {getfield /Aff_innervation_array[{GABAsender_index}] x}
                 setfield /Aff_innervation_array[{GABAsender_index}] x {{getfield /Aff_innervation_array[{GABAsender_index}] x} + 1}
                 echo new {getfield /Aff_innervation_array[{GABAsender_index}] x}
              end // for

       end // foreach
  end // for

  for (i = 0; {i < number_of_neurons}; i = i + 1)
       list = (list) @ {i} @ " " @ {getfield /Aff_innervation_array[{i}] x} @ " " @ {chr 10}

  end
  echo {list}  > {output}