//genesis postpro.g // postprocessor for selecting first positive Vm from CPG_Rev // (defines firing time as first positive Vm) // make a first pass thru VmL1 to count lines openfile VmL1 r int x = 0 while (!{eof VmL1}) readfile VmL1 x = x + 1 end closefile VmL1 // measure an output interval openfile VmL1 r float t1 = {getarg {readfile VmL1} -arg 1} float t2 = {getarg {readfile VmL1} -arg 1} float outint = {t2 - t1} // select first positive VmL1 for each action potential, & write to VmL1x floatformat %09.5f float preVm = 0 //previous Vm will be saved for interpolation of step int k = 0 function processline float step = {argv 1} float Vm = {argv 2} if ((Vm > 0) && (preVm <= 0)) writefile VmL1x {step} {Vm} {preVm} k = k + 1 end preVm = Vm end openfile VmL1x w openfile VmL1 r int i = 1 while (i < x) processline {readfile VmL1} i = i + 1 end closefile VmL1 closefile VmL1x // select first positive VmR1 for each action potential, & write to VmR1x float preVm = 0 int l = 0 function processline float step = {argv 1} float Vm = {argv 2} if ((Vm > 0) && (preVm <= 0)) writefile VmR1x {step} {Vm} {preVm} l = l + 1 end preVm = Vm end openfile VmR1x w openfile VmR1 r int i = 1 while (i < x) processline {readfile VmR1} i = i + 1 end closefile VmR1 closefile VmR1x // select first positive VmL2 for each action potential, & write to VmL2x float preVm = 0 int m = 0 function processline float step = {argv 1} float Vm = {argv 2} if ((Vm > 0) && (preVm <= 0)) writefile VmL2x {step} {Vm} {preVm} m = m + 1 end preVm = Vm end openfile VmL2x w openfile VmL2 r int i = 1 while (i < x) processline {readfile VmL2} i = i + 1 end closefile VmL2 closefile VmL2x // select first positive VmR2 for each action potential, & write to VmR2x float preVm = 0 int n = 0 function processline float step = {argv 1} float Vm = {argv 2} if ((Vm > 0) && (preVm <= 0)) writefile VmR2x {step} {Vm} {preVm} n = n + 1 end preVm = Vm end openfile VmR2x w openfile VmR2 r int i = 1 while (i < x) processline {readfile VmR2} i = i + 1 end closefile VmR2 closefile VmR2x // combine VmL1x, VmR1x, VmL2x, & VmR2x in Vmy openfile VmL1x r openfile VmR1x r openfile VmL2x r openfile VmR2x r openfile Vmy w float preVm = 0 function processlineL1 float step = {argv 1} float Vm = {argv 2} float preVm = {argv 3} writefile Vmy {step - ((Vm / (Vm - preVm)) * outint)} \ " L1 fires " end int i = 0 while ((i <= (k - 1)) && (((k - 1) != 0) || (k == 1))) processlineL1 {readfile VmL1x} i = i + 1 end closefile Vmy openfile Vmy a function processlineR1 float step = {argv 1} float Vm = {argv 2} float preVm = {argv 3} writefile Vmy {step - ((Vm / (Vm - preVm)) * outint)} \ " R1 fires " end int i = 0 while ((i <= (l - 1)) && (((l - 1) != 0) || (l == 1))) processlineR1 {readfile VmR1x} i = i + 1 end function processlineL2 float step = {argv 1} float Vm = {argv 2} float preVm = {argv 3} writefile Vmy {step - ((Vm / (Vm - preVm)) * outint)} \ " L2 fires " end int i = 0 while ((i <= (m - 1)) && (((m - 1) != 0) || (m == 1))) processlineL2 {readfile VmL2x} i = i + 1 end function processlineR2 float step = {argv 1} float Vm = {argv 2} float preVm = {argv 3} writefile Vmy {step - ((Vm / (Vm - preVm)) * outint)} \ " R2 fires " end int i = 0 while ((i <= (n - 1)) && (((n - 1) != 0) || (n == 1))) processlineR2 {readfile VmR2x} i = i + 1 end // sort to FireOrd1 closefile Vmy openfile Vmy r sort Vmy -o FireOrd1 // postprocess file FireOrd1 to yield FireOrd2 with differences openfile FireOrd1 r openfile FireOrd2 w float diff = 0 float prestep = 0 floatformat %8.4f function processline float step = {argv 1} str cell = {argv 2} diff = {step} - {prestep} writefile FireOrd2 " " {step} " " {cell} " fires "\ {diff} -n floatformat %6.3f writefile FireOrd2 " " {diff} floatformat %8.4f prestep = {step} end int i = 0 while (i < (k + l + m + n)) processline {readfile FireOrd1} i = i + 1 end