function [all_events,all_fits]=phasic_and_asynchronous_event_extractor(Imem_array,AP_times,return_all_postAP_windows,template_seeds,time_vector,template_type,taper_template,...
    trunc_templ_detec,event_thresh,event_jitter,event_aligned_extraction,event_window,baseline_offset_window1,baseline_offset_window2,fit_slope_thresh,...
    plot_sloperemovedextractions,plot_extracted_events,fit_events,fit_latency_window,return_pareddown_fitinfo,plot_fits,plot_fit_residuals)
%description: takes inputs of leak-subtracted postsynaptic current recordings and AP times from create_basic_text_file_for_asynch_rel_INa_onset after manual scaling
    %generates a template and passes the recorded data, the template and all other input arguments to the core function
    %template_seeds has 3 values: for PSC template they are amplitude_scaler,tau_rise,tau_decay (often [23.984085025960670   3.861189308388354  27.526665160068116]); 
        %for gaussian they are peak_height,center_time,bell_width (often [25 20 5])
    %time_vector, for template generation, generally 1:100
    %template_type, 1 for psc-like (standard), 2 for gaussian
    %taper_template has two elements, starttaperlength (skip if 0) and endtaperlength (skip if 0); only called if 1 || 2
        %taper_template(1)<0 is a special situation, a kind of non-taper, where abs(taper_template(1)) zeroes are prepended to the front of the template
    %trunc_templ_detec is set at zero to use the full template for detection, otherwise it, as a vector, specifies the elements of the template that will be used for (bekkers-clements) detection
%called by: command line
%calls: template_generator,phasic_and_asynchronous_event_extractor_core
%notes: all time values in samples
    %onset taper appears to increase specificity, possibly decreasing sensitivity. need to decide whether to subtract taper in the measurement of latency
    %is it desirable to find the charge and the amplitude of raw events?  amp/charge gives measure of 'phasicness,' with theoretical maximum of one
    %remove all sporadic PSCs before fitting, clustering, etc.
%code confirmed date: feb 2, 2013

tic
template=template_generator(template_seeds,time_vector,template_type,taper_template);
if any(trunc_templ_detec),template=template(trunc_templ_detec);end

all_events=[];all_fits=[];

if plot_sloperemovedextractions || plot_extracted_events || plot_fits || plot_fit_residuals
    for trial=1:size(Imem_array,2)
        [events,event_fits]=phasic_and_asynchronous_event_extractor_core(Imem_array(:,trial),AP_times(:,trial),trial,return_all_postAP_windows,template,template_seeds,...
            event_thresh,event_jitter,event_aligned_extraction,event_window,baseline_offset_window1,baseline_offset_window2,fit_slope_thresh,...
            plot_sloperemovedextractions,plot_extracted_events,fit_events,fit_latency_window,return_pareddown_fitinfo,plot_fits,plot_fit_residuals); 
        all_events=[all_events events];
        all_fits=[all_fits event_fits];
    end
else
    parfor trial=1:size(Imem_array,2)
        [events,event_fits]=phasic_and_asynchronous_event_extractor_core(Imem_array(:,trial),AP_times(:,trial),trial,return_all_postAP_windows,template,template_seeds,...
            event_thresh,event_jitter,event_aligned_extraction,event_window,baseline_offset_window1,baseline_offset_window2,fit_slope_thresh,...
            plot_sloperemovedextractions,plot_extracted_events,fit_events,fit_latency_window,return_pareddown_fitinfo,plot_fits,plot_fit_residuals);
        all_events=[all_events events];
        all_fits=[all_fits event_fits];
    end   
end
    
toc