% read in file names from the folder
% i.e. infile_root = ('out.txt')
infile_root=('out.txt');
filenames = dir(['*' infile_root]); 

% read in the file data
temp = load (filenames.name);

%Loop to read in separate salt files into one single file
rstep=0;
for ii=1:length(filenames),
    
    temp=load(filenames(ii).name);
    rstep=rstep+1;
    
    %create full file variables. This reads in each file parameter and
    %using the step variable concatenates a full cruise profile for each
    %parameter into one file
    stt(rstep:rstep+length(temp)-1,1)=temp(:,1);
    nsknbtl(rstep:rstep+length(temp)-1,1)=temp(:,3);
    smplebtl(rstep:rstep+length(temp)-1,1)=temp(:,4);
    twiceratio(rstep:rstep+length(temp)-1,1)=temp(:,5);
    slt(rstep:rstep+length(temp)-1,1)=temp(:,6);
    output_quality(rstep:rstep+length(temp)-1,1)=temp(:,7);
    
    %creates the row postion for the next file read in to concatenated
    rstep=rstep+length(temp)-1;
    
end;

%Combine variables into on output matrix
output = [stt nsknbtl smplebtl twiceratio slt output_quality];

%matrix format for load_salts for CTD calibraion
salts=[stt nsknbtl smplebtl twiceratio slt];

%Removes the calibration runs from the data
II=find(stt==1000 | stt==1001);
output(II,:)=[];
salts(II,:)=[];


%save .dat for load salts and .mat for viewing purposes(my preference no
%needed)
save salts_abll04.dat -ascii -tabs salts;
save salts_abll04.mat salts;