function output = make_salinity_file2 (salts)
%
% function output_salts = make_salinity_file (salts)
%
% Creates salinity text file output variable "output"
% that contains all the variables n column order for the Clivar Repeat
% Hydrography program (in a slightly changed order that they should be able
% to handle!).  POutting the columns in this should order should make them
% equivalently readable by Carlos's CTD Toolbox as well.
% Output = 
%   column 1 = output_sta  
%   column 2 = output_niskin
%   column 3 = output_bottle (sample bottle number)
%   column 4 = output_twiceratio 
%   column 5 = output_salinity 
%   column 6 = output_quality
%   column 7 = output_cast 
%
%
% Version 2: Feb 2012
%   Uses only salts.txt* values, not nettxt* values.
%

clear output_sta
output_sta = salts(1).txt_station_id;
for II = 2: length(salts);
    output_sta = [output_sta' salts(II).txt_station_id']';
end;

istart = find(output_sta == 8);
if ~isempty(istart)
    II = istart(end)+1;
    while (II < istart(end)+26)
        if (output_sta(II)~=1001)
            output_sta(II) = 9;    
        end
        II = II+1;
    end
end

istart = find(output_sta == 34);
if ~isempty(istart)
    II = istart(end)+1;
    while (II < istart(end)+26)
        if (output_sta(II)~=1001)
            output_sta(II) = 35;    
        end
        II = II+1;
    end
end

output_cast = ones(length(output_sta),1);
output_cast(find(output_sta == 1)) = 2;
output_cast(find(output_sta == 9)) = 3;
output_cast(find(output_sta == 35)) = 2;
output_cast(find(output_sta == 51)) = 2;

clear output_niskin
output_niskin = salts(1).txt_niskin_bottle;
for II = 2: length(salts);
    output_niskin = [output_niskin' salts(II).txt_niskin_bottle']';
end;

clear output_bottle
output_bottle = salts(1).txt_samp_nbr;
for II = 2: length(salts);
    output_bottle = [output_bottle' salts(II).txt_samp_nbr']';
end;

clear output_twiceratio
output_twiceratio = salts(1).txt_cond_ratio_correct;
for II = 2: length(salts);
    output_twiceratio = [output_twiceratio' salts(II).txt_cond_ratio_correct']';
end;

clear output_salinity
output_salinity = salts(1).txt_salinity_correct;
for II = 2: length(salts);
    output_salinity = [output_salinity' salts(II).txt_salinity_correct']';
end;

output_quality = 2*ones(length(output_sta),1);

output = [output_sta output_niskin output_bottle ...
    output_twiceratio output_salinity output_quality output_cast];

II = find(output_sta == 1000);
output_sta (II,:) = [];
output (II,:) = [];

II = find(output_sta == 1001);
output_sta (II,:) = [];
output (II,:) = [];

II = find(output_sta == -9);
output_sta (II,:) = [];
output (II,:) = [];








