Home > ctdcal > match_autosal_raw_dat.m

match_autosal_raw_dat

PURPOSE ^

match_autosal_raw_dat - Match the samples from the *.dat with the raw values in *.raw

SYNOPSIS ^

function theResult = match_autosal_raw_dat(salts,raw,outfile,analysis_date)

DESCRIPTION ^

 match_autosal_raw_dat - Match the samples from the *.dat with the raw values in *.raw
 
 CTD Calibration toolbox
 
 INPUT: 
   salts: structure containing salinity bottle samples from *.dat files
   raw: structure containing the raw values comprising the averages
             in the salts structure above.  As read from the *.raw files.
     outfile: path and name of the output sample summary log file.
    date: 3 by 1 matrix of the year month and day of the analysis.
 


 OUTPUT:
   theResult: Summary structure containing the revised sample analysis results.

 DESCRIPTION:    


 
 

 SEE ALSO:
            read_autosal_dat
            read_autosal_raw

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function theResult  = match_autosal_raw_dat(salts,raw,outfile,analysis_date)
0002 % match_autosal_raw_dat - Match the samples from the *.dat with the raw values in *.raw
0003 %
0004 % CTD Calibration toolbox
0005 %
0006 % INPUT:
0007 %   salts: structure containing salinity bottle samples from *.dat files
0008 %   raw: structure containing the raw values comprising the averages
0009 %             in the salts structure above.  As read from the *.raw files.
0010 %     outfile: path and name of the output sample summary log file.
0011 %    date: 3 by 1 matrix of the year month and day of the analysis.
0012 %
0013 %
0014 %
0015 % OUTPUT:
0016 %   theResult: Summary structure containing the revised sample analysis results.
0017 %
0018 % DESCRIPTION:
0019 %
0020 %
0021 %
0022 %
0023 %
0024 % SEE ALSO:
0025 %            read_autosal_dat
0026 %            read_autosal_raw
0027 %
0028 
0029 
0030 % CHANGELOG:
0031 %   08-Jul-2004, Version 1.0
0032 %        * Initial version.
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 year= analysis_date(1);
0037 month= analysis_date(2);
0038 day= analysis_date(3);
0039 hour = raw.hours;
0040 minute = raw.minutes;
0041 second = raw.seconds;
0042 cond_ratio = raw.cond_ratio;
0043 bottle = salts.samp_nbr;
0044 
0045 % Some cruises have niskin bottle pos saved in the autosal.dat files, if not
0046 % you must hand edit.
0047 if isfield(salts,'niskin_btl_pos')
0048     niskin_btl_pos_all = salts.niskin_btl_pos;
0049 else
0050     niskin_btl_pos_all = [];
0051 end
0052 
0053 % Open the new summary file.
0054 fid=fopen(outfile,'w');
0055 fprintf(fid,'%%Station\t Bottle\t Mean RT\t Std Dev RT\t Data Used\t QC  year month day hour min sec\n');
0056 
0057 k=1;
0058 limite=1;
0059 while limite <= length(bottle) 
0060     bottle_idx=find(bottle==bottle(limite,1));
0061     limite=max(bottle_idx)+1;
0062     data= cond_ratio(min(bottle_idx):max(bottle_idx),1:10);
0063     d=size(data);
0064     data=reshape(data,d(1)*d(2),1);
0065     mean_rt=mean(data);
0066     std_rt=std(data);
0067     mean_rt_new=0;
0068     std_rt_new=0;
0069     last_std=std_rt;
0070     while std_rt_new < last_std
0071          if std_rt < 0.000024
0072             aux_idx=find(data >= mean_rt-1.8*std_rt & data <= mean_rt+1.8*std_rt);
0073         else
0074             aux_idx=find(data >= mean_rt-1.45*std_rt & data <= mean_rt+1.45*std_rt);
0075         end
0076             new_data=data(aux_idx);
0077             mean_rt_new=mean(new_data);
0078             std_rt_new=std(new_data);
0079             data=new_data;
0080             mean_rt=mean_rt_new;
0081             last_std=std_rt;
0082             std_rt=std_rt_new;
0083     end
0084 
0085     % TODO: add verbose flags.
0086     % Comment these lines if you don't want it to scroll across the screen
0087     %data
0088     %length(data)
0089     %disp('hit return to continue')
0090     %pause
0091     idx = max(bottle_idx);
0092     output(k,1)= salts.station_id(idx,1);    
0093     output(k,2)=bottle(idx);
0094     output(k,3)=mean_rt;
0095     output(k,4)=std_rt;
0096     output(k,5)=length(data);
0097     %sw_sals(max(data)/2, salts.tank_temp(idx))
0098     %sw_sals(min(data)/2, salts.tank_temp(idx))
0099     output(k,6)=sw_sals(max(data)/2, salts.tank_temp(idx))-sw_sals(min(data)/2, salts.tank_temp(idx));
0100     output(k,7)=year;
0101     output(k,8)=month;
0102     output(k,9)=day;
0103     output(k,10)=hour(idx);
0104     output(k,11)=minute(idx);
0105     output(k,12)=second(idx);
0106     tank_temp(k) = salts.tank_temp(idx);
0107     if ~isempty(niskin_btl_pos_all)
0108         niskin_btl_pos(k) = niskin_btl_pos_all(idx);
0109     else
0110         niskin_btl_pos(k) = NaN;
0111     end
0112     % sw_sals(max(data)/2, salts.tank_temp(idx))
0113     % sw_sals(min(data)/2, salts.tank_temp(idx))
0114     output(k,6)=sw_sals(max(data)/2, salts.tank_temp(idx))-sw_sals(min(data)/2, salts.tank_temp(idx));
0115     k=k+1;
0116     fprintf(fid,'%d\t %d\t %1.5f\t %1.6f\t %d\t %1.4f %d\t %d\t %d\t %d\t %d\t %d\n',output(k-1,:)');
0117 end
0118 
0119 % TODO: I think the summary file is being clobbered everytime this function is called.
0120 fclose(fid);
0121 theResult.station_id=output(:,1);
0122 theResult.samp_nbr=output(:,2);
0123 theResult.cond_ratio=output(:,3);
0124 theResult.tank_temp=tank_temp(:);
0125 theResult.niskin_bottle = niskin_btl_pos(:);
0126 theResult.year= year(ones(size(tank_temp(:))));
0127 theResult.month=output(:,8);
0128 idx_23=find(output(:,10)==23);
0129 idx_0=find(output(:,10)==0);
0130 if (isempty(idx_23)==0 & isempty(idx_0)==0)
0131      output((max(idx_23)+1):length(output(:,9)),9)=output((max(idx_23)+1):length(output(:,9)),9)+1;   
0132  end
0133 theResult.day=output(:,9);
0134 theResult.hours=output(:,10);
0135 theResult.minutes=output(:,11);
0136 theResult.seconds=output(:,12);
0137 return

Generated on Fri 08-Oct-2004 11:57:17 by m2html © 2003