// genesis

int number_of_neurons, nsynapses 
int i, j
float x, y, z
str list, name, output, name


/***** positions of NEURONS   *****/
/*
   number_of_neurons = 17043 // 284 // 3834 // 7100 // 142 // 7100
    list = ""
    str output = "PF_positions.dat"

    for (i = 1; {i <= number_of_neurons}; i = i + 1)
        x =  {getfield /molecular_layer/parallel_fiber[{i - 1}] x}
        y =  {getfield /molecular_layer/parallel_fiber[{i - 1}] y}
        z =  {getfield /molecular_layer/parallel_fiber[{i - 1}] z}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
    end
    echo {list}  > {output} // {source_list}
*/

/*
    number_of_neurons = 50 // 2 // 27 // 50 // 1 // 50

    list = ""
    output = "PC_positions.dat"

    for (i = 1; {i <= number_of_neurons}; i = i + 1)
        x =  {getfield /Purkinje_layer/Purkinje[{i - 1}]/soma x}
        y =  {getfield /Purkinje_layer/Purkinje[{i - 1}]/soma y}
        z =  {getfield /Purkinje_layer/Purkinje[{i - 1}]/soma z}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
    end
    echo {list}  > {output} // {source_list}
*/

    number_of_neurons = 800 // 10 // 500
    list = ""
    output = "stc-fw_positions.dat"

    for (i = 0; {i < number_of_neurons / 2}; i = i + 1)
//        nsynapses = {getsyncount /molecular_layer/interneurons_fw/Stellate[{i}]/soma/spike}
//        if ({nsynapses == 0})
          x =  {getfield /molecular_layer/Stellate[{i}]/soma x}
          y =  {getfield /molecular_layer/Stellate[{i}]/soma y}
          z =  {getfield /molecular_layer/Stellate[{i}]/soma z}
          list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
//        echo  {i}  {x}   {y}
//        end
    end
    echo {list}  > {output} // {source_list}


    list = ""
    output = "stc-bw_positions.dat"

    for (i = {number_of_neurons / 2}; {i < number_of_neurons}; i = i + 1)
//        nsynapses = {getsyncount /molecular_layer/Stellate[{i}]/soma/spike}
//        if ({nsynapses == 0})
          x =  {getfield /molecular_layer/Stellate[{i}]/soma x}
          y =  {getfield /molecular_layer/Stellate[{i}]/soma y}
          z =  {getfield /molecular_layer/Stellate[{i}]/soma z}
          list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
//        echo  {i}  {x}   {y}
//        end
    end
    echo {list}  > {output} // {source_list}

/***** positions of ELECTRODES   *****/


    list = ""
    output = "electrode_positions.dat"

       foreach name ({el /electrode_array/##[][TYPE=efield]})

          x =  {getfield {name} x}
          y =  {getfield {name} y}
          z =  {getfield {name} z}
          list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
//        echo  {i}  {x}   {y}
//        end
    end
    echo {list}  > {output} // {source_list}



/***** positions of SYNAPSES   *****/

/*
    list = ""
    output = "PC_spine_positions.dat"

//    foreach name ({el /Purkinje_layer/Purkinje/##[][TYPE=compartment]/par})
    foreach name ({el /Purkinje_layer/##[][TYPE=compartment]/par})
        z =  {getfield {name} z}
        y =  {getfield {name} y}
        x =  {getfield {name} x}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
    end
    echo {list}  > {output} // {source_list}


    list = ""
    output = "PC_stell_positions.dat"

//    foreach name ({el /Purkinje_layer/Purkinje/##[][TYPE=compartment]/stell})
    foreach name ({el /Purkinje_layer/##[][TYPE=compartment]/stell})
        z =  {getfield {name} z}
        y =  {getfield {name} y}
        x =  {getfield {name} x}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
    end
    echo {list}  > {output} // {source_list}


    list = ""
    output = "PC_stc-synapse_positions.dat"

//    foreach name ({el /Purkinje_layer/Purkinje/##[][TYPE=compartment]/stell})
    foreach name ({el /Purkinje_layer/##[][TYPE=compartment]/stell})
//        echo {name} {getfield {name} nsynapses}
        if ({{getfield {name} nsynapses} > 0})
            z =  {getfield {name} z}
            y =  {getfield {name} y}
            x =  {getfield {name} x}
//            echo  {x}  {y}  {z}
            list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
        end
    end
    echo {list}  > {output} // {source_list}



    list = ""
    output = "PC_comp_positions.dat"

//    foreach name ({el /Purkinje_layer/Purkinje/##[][TYPE=compartment]})
    foreach name ({el /Purkinje_layer/##[][TYPE=compartment]})
        x =  {getfield {name} x}
        z =  {getfield {name} z}
        y =  {getfield {name} y}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
    end
    echo {list}  > {output} // {source_list}
*/


/*

// positions of stell synapses on PCs made by a single stellate cell

  list = ""
  str output = "stell-synapse_positions.dat"

  ce /molecular_layer/Stellate[2]/soma/spike

  for (i = 0; {i < {getsyncount .}}; i = i + 1)
        name = {getsyndest . {i}}
        echo {name}
        x =  {getfield {name} x}
        z =  {getfield {name} z}
        y =  {getfield {name} y}
        list = (list) @ " " @ {x} @ " " @ {y} @ " " @ {z} @ {chr 10}
  end
  echo {list}  > {output} // {source_list}

*/