Home > ctdcal > load_salts.m

load_salts

PURPOSE ^

load_salts: Load the autosal samples into the cruise database.

SYNOPSIS ^

function theResult = load_salts(cruiseid)

DESCRIPTION ^

 load_salts: Load the autosal samples into the cruise database.
 
 CTD Calibration toolbox
 
 INPUT: 
   cruiseid: character array containing the cruise id.

 OUTPUT:
   theSalts: Combined salinity structure

 DESCRIPTION:    
  This file may need to be edited for each new cruise.  It attempts to do four things,
 each of which may be cruise dependent.  First, it reads the Ron Brown autosal
 dat and raw analysis files.  Second, it attempts to recompute an average sample
 bottle salinity by performing a more thorough quality control analysis than is done
 by the autosal logging software.  Third, it corrects for a linear drift in the autosal
 between two standardizations using standard seawater samples.  Finally, the cruise
 database is updated with the results.  Eventually it will become more cruise independent.
 
 
 AUTHOR: 
            Derrick Snowden and Carlos Fonseca
            NOAA/AOML/PhOD
            Fri Oct 01 18:32:14 EDT 2004

 CHANGELOG: 
   08-Jul-2004, Version 1.0
        * Initial version.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function theResult  = load_salts(cruiseid)
0002 % load_salts: Load the autosal samples into the cruise database.
0003 %
0004 % CTD Calibration toolbox
0005 %
0006 % INPUT:
0007 %   cruiseid: character array containing the cruise id.
0008 %
0009 % OUTPUT:
0010 %   theSalts: Combined salinity structure
0011 %
0012 % DESCRIPTION:
0013 %  This file may need to be edited for each new cruise.  It attempts to do four things,
0014 % each of which may be cruise dependent.  First, it reads the Ron Brown autosal
0015 % dat and raw analysis files.  Second, it attempts to recompute an average sample
0016 % bottle salinity by performing a more thorough quality control analysis than is done
0017 % by the autosal logging software.  Third, it corrects for a linear drift in the autosal
0018 % between two standardizations using standard seawater samples.  Finally, the cruise
0019 % database is updated with the results.  Eventually it will become more cruise independent.
0020 %
0021 %
0022 % AUTHOR:
0023 %            Derrick Snowden and Carlos Fonseca
0024 %            NOAA/AOML/PhOD
0025 %            Fri Oct 01 18:32:14 EDT 2004
0026 %
0027 % CHANGELOG:
0028 %   08-Jul-2004, Version 1.0
0029 %        * Initial version.
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 % Check for correct number of inputs.
0034 error(nargchk(1,1,nargin))
0035 
0036 % Retrieve the necessary preferences for this cruise
0037 group = group_name(cruiseid);
0038 
0039 % btl_dir is the calibration data directory
0040 if ispref(group,'cal_autosal_dir')
0041     cal_autosal_dir=getpref(group,'cal_autosal_dir');
0042 else
0043     error(['The cal_autosal_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0044 end
0045 
0046 % cruise_dir is the calibration data directory
0047 if ispref(group,'cal_data_dir')
0048     cruise_dir=getpref(group,'cal_data_dir');
0049 else
0050     error(['The cal_data_dir preference was not set for cruise: ' cruiseid '.  Run register_cruise.m']);
0051 end
0052 
0053 % This file will contain the summary information
0054 % It is currently buggy and may not work.  Nevertheless, it is intended
0055 % to be different for each cruise EDIT
0056 sumfile =  fullfile(cal_autosal_dir,'salinity_summary.txt');
0057 
0058 % EDIT
0059 year = 2002;
0060 
0061 % EDIT  If you have more than one batch of standard water per cruise you may
0062 % need to include this in the loop below and change it for each autosal file.
0063 nominal_std_conductivity = 1.999; % This is fake for testing only....
0064 std_water_label = '141';
0065 mnth = 2;
0066 day =20;
0067 
0068 % The cruise database.  Don't edit this line.
0069 db_file = fullfile(cruise_dir,[cruiseid '_db.mat']);
0070 
0071 % EDIT Maybe.  The following two lines should be pretty standard on the Brown.
0072 dat_files = dir(fullfile(cal_autosal_dir,'*.dat'));
0073 raw_files = dir(fullfile(cal_autosal_dir,'*.raw'));
0074 
0075 for idx_file = 1:length(dat_files)
0076     [pathstr,namestr,ext,vers] = fileparts(dat_files(idx_file).name);
0077     % EDIT  The file naming convention I have encountered is MMDDHH or 2 dgit monthe
0078     % two digit day and two digit gmt hour at which the autosal analysis was performed.
0079     %[mnth,day,gmthr] = strread(namestr,'%02d%02d%02d');
0080     this_dat = fullfile(cal_autosal_dir,dat_files(idx_file).name);
0081     this_raw = fullfile(cal_autosal_dir,raw_files(idx_file).name);
0082     % EDIT The raw files are pretty standard and should not need to be edited often.
0083     raw = read_autosal_raw(this_raw);
0084     % EDIT The dat files are likely different on each cruise.
0085     % Take an example read_autosal_dat_*.m and edit it according to your current configuration
0086     % then include it in the line below.  NOTE it MUST have the same input/output syntax as
0087     % examples.
0088     salts = read_autosal_dat(this_dat,std_water_label,[year mnth day]); % specialized for your cruise
0089     % If you've done the read_autosal_dat correctly, the followind two lines will work.
0090     autosal=match_autosal_raw_dat(salts,raw,sumfile,[year mnth day])
0091     cond = correct_autosal_drift(nominal_std_conductivity,autosal,sumfile);
0092     keyboard
0093     % Everything works to here for stc02.
0094     % 1. Concatentate the samples together so that they don't overwrite each other when
0095     %     saved to the db_file.
0096     % 2. Verify that the autosal struct above is what carlos needs for the make_cond_sumfile.
0097     %
0098 end
0099 
0100 
0101 % Open the output file
0102 if exist(db_file)==2
0103     save(db_file,'cond','-append');
0104 else
0105     save(db_file,'cond');
0106 end
0107 if nargout==0
0108     assignin('caller','ans',cond);
0109     return
0110 else
0111     varargout{1}=cond;
0112     return
0113 end
0114 %
0115

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