function [raw_sweep_postsyn,peakz]=create_basic_text_file_forrrp(file_to_read,current_sweep)
%opens the .hdf file, reads one sweep at a time (because these files are so large), finds the peaks in that sweep, and returns the sweep and the peaks

hdfml('closeall'),%clear all,close all,tic
                     
patchlog_name=strcat('H:\work_modulebayHD\', file_to_read,'.hdf');

%open the patchlog created by update patchlog at the time of the recording
converting_hdf=hdfsd('start',patchlog_name,'read');
[datasets_for_converted,nglobal_atts,stat_readinghdf]=hdfsd('fileinfo',converting_hdf);
number_of_trials=datasets_for_converted;
converter_sds_id=hdfsd('select',converting_hdf,0);        %take the first dataset in the .hdf file
[ds_name, ds_ndims, ds_dims, ds_type, ds_atts, stat]=hdfsd('getinfo',converter_sds_id); %get info on the dataset
stat_dataset_end_post=hdfsd('endaccess',converter_sds_id);

windowing=0;
returnrange=[-3000:50000];

raw_sweep_postsyn=[];
%intervals=[];
%stepz=[];   %for holding voltage steps
peakz=[];
for trial=current_sweep
    %choose the dataset for this trial
    converter_sds_id=hdfsd('select',converting_hdf,(trial-1)); %trial, corrected for zeroth indexing, tells which data set to read
    [ds_name, ds_ndims, ds_dims, ds_type, ds_atts, stat]=hdfsd('getinfo',converter_sds_id); 
    samples_per_trigger=ds_dims(2);
    %get the ITI which preceded the current trial, which was stored as the ds_name by update_patchlog
    measured_ITI=str2num(ds_name);
    ds_stride=[];       %these lines tell how the dataset should be read
    ds_edges=[1, samples_per_trigger];
        %read in the recording from the presynaptic neuron
    ds_start=[0 0];   %starts reading from the first row in the first column, with the row and column switched ala .hdf's indexing system 
    [ds_dataein,status]=hdfsd('readdata',converter_sds_id,ds_start,ds_stride,ds_edges);
    %read in the recording from the postsynaptic neuron
    ds_start=[1 0];   %starts reading from the first row in the second column
    [ds_datazwei,status]=hdfsd('readdata',converter_sds_id,ds_start,ds_stride,ds_edges); 
    ein=ds_dataein(10:end)-mean(ds_dataein(10:2000));
    ein_peaks=find_peaks_within_threshold_crossing_regions(4.5,50,ein);
    peakz=[peakz;ein_peaks];
    zwei=ds_datazwei(10:end)-mean(ds_datazwei(10:2000));
%         zwei_peaks=find_peaks_within_threshold_crossing_regions(1,50,zwei)
% 	    %if zwei_peaks,zweimax=zwei(zwei_peaks(1));else zweimax=0;end
% 	    %if einmax>zweimax, maxind=ein_peaks(1); elseif zweimax>einmax, maxind=zwei_peaks(1); else error('which trace has stim artifact?'), end
%         if find(zwei_peaks),maxind=zwei_peaks(1); else maxind=abs(returnrange(1))+1;end  
%         
%         if windowing, ein=ein(maxind+returnrange); zwei=zwei(maxind+returnrange); end
% 	end
	raw_sweep_postsyn=[raw_sweep_postsyn  zwei];
    stat=hdfsd('endaccess',converter_sds_id);  %closing the data set after having read it
end
%closing the patchlog file
stat_hdfend=hdfsd('end',converting_hdf);