function dwnrawreader_core_simplified(trial,ddata,patchlog_name,hy,stim_artifact_threshold,stim_artifact_jitter,IPI_jitter,raw_window,baseline_time_window,PSC_time_window,Q_time_window,...
        Q_btwn_thresholds,PSCbegin_threshold,PSCend_threshold,asynchronous_window,mcc_output_voltage_scaling_factor,samples_per_ms,permutations_of_IPIs,number_of_IPIs,possible_repetitions_of_permutation,...
        APs_in_the_train,max_length_raw,min_length_raw,metrics_of_interest,measured_ITI,real_time_mode,amillion,atrillion,samples_per_second,number_of_trials,plot_controls,save_that_sht,...
        asynch_window_fractionofsecond,minimum_possible_psc_duration)
    
%plot raw recording alone
if ~real_time_mode
    figure(1)
    plot(ddata)
    ylim([-2 1])
    title(strcat('Raw recording__',patchlog_name,'__',num2str(trial)))
    set(1,'Position',[13 54 1575 501])
end

%there will come a day in the not-too-distant future when all of us will believe in one another

OVSF_presyn=ddata(1,1);   %the same information could be had from either column
sizeddata=size(ddata)
post_oct_19_2003=1;
post_feb_11_2004=1;
if post_oct_19_2003         
    OVSF_postsyn=ddata(2,1)
    pulse_duration_presyn=ddata(3,1)
    pulse_duration_postsyn=ddata(4,1)
    sampling_rate=ddata(5,1)
    stim_philosophy=ddata(6,1)
    output_channel_to_presyn=ddata(7,1)
    ddata=ddata(8:end,:);
    if post_feb_11_2004
        temperature_during_train_mean=ddata(1,1)*10 %multiply to account for conversion factor of the heater/thermometer (.1V/degree C)
        temperature_during_train_std=ddata(2,1)*10
        ddata=ddata(3:end,:);
    else
        temperature_during_train_mean=NaN
        temperature_during_train_std=NaN
    end
else
    pulse_duration_presyn=1
    OVSF_postsyn=NaN;
    pulse_duration_postsyn=NaN;
    sampling_rate=NaN;
    output_channel_to_presyn=NaN;
    temperature_during_train_mean=NaN;
    temperature_during_train_std=NaN;
    ddata=ddata(2:end,:);
end
shrunksizeddata=size(ddata)

%converting the recorded signal, voltage from the board, into pA, by the conversion factor used by multiclamp commander
ddata=ddata*mcc_output_voltage_scaling_factor;

stim_artifact_jitter=stim_artifact_jitter*(samples_per_ms*pulse_duration_presyn)%used in finding the stims from the recorded trains to compensate for temporal variability
                                            %anything within this value following the peak of a pulse artifact will be considered part of that same pulse
                                            
for j=1:2   %leak, input resistance, access resistance for each channel
    leak(j)=mean(ddata(1:1000,j));
    ddata(:,j)=ddata(:,j)-leak(j); %subtracting leak, so thresholds etc. will work properly
    
    above_threshold=ddata(:,j)>stim_artifact_threshold; %for no particular reason, in this peak-finding portion have moved away from the array(:,j) format
    beginnings_iftrue=~above_threshold(1:end-1)&above_threshold(2:end);
    endings_iftrue=above_threshold(1:end-1)&~above_threshold(2:end);
    stim_start_indices=1+find(beginnings_iftrue);
    stim_end_indices=find(endings_iftrue);
    %find the max value within each group of suprathreshold values
    stim_peaks=[];
    for ttt=1:length(stim_start_indices)
        superthresh_max=find(ddata(stim_start_indices(ttt):stim_end_indices(ttt),j)==max(ddata(stim_start_indices(ttt):stim_end_indices(ttt),j)));
        stim_peaks(ttt)=superthresh_max(1)+stim_start_indices(ttt)-1;
    end
    %remove any stim artifacts within stim_artifact_jitter of a previous stim artifact
    z=length(stim_peaks);
    if length(stim_peaks)>1
		for bleb=2:length(stim_peaks)
            if stim_peaks(z)-stim_peaks(z-1)<stim_artifact_jitter
                stim_peaks(z)=[];
            end
            z=z-1;
        end
    end
	stim_indices(1:length(stim_peaks),j)=stim_peaks' 
    %find the access resistance and input resistance
            %stim_indices(1,2)=3500;
			%if find([6]==trial) &j==1,stim_indices(2)=[],end%stim_indices=cat(1,3000,stim_indices),end
			%if find(trial==[33 38])&j==1,stim_indices=cat(1,3000,stim_indices),end
			%if trial==3 &j==2,stim_indices(2:end,2)=0,end
			%if j==2,stim_indices(1,j)=stim_indices(1,1),end 
    [r_acc_minval(j) r_acc_min_ind(j)]=min(ddata((stim_indices(1,j)-(51*samples_per_ms):stim_indices(1,j)-(49*samples_per_ms)),j));%this is the first line that is NOT BACK-COMPATIBLE, b/c it assumes test pulse exists & lasts 50ms
    r_acc_min_ind(j)=r_acc_min_ind(j)+stim_indices(1,j)-((51*samples_per_ms)+1);   %this point is plotted to be sure r_access is being found correctly
    access_resistance(j)=-.005/r_acc_minval(j); %assumes a 5mV hyperpolarizing test pulse
    input_resistance(j)=-.005/(mean(ddata(stim_indices(1,j)-(17*samples_per_ms):stim_indices(1,j)-(2*samples_per_ms),j)));
    access_resistance(j)=access_resistance(j)/amillion; %converting to MOhms
    input_resistance(j)=input_resistance(j)/amillion;  
