// include sine.g (already included in Parallel_fiber.g 
// include Stell_layer_const.g


/*
   create pulsegen /pulse_E
     setfield ^ delay1 10  \
                width1 0.05 \
                level1 {parallel_fiber_firing_rate * 1000} \
                baselevel {parallel_fiber_firing_rate} 
//   addmsg /pulse_E /molecular_layer/parallel_fiber[] RATE output
*/

/*
   str ascii_filename   =  "results/pulse.ascii"

   if (!({exists /output/ascii}))
          create asc_file /output/ascii
   end
   enable /output
   enable /output/ascii
   setfield /output/ascii filename {ascii_filename} \ 
           initialize 1 leave_open 1  flush 1
   echo Output to {ascii_filename}

   addmsg /pulse_E     /output/ascii SAVE output
   addmsg /pulse_E/RC  /output/ascii SAVE state
*/


/*
echo  creating sine

   create sine /sine
   setfield /sine period {2.048 / 4} // 2.048 // 0.512 // 0.25 //  {1.024} // {0.015625}
   setfield /sine amplitude {parallel_fiber_firing_rate} background_level {parallel_fiber_firing_rate}
//   addmsg /sine /white_matter/parallel_fiber[180-239] RATE output
//   addmsg /sine  /molecular_layer/parallel_fiber[] RATE output
   useclock /sine 1

*/


/*
echo creating counter phase grating

include counter-phase-grating.g

float sagittal_span = {ylength_mollayer}
float spatial_wavelength = {sagittal_span} * 2 //  / 2.0}
float temporal_wavelength = 100000 // 10 // 0.25

make_counterphasegrating  {sagittal_span} {spatial_wavelength} {temporal_wavelength}

echo   {sagittal_span} {spatial_wavelength} {temporal_wavelength}

// activate all parallel fibers at a specified position
  int  i
  int  cell_index

   for (i = 0; i < {number_parallel_fibers}; i = i + 1)

       cell_index = {round {{getfield  /molecular_layer/parallel_fiber[{i}] y} / {sagittal_span} * {number_PF_cells}}} 
      
       addmsg /counterphasegrating[{cell_index}]  /molecular_layer/parallel_fiber[{i}] RATE output
   end // for
*/

echo creating rectangular grating

include rectangular-grating.g

float sagittal_span = {ylength_mollayer}
float spatial_wavelength = {sagittal_span} * 0.5 // 1 // 2 // 2 //  / 2.0}
float temporal_wavelength = 100000 // 10 // 0.25

make_rectangulargrating  {sagittal_span} {spatial_wavelength} {temporal_wavelength}

echo   {sagittal_span} {spatial_wavelength} {temporal_wavelength}

// activate all parallel fibers at a specified position
  int  i
  int  cell_index

   for (i = 0; i < {number_parallel_fibers}; i = i + 1)

       cell_index = {round {{getfield  /molecular_layer/parallel_fiber[{i}] y} / {sagittal_span} * {number_PF_cells}}}

       addmsg /rectangulargrating[{cell_index}]  /molecular_layer/parallel_fiber[{i}] RATE output
   end // for


// make temporal patterns
/*
   create pulsegen /pulse_E
//     setfield ^ delay1 20  \
//                width1 20 \
//                level1 2 \
//                baselevel 0

     setfield ^ delay1 10  \
                width1 10 \
                level1 1 \
                baselevel 0
*/
//   addmsg /pulse_E /rectangulargrating[32] PLUS output
//   addmsg /pulse_E /rectangulargrating[33] PLUS output
//   addmsg /pulse_E /rectangulargrating[34] PLUS output
//   addmsg /pulse_E /rectangulargrating[35] PLUS output
//   addmsg /pulse_E /rectangulargrating[36] PLUS output
//   addmsg /pulse_E /rectangulargrating[64] PLUS output



/*

echo  creating second sine

   create sine /sine2
   setfield /sine2 period {2.048} //  * 0.5} // 2} //  * 8} // 4} // 2} //  * 8} // 2} //  * 4} //  * 0.25} // 4 } // 8} // 4} //  * 4} // * 2} // * 4} //  / 4 
   setfield /sine2 phase 0  background_level 0 // {parallel_fiber_firing_rate}
   setfield /sine2 amplitude {parallel_fiber_firing_rate * 0.1} // 0.2} // 0.1} // 0.125} // 0.1} // 0.5} // 0.02} // 0.1 // 1.0} // 0.05} // 0.1} 

//  addmsg /sine2 /rectangulargrating[24] PLUS output
  addmsg /sine2 /rectangulargrating[54] PLUS output
  addmsg /sine2 /rectangulargrating[55] PLUS output
//  addmsg /sine2 /rectangulargrating[81] PLUS output
//  addmsg /sine2 /rectangulargrating[82] PLUS output
//  addmsg /sine2 /rectangulargrating[83] PLUS output
//   addmsg /sine2 /rectangulargrating[8] PLUS output
   useclock /sine2 1

*/



// single pulse

   create pulsegen /pulse_E
     setfield ^ delay1 1.0  \
                width1 0.05 \
                level1 29 \
                baselevel 0
//   addmsg /pulse_E /molecular_layer/parallel_fiber[] RATE output
  addmsg /pulse_E /rectangulargrating[54] PLUS output
  addmsg /pulse_E /rectangulargrating[55] PLUS output



/*
// doublet

//   setfield   /plusONE x 0
   create pulsegen /pulse_E
     setfield ^ delay1 1  \
                width1 0.005 \
                level1 39 \
                delay2 0.015 \
                level2 39 \
                width2 0.005 \
                baselevel 0
//   addmsg /pulse_E /molecular_layer/parallel_fiber[] RATE output
  addmsg /pulse_E /rectangulargrating[32] PLUS output
*/

/*
// bipolar
   create pulsegen /pulse_E
     setfield ^ delay1 2  \
                width1 0.005 \
                level1 19 \
                delay2 0.005 \
                level2 -1 \
                width2 0.095 \
                baselevel 0
//   addmsg /pulse_E /molecular_layer/parallel_fiber[] RATE output
  addmsg /pulse_E /rectangulargrating[32] PLUS output

*/