MAKE_OXY_SUMFILE - Makes oxygen bottle/ctd comparison summary file. USAGE: [oxy_struct] = function_name(oxy_dir,bottle_dir,cruise_name); INPUT: oxy_dir: string containing the path to the oxygen titration results bottle_dir: string path to the ctd *.btl files cruise_name: 3 o 4 character cruise label OUTPUT: Automatically writes two files in the oxy_dir Files are basically the same in *.mat and *.asc formats oxy_struct: contains a structure with the same information contained in the *.mat file DESCRIPTION: This function tries to load the *.btl files from the Seabird seasave software and the *.oxy files from the AOML titration system and create a summary file containing coincident measurements from both systems. The data for a whole cruise is processed at once so if you want less data you'll have to subset afterwards. BUGS: 1. Not really a bug but it's based on the AOML *.oxy files. These files can vary slightly in terms of what each field means, based on operator preference. The results of read_oxy contain a field called depth which is usu. either the niskin bottle position on the rosette or the firing order. Position is preferrable if you think about it at the beginning of the cruise. 2. The configuration of the data is specific to what we wanted on the Ron Brown in Feb 2002. It's not fully generalized yet. NOTE: TO BE DONE: VERSION: 0.1 AUTHOR: Derrick Snowden NOAA/AOML/PhOD CALLER: DEPENDENCIES: SW package. read_oxy ox_units_2 (maybe ox_units)
0001 function oxy_struct = make_oxy_sumfile(oxy_dir,bottle_dir,cruise_name) 0002 % MAKE_OXY_SUMFILE - Makes oxygen bottle/ctd comparison summary file. 0003 % 0004 % USAGE: 0005 % [oxy_struct] = function_name(oxy_dir,bottle_dir,cruise_name); 0006 % 0007 % INPUT: 0008 % oxy_dir: string containing the path to the oxygen titration results 0009 % bottle_dir: string path to the ctd *.btl files 0010 % cruise_name: 3 o 4 character cruise label 0011 % 0012 % OUTPUT: Automatically writes two files in the oxy_dir 0013 % Files are basically the same in *.mat and *.asc formats 0014 % oxy_struct: contains a structure with the same information 0015 % contained in the *.mat file 0016 % 0017 % DESCRIPTION: This function tries to load the *.btl files from the Seabird 0018 % seasave software and the *.oxy files from the AOML titration system 0019 % and create a summary file containing coincident measurements from both 0020 % systems. The data for a whole cruise is processed at once so if you want 0021 % less data you'll have to subset afterwards. 0022 % 0023 % BUGS: 1. Not really a bug but it's based on the AOML *.oxy files. These files 0024 % can vary slightly in terms of what each field means, based on operator preference. 0025 % The results of read_oxy contain a field called depth which is usu. either 0026 % the niskin bottle position on the rosette or the firing order. Position is 0027 % preferrable if you think about it at the beginning of the cruise. 0028 % 0029 % 2. The configuration of the data is specific to what we wanted on 0030 % the Ron Brown in Feb 2002. It's not fully generalized yet. 0031 % 0032 % NOTE: 0033 % 0034 % TO BE DONE: 0035 % 0036 % 0037 % VERSION: 0.1 0038 % 0039 % AUTHOR: Derrick Snowden 0040 % NOAA/AOML/PhOD 0041 % 0042 % CALLER: 0043 % 0044 % DEPENDENCIES: SW package. 0045 % read_oxy 0046 % ox_units_2 (maybe ox_units) 0047 % 0048 0049 % load the oxygen data fromn the bottle titrations 0050 oxy_files = dir([oxy_dir,cruise_name,'*.oxy']); 0051 0052 for i = 1:length(oxy_files) 0053 oxy(i) = read_oxy([oxy_dir,oxy_files(i).name]); 0054 end 0055 0056 stations = unique(vertcat(oxy.station)); 0057 num_bottles_processed = length(stations); 0058 0059 % Load all the *.btl files 0060 num_files = 1; 0061 for i = 1:length(stations) 0062 bottle_files{num_files} = [bottle_dir,cruise_name,sprintf('%.3d',stations(i)),'.btl']; 0063 num_files = num_files + 1; 0064 end 0065 for i = 1:length(bottle_files) 0066 btl(i) = read_sbebtl(char(bottle_files{i})); 0067 end 0068 0069 % The matrix of data we need is 0070 % niskin_position niskin_fire_order station pressure_ctd temp_ctd salinity_ctd oxygen_ctd oxygen_bottles 0071 % n X 8 0072 0073 % Insert the fields known from the oxy structure. 0074 bottle = [vertcat(oxy.depth) vertcat(oxy.station) vertcat(oxy.oxygen)]; 0075 pos_btl = 1; 0076 stn_btl = 2; 0077 ox_btl = 3; 0078 0079 % The rest of the data is taken from the bottle files. 0080 % First compile a m,atrix of data from bottles and then 0081 % select from it the columns which belong in the desired data matrix. 0082 % This assumes all the bottle files have the same number of fields. 0083 0084 for i = 1:length(stations) 0085 pos_ctd = find(strcmp(btl(i).names,'bottle_ros_position') == 1); 0086 fire_ctd = find(strcmp(btl(i).names,'bottle_fired_count') == 1); 0087 sa00_ctd = find(strcmp(btl(i).names,'sal_pri_pri') == 1); 0088 sa11_ctd = find(strcmp(btl(i).names,'sal_sec_sec') == 1); 0089 t090_ctd = find(strcmp(btl(i).names,'t90_pri') == 1); 0090 t190_ctd = find(strcmp(btl(i).names,'t90_sec') == 1); 0091 ox0_ctd = find(strcmp(btl(i).names,'sbedo2_pri') == 1); 0092 ox1_ctd = find(strcmp(btl(i).names,'sbedo2_sec') == 1); 0093 pr_ctd = find(strcmp(btl(i).names,'pressure') == 1); 0094 ctd = btl(i).data; 0095 lon = btl(i).lon; 0096 lat = btl(i).lat; 0097 % Now find which oxygen bottle measurements match 0098 % the ones just read from the ctd for this station 0099 this_station_oxy_idx = find(bottle(:,2) == stations(i)); 0100 % find the index of the first appearance in the data matrix of 0101 % the given station, i.e. the offset 0102 this_station_first_oxy_idx = min(this_station_oxy_idx) - 1; 0103 try 0104 [ix,iy] = index(ctd(:,pos_ctd),bottle(this_station_oxy_idx,1)); 0105 catch 0106 disp(['make_oxy_summfile: Error trying to combine btl/oxy data for station ',num2str(stations(i)),'.']); 0107 error(['make_oxy_sumfile: Check data files for a couple stations on either side for errors.']); 0108 end 0109 % Add the offset to the iy to get the absolute position rather than the relative position 0110 iy = this_station_first_oxy_idx + iy; 0111 the_rest = [pr_ctd t090_ctd t190_ctd sa00_ctd sa11_ctd ox0_ctd ox1_ctd]; 0112 % Assemble the joined data matrix from the various indices defined above. 0113 LON = repmat(lon,size(iy)); 0114 LAT = repmat(lat,size(iy)); 0115 tmp = [bottle(iy,pos_btl) ctd(ix,fire_ctd) bottle(iy,stn_btl) LON LAT ctd(ix,the_rest) bottle(iy,ox_btl)]; 0116 if i==1 0117 data = tmp; 0118 else 0119 data = [data ; tmp]; 0120 end 0121 end %loop through stations. 0122 0123 % Reassign the indices for plotting purposes using the joined data matrix 0124 % joined data = intersect(bottle,ctd). 0125 pos = 1; fire = 2; stn = 3; lo = 4; la = 5; pr = 6; t090 = 7; t190 = 8; 0126 sa00 = 9; sa11 = 10; ox0 = 11; ox1 = 12; oxb = 13; 0127 indx.pos = pos; 0128 indx.fire = fire; 0129 indx.stn = stn; 0130 indx.lo = lo; 0131 indx.la = la; 0132 indx.pr = pr; 0133 indx.t090 = t090; 0134 indx.t190 = t190; 0135 indx.sa00 = sa00; 0136 indx.sa11 = sa11; 0137 indx.ox0 = ox0; 0138 indx.ox1 = ox1; 0139 indx.oxb = oxb; 0140 0141 ptemp = sw_ptmp(data(:,sa00),t90tot68(data(:,t090)),data(:,pr),1000); 0142 % Change units to ml/l 0143 data(:,oxb) = ox_units_2(data(:,oxb),data(:,sa00),ptemp,'mml2mll'); 0144 0145 oxy_struct.btl_pos = data(:,indx.pos); 0146 oxy_struct.btl_order = data(:,indx.fire); 0147 oxy_struct.stn = data(:,indx.stn); 0148 oxy_struct.lon = data(:,indx.lo); 0149 oxy_struct.lat = data(:,indx.la); 0150 oxy_struct.pr = data(:,indx.pr); 0151 oxy_struct.t090 = data(:,indx.t090); 0152 oxy_struct.t190 = data(:,indx.t190); 0153 oxy_struct.sa00 = data(:,indx.sa00); 0154 oxy_struct.sa11 = data(:,sa11); 0155 oxy_struct.ox0 = data(:,ox0); 0156 oxy_struct.ox1 = data(:,ox1); 0157 oxy_struct.oxb = data(:,oxb); 0158 oxy_struct.th090 = ptemp; 0159 oxy_struct.th190 = sw_ptmp(data(:,sa11),data(:,t190),data(:,pr),1000); 0160 0161 % Write a summary table 0162 dlmwrite([oxy_dir,'summary_oxy.asc'],data,' ') 0163 0164 save([oxy_dir,'summary_oxy.mat'],'oxy_struct') 0165 0166 0167 0168 0169 0170 0171