end

%checking to make sure the expected number of pulses is present
% if ~isempty(find(trial==[33 38]))
%     stim_indices=[3500 stim_indices(1,2);stim_indices];
%     stim_indices(2,2)=0;%[3500 0;stim_indices];%stim_indices([3 5],:)=[];%stim_indices(,:)=[],stim_indices(2,2)=0
% end
if stim_philosophy==1
	if ~isempty(hy)
%         if trial==43
%             stim_indices([3 5],:)=[];%stim_indices(,:)=[],stim_indices(2,2)=0
%         end
%         if  post_induction &find([1 20 33 38] == trial)
%             presynstim_indices=[3400;presynstim_indices]
%         end
%         if ~post_induction & find([10 12 13 16 19 20 23 27 32 34] ==trial)
%             presynstim_indices=[3400;presynstim_indices]
%         end
%         if find([1 2 3 4 5 6 7 10:15 18 19 21:40 42:77 79:85 87:91 93:108]==trial)
%                 presynstim_indices(1)=[]
%         end
        if length(stim_indices(:,1))~=APs_in_the_train+1  %add one for the hyperpolarizing pulse
            error('see here1')
%         elseif length(stim_indices(:,1))~=APs_in_the_train
%             error('see here2')    
        end
	else
%         if find(trial==[63 86])
%             presynstim_indices=[3000;presynstim_indices]
%         end
        if length(stim_indices(:,1))~=2     %one for the real stim artifact, one for the hyperpolarizing test pulse
            error ('see here3')
        end
	end
elseif stim_philosophy==2
    if test_pulse_present & (length(stim_indices(:,1))~=11) %NOT BACK COMPATIBLE
        error('see here4')
    elseif ~test_pulse_present & (length(stim_indices(:,1))~=10)
        error('see here5')
    end
elseif stim_philosophy==3
    %any number of stimuli goes  
elseif stim_philosophy==6
    if length(stim_indices(:,1))~=3, error('see here6'), end        %counting the test pulse, 3 stimuli
end

%removing the test pulse stim from the list and finding the interpulse intervals
stim_indices=stim_indices(2:end,:) %prevents the hyperpolarizing seal test pulse from being treated as a stimulus pulse (NOT BACK COMPATIBLE)
stim_indices(find(~stim_indices))=NaN %convert the zeros to NaNs
%find the IPI values in the output train to presynaptic
IPI_val_vec=diff(stim_indices(:,1));
IPI_val_vec=IPI_val_vec/samples_per_ms  %converting into ms

%determining the permutation of IPIs presented on this trial
placefinder=[];
if stim_philosophy~=6
	if ~isempty(hy)
        for jia=1:length(hy(1,:))
            for yi=1:hy(1,jia)
                if abs(IPI_val_vec(jia)-(hy(2,jia)+((yi-1)*hy(3,jia))))<IPI_jitter
                    placefinder(jia)=yi;
                    break
                end
            end
		end
        azaz=placefinder
	else
        azaz=[0]
    end
else    %if stimphil is 6 
    azaz=hy(find(IPI_val_vec<(hy+IPI_jitter)&IPI_val_vec>(hy-IPI_jitter)))
end
%if length(azaz)~=length(hy(1,:)),error('error finding interpulse intervals'),end

%this loop is going to extract all 6 parameters following each AP in each relevant one of the 4 possible synapses
asky='-ascii';dub='-double';tbs='-tabs';shortpatch_name=strrep(patchlog_name,'.hdf','');
common_pathname=strcat('F:\extracted_values_f\',shortpatch_name,'__');
stsd_parameters={'PSC','charge','latency','risetime','decaytime','asynchronous'};
stimulated_recorded={{'pre-' 'post-'} {'pre' 'post'}};
persistent ooverall_values
if trial==1,ooverall_values=[];end
for stimulated=1:length(stimulated_recorded{1})
     for recorded=1:length(stimulated_recorded{2})
         %getting the baseline immediately before the first AP stimulation
         if ~isnan(stim_indices(1,stimulated))
             orig_baseline(recorded)=mean(ddata(stim_indices(1,stimulated)+baseline_time_window,recorded))
             starterthresh=orig_baseline(recorded)-PSCbegin_threshold*std(ddata(stim_indices(1,stimulated)+baseline_time_window,recorded))
             enderthresh=orig_baseline(recorded)-PSCend_threshold*std(ddata(stim_indices(1,stimulated)+baseline_time_window,recorded))
             for jb=1:length(find(~isnan(stim_indices(:,stimulated))))      %fill in any additional spaces w/ NaN
                 index_now=stim_indices(jb,stimulated);%below, index_now is sometimes used and stim_indices(jb,stimulated) is also used;  there is some rhyme/reason to this
                 if stimulated==recorded,index_now=index_now+2*samples_per_ms;end%to give breathing space when measuring response on the same chan stimulated
                     PSC_startoff=find(ddata(index_now+[PSC_time_window],recorded)<starterthresh);
                     %if isempty(PSC_startoff),PSC_startoff=index_now+30,end
                     if ~isempty(PSC_startoff)
                         PSC_start_time(jb,stimulated,recorded)=PSC_startoff(1)+index_now+PSC_time_window(1)-1;
                         PSC_endup=find(ddata(PSC_start_time(jb,stimulated,recorded)+minimum_possible_psc_duration:index_now+PSC_time_window(end),recorded)>enderthresh);
                         if stimulated==1&isempty(PSC_endup),PSC_endup=index_now+120,end %error('PSC ending not found'),end
                         if ~isempty(PSC_endup)
                             %aaaa=PSC_endup(1)
                             PSC_end_time(jb,stimulated,recorded)=PSC_endup(1)+index_now+PSC_time_window(1)+minimum_possible_psc_duration-1;
                             PSC_minz=index_now+PSC_time_window(1)-1+find(ddata(index_now+[PSC_time_window],recorded)==min(ddata(index_now+[PSC_time_window],recorded)))
                             %if stimulated==2&recorded==1,error('sch'),end
                             figure(4),plot(trial,PSC_minz(1),'o','markersize',10),hold on
                             PSC_minindex(jb,stimulated,recorded)=PSC_minz(1)
                             if PSC_end_time(jb,stimulated,recorded)<PSC_minindex(jb,stimulated,recorded),jaybee=jb,stimm=stimulated,recc=recorded,aa=PSC_end_time,bb=PSC_minindex,end %error('schsch'),end
                             PSC(jb,stimulated,recorded)=ddata(PSC_minindex(jb,stimulated,recorded),recorded)-orig_baseline(recorded)
                             if Q_btwn_thresholds
                                charge(jb,stimulated,recorded)=sum(ddata(PSC_start_time(jb,stimulated,recorded):PSC_end_time(jb,stimulated,recorded),recorded))
                                psc_duration(jb,stimulated,recorded)=PSC_end_time(jb,stimulated,recorded)-PSC_start_time(jb,stimulated,recorded)+1;%used in plotting
                                charge_window_fractionofsecond(jb,stimulated,recorded)=psc_duration(jb,stimulated,recorded)/samples_per_second                               
                             else
                                charge(jb,stimulated,recorded)=sum(ddata(index_now+[Q_time_window],recorded));
                                charge_window_fractionofsecond(jb,stimulated,recorded)=length(Q_time_window)/samples_per_second
                             end
                            %charge(jb,stimulated,recorded)=charge(jb,stimulated,recorded)/atrillion; %convert from pA to A
		                    charge(jb,stimulated,recorded)=charge(jb,stimulated,recorded)*charge_window_fractionofsecond(jb,stimulated,recorded) %correcting for the window length to get coulombs
                            if charge(jb,stimulated,recorded)>0, charge(jb,stimulated,recorded)=0,end
                            latency(jb,stimulated,recorded)=(PSC_start_time(jb,stimulated,recorded)-stim_indices(jb,stimulated))/samples_per_ms;
                            risetime(jb,stimulated,recorded)=(PSC_minindex(jb,stimulated,recorded)-PSC_start_time(jb,stimulated,recorded))/samples_per_ms;
                            decaytime(jb,stimulated,recorded)=(PSC_end_time(jb,stimulated,recorded)-PSC_minindex(jb,stimulated,recorded))/samples_per_ms;
                            if stimulated==1&recorded==2,abc=decaytime,end
%                             if (stimulated==1&jb<(size(hy,2)+1)&((azaz(jb)-1)*hy(3,jb)+hy(2,jb)>=150))|(stimulated==1&jb==(size(hy,2)+1))|stimulated==2    %only reading asynchronous for IPIs of 150ms (or more)
%                                 asynchronous(jb,stimulated,recorded)=sum(ddata(stim_indices(jb,stimulated)+[asynchronous_window],recorded))
%                                 %asynchronous(jb,stimulated,recorded)=asynchronous(jb,stimulated,recorded)/atrillion;%picoAmps to Amps   
%                                 asynchronous(jb,stimulated,recorded)=asynchronous(jb,stimulated,recorded)*asynch_window_fractionofsecond%to coulombs
%                             else
                                asynchronous(jb,stimulated,recorded)=nan;asynchronousforplotting=nan;
%                             end
                            if asynchronous(jb,stimulated,recorded)>0,asynchronous(jb,stimulated,recorded)=0,end
                        else
                            PSC(jb,stimulated,recorded)=nan;charge(jb,stimulated,recorded)=nan;latency(jb,stimulated,recorded)=nan;risetime(jb,stimulated,recorded)=nan;...
                                decaytime(jb,stimulated,recorded)=nan;asynchronous(jb,stimulated,recorded)=nan;PSC_minindex(jb,stimulated,recorded)=nan;
                        end
                     else
                        PSC(jb,stimulated,recorded)=nan;charge(jb,stimulated,recorded)=nan;latency(jb,stimulated,recorded)=nan;risetime(jb,stimulated,recorded)=nan;...
                                decaytime(jb,stimulated,recorded)=nan;asynchronous(jb,stimulated,recorded)=nan;PSC_minindex(jb,stimulated,recorded)=nan;
                     end
                          
             ooverall_values(number_of_IPIs+jb,trial,1,stimulated,recorded)=-1*PSC(jb,stimulated,recorded);     %now (oct 10, 2004) using positive PSC, charge and asynch
             ooverall_values(number_of_IPIs+jb,trial,2,stimulated,recorded)=-1*charge(jb,stimulated,recorded);
             ooverall_values(number_of_IPIs+jb,trial,3,stimulated,recorded)=latency(jb,stimulated,recorded);
             ooverall_values(number_of_IPIs+jb,trial,4,stimulated,recorded)=risetime(jb,stimulated,recorded);
             ooverall_values(number_of_IPIs+jb,trial,5,stimulated,recorded)=decaytime(jb,stimulated,recorded);
             ooverall_values(number_of_IPIs+jb,trial,6,stimulated,recorded)=-1*asynchronous(jb,stimulated,recorded);
             
             ooverall_values(1:number_of_IPIs,trial,1:6,stimulated,recorded)=cat(3,azaz',azaz',azaz',azaz',azaz',azaz');

             end
             if trial==number_of_trials 
%                 %ooverall_values(find(~ooverall_values))=NaN;  reinstate this once everything above is fixed
                 for parameter=1:length(stsd_parameters)
%                     %save the 6 parameters (for the current one of the four possible synapses) separately
                     filename=strcat(stimulated_recorded{1}(stimulated),stimulated_recorded{2}(recorded),stsd_parameters{parameter});
                     pathname=strcat(common_pathname,filename);
                     single_param=ooverall_values(1:end,1:end,parameter,stimulated,recorded);
                     var='single_param';
              	    if save_that_sht,save(pathname{1},var,asky,dub,tbs),end
                end
            end
        end
    end
end

if real_time_mode
    mlock
    persistent bibimbab
    persistent shelob
    if trial==1 & ishandle(3)
        a=get(findobj(3,'Type','line'));
        bibimbab=a(1,1).XData;
        figure(3),plot([trial+bibimbab-.5 trial+bibimbab-.5],[5*shelob(1) 0],'r','LineWidth',3)
    elseif trial==1
        bibimbab=0;
        shelob=[ooverall_values(number_of_IPIs+1,trial,1,1,2) 1.1*ooverall_values(number_of_IPIs+1,trial,1,1,2)];
    end
    if ooverall_values(number_of_IPIs+1,trial,1,1,2)<shelob(1),shelob(1)=ooverall_values(number_of_IPIs+1,trial,1,1,2);end
    if ooverall_values(number_of_IPIs+1,trial,1,1,2)>shelob(2),shelob(2)=ooverall_values(number_of_IPIs+1,trial,1,1,2);end
    figure(3)
    plot(trial+bibimbab,ooverall_values(number_of_IPIs+1,trial,1,1,2),'o','MarkerFaceColor','k','MarkerEdgeColor','k','MarkerSize',10),hold on
    axis([0 trial+bibimbab+1 shelob(1) shelob(2)])
    ylabel('PSCo'),xlabel('overall trial')
    title(prosslog_name)
    figure(4)
    subplot(3,2,1),plot(trial,ooverall_values(number_of_IPIs+1,trial,1,1,2),'o','MarkerFaceColor','k','MarkerEdgeColor','k','MarkerSize',7),title('pre-post'),hold on
    subplot(3,2,2),plot(trial,ooverall_values(number_of_IPIs+1,trial,1,2,1),'o','markerfacecolor','k','markeredgecolor','k','markersize',7),title('post-pre'),hold on
    subplot(3,2,3),plot(trial,access_resistance(2),'o','markerfacecolor','k','markeredgecolor','k','markersize',7),title('access resistance post'),hold on
    subplot(3,2,4),plot(trial,access_resistance(1),'o','markerfacecolor','k','markeredgecolor','k','markersize',7),title('access resistance pre'),hold on
    subplot(3,2,5),plot(trial,input_resistance(2),'o','markerfacecolor','k','markeredgecolor','k','markersize',7),title('input resistance post'),hold on
    subplot(3,2,6),plot(trial,input_resistance(1),'o','markerfacecolor','k','markeredgecolor','k','markersize',7),title('input resistance pre'),hold on
end

%a list of the variables, stored row-by-row, in the control figure (columns represent trials;  everything is on one sheet)
trials=trial;
ITI=measured_ITI;
temperature=temperature_during_train_mean; 
intensity_pre=OVSF_presyn; 
pulsedur_pre=pulse_duration_presyn; 
r_access_chanone=access_resistance(1);  %the method of filling these 3, and their equivalents for the other channel, may change
r_input_chanone=input_resistance(1); 
leak_chanone=leak(1); 
tot_charge_chanone=sum(ddata(1:end,1)); 
intensity_post=OVSF_postsyn;
pulsedur_post=pulse_duration_postsyn;
r_access_chantwo=access_resistance(2); 
r_input_chantwo=input_resistance(2); 
leak_chantwo=leak(2); 
tot_charge_chantwo=sum(ddata(1:end),2);
psc_o_prepre=ooverall_values(number_of_IPIs+1,trial,1,1,1); 
q_o_prepre=ooverall_values(number_of_IPIs+1,trial,2,1,1);
lat_prepre=ooverall_values(number_of_IPIs+1,trial,3,1,1);
ris_prepre=ooverall_values(number_of_IPIs+1,trial,4,1,1);
decay_prepre=ooverall_values(number_of_IPIs+1,trial,5,1,1);
asynch_prepre=ooverall_values(number_of_IPIs+1,trial,6,1,1);
psc_o_prepost=ooverall_values(number_of_IPIs+1,trial,1,1,2); 
q_o_prepost=ooverall_values(number_of_IPIs+1,trial,2,1,2);
lat_prepost=ooverall_values(number_of_IPIs+1,trial,3,1,2);
ris_prepost=ooverall_values(number_of_IPIs+1,trial,4,1,2);
decay_prepost=ooverall_values(number_of_IPIs+1,trial,5,1,2);
asynch_prepost=ooverall_values(number_of_IPIs+1,trial,6,1,2);
if size(ooverall_values,4)>1 %if this analysis includes trials where the postsyn cell was stimulated to fire an AP
	psc_o_postpre=ooverall_values(number_of_IPIs+1,trial,1,2,1);
    q_o_postpre=ooverall_values(number_of_IPIs+1,trial,2,2,1); 
    lat_postpre=ooverall_values(number_of_IPIs+1,trial,3,2,1);
	ris_postpre=ooverall_values(number_of_IPIs+1,trial,4,2,1);
	decay_postpre=ooverall_values(number_of_IPIs+1,trial,5,2,1);
	asynch_postpre=ooverall_values(number_of_IPIs+1,trial,6,2,1);
	psc_o_postpost=ooverall_values(number_of_IPIs+1,trial,1,2,2); 
    q_o_postpost=ooverall_values(number_of_IPIs+1,trial,2,2,2);
    lat_postpost=ooverall_values(number_of_IPIs+1,trial,3,2,2);
	ris_postpost=ooverall_values(number_of_IPIs+1,trial,4,2,2);
	decay_postpost=ooverall_values(number_of_IPIs+1,trial,5,2,2);
	asynch_postpost=ooverall_values(number_of_IPIs+1,trial,6,2,2);
else
    psc_o_postpre=NaN;q_o_postpre=NaN;lat_postpre=NaN;ris_postpre=NaN;decay_postpre=NaN;asynch_postpre=NaN;psc_o_postpost=NaN;q_o_postpost=NaN;
    lat_postpost=NaN;ris_postpost=NaN;decay_postpost=NaN;asynch_postpost=NaN;
end

control_variables=[trials ITI temperature intensity_pre pulsedur_pre r_access_chanone r_input_chanone leak_chanone tot_charge_chanone intensity_post ...
        pulsedur_post r_access_chantwo r_input_chantwo leak_chantwo tot_charge_chantwo psc_o_prepre q_o_prepre lat_prepre ris_prepre decay_prepre ...
        asynch_prepre psc_o_prepost q_o_prepost lat_prepost ris_prepost decay_prepost asynch_prepost psc_o_postpre q_o_postpre lat_postpre ris_postpre...
        decay_postpre asynch_postpre psc_o_postpost q_o_postpost lat_postpost ris_postpost decay_postpost asynch_postpost];

control_variable_list={'trials' 'ITI' 'temperature' 'intensity_pre' 'pulsedur_pre' 'r_access_chanone' 'r_input_chanone' 'leak_chanone' 'tot_charge_chanone' 'intensity_post' ...
        'pulsedur_post' 'r_access_chantwo' 'r_input_chantwo' 'leak_chantwo' 'tot_charge_chantwo' 'psc_o_prepre' 'q_o_prepre' 'lat_prepre' 'ris_prepre' 'decay_prepre' 'asynch_prepre'...
        'psc_o_prepost' 'q_o_prepost' 'lat_prepost' 'ris_prepost' 'decay_prepost' 'asynch_prepost' 'psc_o_postpre' 'q_o_postpre' 'lat_postpre' 'ris_postpre' 'decay_postpre'...
        'asynch_postpre' 'psc_o_postpost' 'q_o_postpost' 'lat_postpost' 'ris_postpost' 'decay_postpost' 'asynch_postpost'};
persistent controlll
if trial==1, controlll=[];end
controlll(:,trial)=control_variables';

if trial==number_of_trials&plot_controls,figure(5);set(5,'PaperOrientation','landscape','PaperPosition',[0.5 0.5 10 7.5]);
    filename=strcat(common_pathname,'controls'); var='controlll';if save_that_sht,save(filename,var,asky,dub,tbs),end
	hold on
	x_factors={'trials'
	%         'ITI_history'
    %          'temperature'
	%         'intensity_pre' 
	%         'pulsedur_pre'
              'r_access_chanone'
              'r_input_chanone'
              'leak_chanone'
	%         'intensity_post'
	%         'pulsedur_post'
              'r_access_chantwo'
              'r_input_chantwo'
              'leak_chantwo'
               };
	x_cols=size(x_factors,1);
	y_factors={
    %          'psc_o_prepre'
    %          'q_o_prepre'
    %          'lat_prepre'
    %          'ris_prepre'
    %          'decay_prepre'
    %          'asynch_prepre'
              'psc_o_prepost'
              'q_o_prepost'
              'lat_prepost'
              'ris_prepost'
              'decay_prepost'
              'asynch_prepost'
    %          'psc_o_postpre'
    %          'q_o_postpre'
    %          'lat_postpre'
    %          'ris_postpre'
    %          'decay_postpre'
    %          'asynch_postpre'
    %          'psc_o_postpost'
    %          'q_o_postpost'
    %          'lat_postpost'
    %          'ris_postpost'
    %          'decay_postpost'
    %          'asynch_postpost'
    %          'tot_charge_chanone'
    %          'leak_chanone'
    %          'r_access_chanone'
    %          'r_input_chanone'
    %          'tot_charge_chantwo'
    %          'leak_chantwo'
    %          'r_access_chantwo'
    %          'r_input_chantwo'
    %          'temperature'
                };
	y_rows=size(y_factors,1);
	for j=1:y_rows  %from convert_stored_matrix just add one more loop to represent epoch, and change the color of the symbol for each epoch
       for k=1:x_cols
           subplot(y_rows,x_cols,((j-1)*x_cols)+k)
           jj=y_factors{j};
           kk=x_factors{k};
           jj=strcmp(y_factors(j),control_variable_list);
           kk=strcmp(x_factors(k),control_variable_list);
           plot(controlll(find(kk),1:trial),controlll(find(jj),1:trial),'o','markeredgecolor','b','markerfacecolor','b','markersize',3)
           hold on
           if k==1, ylabel(strrep(y_factors(j),'_','\_')),set(get(gca,'YLabel'),'Rotation',0.0,'Horizontal','Right','FontWeight','demi'),end
           if j==y_rows, xlabel(strrep(x_factors(k),'_','\_')),set(get(gca,'XLabel'),'FontWeight','demi'),end
           if j==1 & k==ceil(x_cols/2),title(strrep(patchlog_name,'_','\_'),'FontWeight','bold'),end
       end
	end
end

%save the full trace from each of the two channels (with azaz), and label it accordingly
persistent raw_values
if trial==1, raw_values=[];end

for j=1:2
    raw_holding(:,j)=ddata(stim_indices(1,1)+raw_window,j);
end
oldsiz=size(raw_values,2);
raw_values(1:number_of_IPIs,oldsiz+[1:2])=[azaz' azaz'];
%size(raw_holding)
raw_values(number_of_IPIs+[1:size(raw_holding,1)],oldsiz+[1:2])=raw_holding;

if trial==number_of_trials
	filename=strcat(common_pathname,'__raw');
	var='raw_values';
	if save_that_sht,save(filename,var,asky,dub,tbs),end
end

%plot it all
if trial==number_of_trials
	figure(2)
    clf
    %set(gca,'yticklabel',[]),set(gca,'xticklabel',[])
	%plot raw recording
	%title(strcat(patchlog_name,'__',num2str(trial)))
	hold on
	plot(ddata(:,1),'b','linewidth',3)
	plot(ddata(:,2),'k','linewidth',3)
    plot(r_acc_min_ind(1),r_acc_minval(1),'rd','linewidth',4)
    plot(r_acc_min_ind(2),r_acc_minval(2),'gd','linewidth',4)
    plot(stim_indices(:,1),ddata(stim_indices(:,1),1),'ro','LineWidth',4)
    plot(PSC_minindex(:,1,2),ddata(PSC_minindex(:,1,2),2),'r+','markersize',10,'LineWidth',4)
    rectangle('position',[stim_indices(1,1)+baseline_time_window(1) -5 baseline_time_window(end)-baseline_time_window(1) 10],'LineWidth',2,'EdgeColor','r'),hold on
    latprepost=ooverall_values(number_of_IPIs+1:end,trial,3,1,2);risprepost=ooverall_values(number_of_IPIs+1:end,trial,4,1,2);decayprepost=ooverall_values(number_of_IPIs+1:end,trial,5,1,2);
    latprepost=latprepost*samples_per_ms;risprepost=risprepost*samples_per_ms;decayprepost=decayprepost*samples_per_ms;
    plot(stim_indices(:,1)+latprepost,ddata((stim_indices(:,1)+latprepost),2),'rs','LineWidth',2)
    plot(stim_indices(:,1)+latprepost+risprepost,ddata(stim_indices(:,1)+latprepost+risprepost,2),'rp','LineWidth',2)
    plot(stim_indices(:,1)+latprepost+risprepost+decayprepost,ddata(stim_indices(:,1)+latprepost+risprepost+decayprepost,2),'rh','LineWidth',2)
    for presynstim=1:length(stim_indices(:,1))
        if ooverall_values(number_of_IPIs+presynstim,trial,2,1,2)>0  %if a charge has been detected/stored
            scaled_charge_prepost=(ooverall_values(number_of_IPIs+presynstim,trial,2,1,2))/charge_window_fractionofsecond(presynstim,1,2)
            if Q_btwn_thresholds, heighty=scaled_charge_prepost/psc_duration(presynstim,1,2);
                rectangle('position',[PSC_start_time(presynstim,1,2) -heighty psc_duration(presynstim,1,2) heighty],'LineWidth',2, 'EdgeColor','r')
            else heighty=scaled_charge_prepost/(Q_time_window(end)-Q_time_window(1)); 
                rectangle('position',[stim_indices(presynstim,1)+Q_time_window(1) -heighty (Q_time_window(end)-Q_time_window(1)) heighty],'LineWidth',2, 'EdgeColor','r')
            end
        end
        if ooverall_values(number_of_IPIs+presynstim,trial,6,1,2)>0 %if asynchronous release has been detected/stored
            aa=number_of_IPIs
            bb=presynstim
            cc=trial
            dd=ooverall_values(number_of_IPIs+presynstim,trial,6,1,2)
            heighti=((ooverall_values(number_of_IPIs+presynstim,trial,6,1,2))/asynch_window_fractionofsecond)/(asynchronous_window(end)-asynchronous_window(1));%area divided by length gives height
            heighti=500*heighti;%scaling for display salience
            rectangle('position',[stim_indices(presynstim,1)+asynchronous_window(1) -heighti asynchronous_window(end)-asynchronous_window(1) heighti],'LineWidth',2, 'EdgeColor','r')
        end    
    end
        
   second_col=stim_indices(:,2)
   for postsynstim=1:length(second_col(~isnan(second_col)))
       a=PSC_minindex
       plot(stim_indices(postsynstim,2),ddata(stim_indices(postsynstim,2),2),'go','LineWidth',2)
       if ~isnan(PSC_minindex(postsynstim,2,1))
           plot(PSC_minindex(postsynstim,2,1),ddata(PSC_minindex(postsynstim,2,1),1),'g+','LineWidth',2)
           latpostpre=ooverall_values(number_of_IPIs+1:end,trial,3,2,1),rispostpre=ooverall_values(number_of_IPIs+1:end,trial,4,2,1),decaypostpre=ooverall_values(number_of_IPIs+1:end,trial,5,2,1)
           latpostpre=latpostpre*samples_per_ms;rispostpre=rispostpre*samples_per_ms;decaypostpre=decaypostpre*samples_per_ms;
           plot(stim_indices(postsynstim,2)+latpostpre,ddata((stim_indices(postsynstim,2)+latpostpre),1),'gs','LineWidth',2)
           plot(stim_indices(postsynstim,2)+latpostpre+rispostpre,ddata(stim_indices(postsynstim,2)+latpostpre+rispostpre,1),'gp','LineWidth',2)
           plot(stim_indices(postsynstim,2)+latpostpre+rispostpre+decaypostpre,ddata(stim_indices(postsynstim,2)+latpostpre+rispostpre+decaypostpre,1),'gh','LineWidth',2)
           if ooverall_values(number_of_IPIs+postsynstim,trial,2,2,1)>0
               scaled_charge_postpre=(ooverall_values(number_of_IPIs+postsynstim,trial,2,2,1))/charge_window_fractionofsecond(postsynstim,2,1)
               if Q_btwn_thresholds,heighty_post=scaled_charge_postpre/psc_duration(postsynstim,2,1); 
                   rectangle('position',[PSC_start_time(postsynstim,2,1) -heighty_post psc_duration(postsynstim,2,1) heighty_post],'linewidth',2,'edgecolor','g')
               else heighty_post=scaled_charge_postpre/(Q_time_window(end)-Q_time_window(1));
                   rectangle('position',[stim_indices(postsynstim,2)+Q_time_window(1) -heighty_post (Q_time_window(end)-Q_time_window(1)) heighty_post],'linewidth',2,'edgecolor','g')
               end
           end
           if ooverall_values(number_of_IPIs+postsynstim,trial,6,2,1)>0
               heighti_post=((ooverall_values(number_of_IPIs+postsynstim,trial,6,2,1))/asynch_window_fractionofsecond)/(asynchronous_window(end)-asynchronous_window(1)); %area divided by length gives height
               heighti=500*heighti;
               rectangle('position',[stim_indices(postsynstim,2)+asynchronous_window(1) -heighti_post asynchronous_window(end)-asynchronous_window(1) heighti_post],'LineWidth',2, 'EdgeColor','g')
           end   
       end
   end
end