clear all
close all
addpath(genpath('/Volumes/Chem/ARGO_PROCESSING/MFILES/FLOATS/'));
% addpath(genpath('/Users/Mau/Documents/MBARIprojects/CPF/CPFPROCESSING'));
% addpath(genpath('/Users/Mau/Documents/MATLABhelp_new')); % for
% betasw_ZHH2009.m
%% Calculate DERIVED VARIABLES for BGC sensors

% Path to CPF data:
path_data='/Volumes/CPF/CPF003/Data/TankTests/2021-8-11T20-6-55/'; % use parse_CPFmsg_v3(msg_file);
path_data='/Volumes/CPF/CPF003/Data/TankTests/2021-8-25T19-5-6/'; % latest tank test

cast='001'; %
msg_file = [path_data,'CPF003.',cast,'.msg'];
isus_file = [path_data,'CPF003.',cast,'.isus'];
% NOTE: AirCalData only for .001.msg file?

%%  load data from msg files
d=parse_CPFmsg_v4(msg_file);
data=d;

%%  get cal data
get_cpf_cals_mc
% cal.type='4330'; %otherwise, calc_O2_4ARGO.m gets stuck

% % SET DATA FILL VALUES
fv.bio = NaN; %99999;
fv.QC  = NaN; %99;

%% VALID BIO ARGO RANGE CHECKS - RAW DATA [MIN MAX]
% values and code above from Process_APEX_float.m
% last modification 07/13/21 JP

RCR.P     = [0 12000];
RCR.S     = [26 38]; % from argo parameter list
RCR.T     = [-2.5 40]; % from argo parameter list
RCR.O     = [-5 550]; % from argo parameter list
RCR.PO2   = [-5 5000]; % from argo parameter list; added to this code 5/25/21, TM: is this range right?  Should be max 500??
RCR.OP    = [10 70]; % optode phase, from argo parameter list
RCR.OT    = [-2.5 40]; % optode temperature, from argo parameter list
RCR.CHL   = [-0.1 150]; % argoBGC QC manual 09July2016
RCR.BB700 = [-0.000025 0.1]; % argoBGC QC manual 09July2016
RCR.BB532 = [-0.000005 0.1]; % argoBGC QC manual 09July2016
RCR.CDOM = [-1000 1000]; % Place Holder
RCR.NO3  = [-15 65];
RCR.PH     = [7.0 8.8];
RCR.PHV  = [-1.2 -0.7]; % Range check on pH volts
RCR.IB   = [-100 100]; % Range check on pH Ib, nano amps
RCR.IK   = [-100 100]; % Range check on pH Ik, nano amps

% VALID BIO ARGO RANGE CHECKS - QC DATA [MIN MAX]
RC.P     = [0 12000];
RC.S     = [26 38]; % from argo parameter list
RC.T     = [-2.5 40]; % from argo parameter list
RC.O     = [-5 550]; % from argo parameter list
RC.OP    = [10 70]; % optode phase, from argo parameter list
RC.OT    = [-2.5 40]; % optode temperature, from argo parameter list
RC.CHL   = [-0.1 50]; % argoBGC QC manual 09July2016
RC.BB700 = [-0.000025 0.1]; % argoBGC QC manual 09July2016
RC.BB532 = [-0.000005 0.1]; % argoBGC QC manual 09July2016
RC.CDOM  = [-1000 1000]; % Place Holder
RC.NO3   = [-10 55];
RC.PH    = [7.3 8.5];
RC.PHV   = [-1.2 -0.7]; % Range check on pH volts
RC.IB    = [-100 100]; % Range check on pH Ib, nano amps
RC.IK    = [-100 100]; % Range check on pH Ik, nano amps

% INST_ID_str = regexp(MBARI_ID_str,'^\d+', 'once','match');
crazy_val = 99990; %some ridiculous number that is less than the GDAC fill value of 99999

%% 
    % GATHER INFO FOR BUILDING ODV FILE LATER AND JUST TO MAKE LIFE
    % EASIER
    INFO.CpActivationP = d.CpActivationP;
    INFO.FwRev    = d.FwRev;
    INFO.CTDtype  = d.CTDtype;
    INFO.CTDsn    = d.CTDsn;
    INFO.FlbbMode = d.FlbbMode;
    if isfinite(INFO.FlbbMode)  && INFO.FlbbMode >0
        master_FLBB = 1;
    end
    
    INFO.sdn      = d.sdn;

%% LOW RES data coolumns

% iP=1;
% iT=2;
% iS=3;
% iNO3 = 8;
% iChl=10;
% iBb=11;

% % Identify columns in header of low res data
% % (adapted to include units and lr header names in CPF .msg files)
% iP   = find(strcmp('pres(dBar)',      d.lr_hdr) == 1); % CTD P
% iT   = find(strcmp('temp(degC)',      d.lr_hdr) == 1); % CTD T
% iS   = find(strcmp('sal(ppt)',      d.lr_hdr) == 1); % CTD S
% % iPh83  = find(strcmp('Phase',   d.lr_hdr) == 1); % SBE83 O2 phase delay
% % iT83 = find(strcmp('T83', d.lr_hdr) == 1); % SBE83 Temp (degC)
% iTo  = find(strcmp('Topt(degC)',   d.lr_hdr) == 1); % optode temp
% iTPh = find(strcmp('TPhase(deg)', d.lr_hdr) == 1); % T Phase 4330
% iRPh = find(strcmp('RPhase(deg)', d.lr_hdr) == 1); % R Phase 4330
% % iBPh = find(strcmp('BPhase', d.lr_hdr) == 1); % B Phase 3830
% ipH  = find(strcmp('pH(V)',  d.lr_hdr) == 1); % pH
% iChl = find(strcmp('FSig(counts)',   d.lr_hdr) == 1); % CHL fluor
% iBb  = find(strcmp('BbSig(counts)',  d.lr_hdr) == 1); % Backscatter
% iNO3 = find(strcmp('NO3(V)',    d.lr_hdr) == 1); % Nitrate

% Identify columns in header of low res data
% (adapted to include units and lr header names in CPF .msg files)
iP   = find(strcmp('pres_dBar',      d.lr_hdr) == 1); % CTD P
iT   = find(strcmp('temp_degC',      d.lr_hdr) == 1); % CTD T
iS   = find(strcmp('sal_ppt',      d.lr_hdr) == 1); % CTD S
% iPh83  = find(strcmp('Phase',   d.lr_hdr) == 1); % SBE83 O2 phase delay
% iT83 = find(strcmp('T83', d.lr_hdr) == 1); % SBE83 Temp (degC)
iTo  = find(strcmp('Topt_degC',   d.lr_hdr) == 1); % optode temp
iTPh = find(strcmp('TPhase_deg', d.lr_hdr) == 1); % T Phase 4330
iRPh = find(strcmp('RPhase_deg', d.lr_hdr) == 1); % R Phase 4330
% iBPh = find(strcmp('BPhase', d.lr_hdr) == 1); % B Phase 3830
ipH  = find(strcmp('pH_V',  d.lr_hdr) == 1); % pH
iChl = find(strcmp('FSig_counts',   d.lr_hdr) == 1); % CHL fluor
iBb  = find(strcmp('BbSig_counts',  d.lr_hdr) == 1); % Backscatter
iNO3 = find(strcmp('NO3_V',    d.lr_hdr) == 1); % Nitrate

iOCR1 = find(strcmp('OCRCh1_uW/cm2/nm',    d.lr_hdr) == 1); % OCR1
iOCR2 = find(strcmp('OCRCh2',    d.lr_hdr) == 1); % OCR1
iOCR3 = find(strcmp('OCRCh3',    d.lr_hdr) == 1); % OCR1
iOCR4 = find(strcmp('OCRCh4',    d.lr_hdr) == 1); % OCR1


%% 
    %GET SOME ARGO CORE PARAMTERS
    LR.PRES      = d.lr_d(:,iP);
    
    % MAKE AN ARRAY OF ZEROS FOR FILLING ARRAYS LATER
    fill0  = ones(size(LR.PRES))* 0;
    
    LR.PRES_QC          = fill0 + fv.QC;
    LR.PRES_ADJUSTED    = LR.PRES;
    LR.PRES_ADJUSTED_QC = fill0 + fv.QC;
    
    LR.PSAL             = d.lr_d(:,iS);
    LR.PSAL_QC          = fill0 + fv.QC;
    LR.PSAL_ADJUSTED    = LR.PSAL;
    LR.PSAL_ADJUSTED_QC = fill0 + fv.QC;
    
    LR.TEMP             = d.lr_d(:,iT);
    LR.TEMP_QC          = fill0 + fv.QC;
    LR.TEMP_ADJUSTED    = LR.TEMP;
    LR.TEMP_ADJUSTED_QC = fill0 + fv.QC;
    
    % CHECK FOR BAD PRESS VALUES
    LRQF_P = LR.PRES < RCR.P(1) | LR.PRES > RCR.P(2);
    LR.PRES_QC(LRQF_P)  = 4;  % BAD
    LR.PRES_QC(~LRQF_P & LR.PRES ~= fv.bio) = 1; % GOOD
    
    LR.PRES_ADJUSTED_QC(LRQF_P)  = 4;  % BAD
    LR.PRES_ADJUSTED_QC(~LRQF_P & LR.PRES_ADJUSTED ~= fv.bio) = 1; % GOOD
    
        % CALCULATE POTENTIAL DENSITY (STILL NEED TO UPDATE TO TEOS 10 !)
    potT   = theta(LR.PRES, LR.TEMP, LR.PSAL,0); % potential temp, p=0
    % USING POTENTIAL DENSITY ( per: Processing Argo OXYGEN data at the
    % DAC level Version 2.0 October 1st 2015, Chap 5)
    lr_den = density(LR.PSAL, potT); % potential density, kg /m^3
    
%% ------------------- Calculate CHLA ------------------------------------

% t_nan = isnan(data.lr_d(:,iChl)); % NaN's in data if any
% 
% LR.CHLA= (data.lr_d(~t_nan,iChl) - cal.CHL.ChlDC) .* ...
%                 cal.CHL.ChlScale;

    % ****************************************************************
    % CALCULATE CHLOROPHYLL CONCENTRATION (µg/L or mg/m^3)
    % ****************************************************************
    
    if ~isempty(iChl) % ( ~isempty(iChl) && master_FLBB ~= 0) || ...
            % (~isempty(iChl) && ~isempty(regexp(MBARI_ID_str, bad_chl_filter,'once')))
        
        % Not sure why master_FLBB variable part of the statement, seems having
        % just ~istempty(iChl) would suffice?
        % JP 03/10/20201 - There are a handful of earlier floats where the msg
        % file header indicates that an FLBB exists but there isn't one on the
        % float. For these floats the FLBB_mode = 0 from the start maybe there
        % is a better way...
        
        % Predim variables with fill values then adjust as needed
        LR.FLUORESCENCE_CHLA    = fill0 + fv.bio;
%         LR.FLUORESCENCE_CHLA_QC = fill0 + fv.QC;
        LR.CHLA                 = fill0 + fv.bio;
%         LR.CHLA_QC              = fill0 + fv.QC;
%         LR.CHLA_ADJUSTED        = fill0 + fv.bio;
%         LR.CHLA_ADJUSTED_QC     = fill0 + fv.QC;
%         LR.CHLA_ADJUSTED_ERROR  = fill0 + fv.bio;
%         INFO.CHLA_SCI_CAL_EQU   = 'not applicable';
%         INFO.CHLA_SCI_CAL_COEF  = 'not applicable';
%         INFO.CHLA_SCI_CAL_COM   = 'not applicable';
%         INFO.CHLA_DATA_MODE  = 'R'; %"not applicable" is not acceptable for this field, should be 'R' (per Coriolis)
        
        t_nan = isnan(d.lr_d(:,iChl)); % NaN's in data if any
        
        LR.FLUORESCENCE_CHLA(~t_nan)    = d.lr_d(~t_nan,iChl);
%         LR.FLUORESCENCE_CHLA_QC(~t_nan) = fv.QC;
        
        if isfield(cal,'CHL') % Sensor could be bad so maybe no cal info
            LR.CHLA(~t_nan) = (d.lr_d(~t_nan,iChl) - cal.CHL.ChlDC) .* ...
                cal.CHL.ChlScale;
%             LR.CHLA_QC(~t_nan) =  3; % 3 do not use w/o adjusting
        end
    end

%% ------------------- Calculate BBP ------------------------------------

    % ****************************************************************
    % CALCULATE PARTICLE BACKSCATTER COEFFICIENT FROM VOLUME
    % SCATTERING FUNCTION (VSF) (m^-1)
    % APEX FLBB
    % ****************************************************************
    if ~isempty(iBb) % (~isempty(iBb) && master_FLBB ~= 0) || ....
        %     (~isempty(iBb) && ~isempty(regexp(MBARI_ID_str, bad_chl_filter,'once')))
        %     if ~isempty(iBb) && master_FLBB ~= 0
        VSF                          = fill0 + fv.bio;
        BETA_SW                      = fill0 + fv.bio;
        LR.BETA_BACKSCATTERING700    = fill0 + fv.bio;
%         LR.BETA_BACKSCATTERING700_QC = fill0 + fv.QC;
        LR.BBP700                    = fill0 + fv.bio;
%         LR.BBP700_QC                 = fill0 + fv.QC;
%         LR.BBP700_ADJUSTED           = fill0 + fv.bio;
%         LR.BBP700_ADJUSTED_QC        = fill0 + fv.QC;
%         LR.BBP700_ADJUSTED_ERROR     = fill0 + fv.bio;
%         INFO.BBP700_SCI_CAL_EQU   = 'not applicable';
%         INFO.BBP700_SCI_CAL_COEF  = 'not applicable';
%         INFO.BBP700_SCI_CAL_COM   = 'not applicable';
%         INFO.BBP700_DATA_MODE  = 'R'; %"not applicable" is not acceptable for this field, should be 'R' (per Coriolis)
        
        t_nan = isnan(d.lr_d(:,iBb)); % NaN's in data if any
        
        if isfield(cal,'BB') % Sensor could be bad so maybe no cal info
            % VOLUME SCATTERING FUNCTION (VSF) (m^-1 sr^-1)
            VSF(~t_nan) = (d.lr_d(~t_nan, iBb) - cal.BB.BetabDC) ...
                .* cal.BB.BetabScale;
            % NOW CALCULATE PARTICLE BACKSCATTER COEFFICIENT
            %X       = 1.13*2*pi; % (Barnes and Antoine, 2014)
            %X       = 1.17*2*pi; % (email from E. Boss 24 May 2016)
            
            % (Proc. Bio-Argo particle backscattering at the DAC level
            % Version 1.2, July 21th 2016
            X      = 1.097*2*pi; % FLBB,BBP processing doc July 2016
            LAMBDA = 700;
            DELTA  = 0.039;      % depolarization ratio
            THETA  = 142;        % FLBBAP2 , DAC manual says 120
            BETA_SW_ind = find(t_nan == 0);
            if ~isempty(BETA_SW_ind)
                for ct = 1:size(BETA_SW_ind,1)
                    [BETA_SW(BETA_SW_ind(ct)), b90sw, bsw] = ...
                        betasw_ZHH2009(LAMBDA,d.lr_d(BETA_SW_ind(ct),iT), ...
                        THETA, d.lr_d(BETA_SW_ind(ct),iS), DELTA);
                end
            end
            %LR.BETA_BACKSCATTERING700 = VSF; % (DOUBLE CHECK SPEC say counts???)
            LR.BETA_BACKSCATTERING700(~t_nan) = d.lr_d(~t_nan,iBb); % counts
%             LR.BETA_BACKSCATTERING700_QC(~t_nan) = fv.QC; % counts
            LR.BBP700(~t_nan)    = (VSF(~t_nan) - BETA_SW(~t_nan)) * X; %b_bp m^-1
%             LR.BBP700_QC(~t_nan) = 2; % 3 do not use w/o adjusting ... 6/10/21 modify qcraw flag from 3 to 2.
            
%             % CALCULATE ADJUSTED DATA _ NO ADJUSTMENTS AT THIS TIME
%             % BUT...6/10/21 START POPULATING BBP700_ADJUSTED WITH BBP
%             % DIRECTLY!!!  KEEP ORIGINAL BLOCK IN CASE AN ACTUAL ADJUSTMENT
%             % GETS IMPLEMENTED/STORED IN THE QC MATRIX.
%             LR.BBP700_ADJUSTED(~t_nan) = LR.BBP700(~t_nan);
%             LR.BBP700_ADJUSTED_QC(~t_nan) = 1;
%             LR.BBP700_ADJUSTED_ERROR(~t_nan) = fv.bio; % PLACE HOLDER FOR NOW
%             INFO.BBP700_SCI_CAL_EQU  = 'BBP700_ADJUSTED=BBP700';
%             INFO.BBP700_SCI_CAL_COEF = [''];
%             INFO.BBP700_SCI_CAL_COM  =['BBP700_ADJUSTED is being filled with BBP700 directly in real time.  Adjustment method may be enhanced in the future.'];
%             
%             %             if isfield(QC,'BB')
%             %                 QCD = [LR.PRES, LR.TEMP, LR.PSAL, LR.BBP700];
%             %                 LR.BBP700_ADJUSTED(~t_nan) = ...
%             %                     apply_QC_corr(QCD(~t_nan,:), INFO.sdn, QC.BB);
%             %                 LR.BBP700_ADJUSTED_QC(~t_nan) =  2;
%             %                 LR.BBP700_ADJUSTED_ERROR(~t_nan) = fv.bio; % PLACE HOLDER FOR NOW
%             %                 INFO.BBP700_SCI_CAL_EQU  = 'BBP700_ADJUSTED=BBP700*A-B';
%             %                 INFO.BBP700_SCI_CAL_COEF = ['A=', ...
%             %                     num2str(QC.BB.steps(3),'%0.4f'),',B=',...
%             %                     num2str(QC.BB.steps(4),'%0.4f')];
%             %                 INFO.BBP700_SCI_CAL_COM  =['A and B determined by comparison', ...
%             %                     ' to discrete samples from post deployment calibration',...
%             %                     ' rosette cast'];
%             %             end
        end
    end

%% ------------------- Calculate O2 ---------------------------------------
% P=data.lr_d(:,iP);
% T=data.lr_d(:,iT);
% S=data.lr_d(:,iS);
% Phase=data.lr_d(:,5);
% 
% O2data = calc_O2_4ARGO(S, T, P, Phase, cal.O); % from ARGOPROCESSING/
% % OUTPUT O2data    =  [S, T, P, Phase, CalPhase, [O2], O2sol, pO2] 
% %                     units: [O2 ] = [mmol/m^3 =uM/L]
% %                             O2 sol= % Sat ; [mmol/m^3 =uM/L],
% %                             pO2 = ?

iPhase=iTPh;

    % ****************************************************************
    % CALCULATE OXYGEN CONCENTRATION
    % ****************************************************************
    if ~isempty(iPhase) % Bphase or Tphase exists so O2 data should exist
        t_nan = isnan(d.lr_d(:,iPhase));
        O2_chk = d.lr_d(:,iPhase) < RCR.OP(1) | ...
            d.lr_d(:,iPhase) > RCR.OP(2) | ...
            d.lr_d(:,iTo) < RCR.OT(1) | ...
            d.lr_d(:,iTo) > RCR.OT(2); % Flag phase, Temp out of range
        if any(O2_chk)
            disp(['Out of range phase or optode T detected for ', ...
                msg_file])
        end
        
        if strcmp(cal.O.type,'3830')
            LR.BPHASE_DOXY            = fill0 + fv.bio; % predim w fill val
            LR.BPHASE_DOXY_QC         = fill0 + fv.QC;
            LR.BPHASE_DOXY(~t_nan)    = d.lr_d(~t_nan,iBPh);
            LR.BPHASE_DOXY_QC(~t_nan) = fv.QC;
        elseif strcmp(cal.O.type,'4330')
            LR.TPHASE_DOXY            = fill0 + fv.bio;
%             LR.TPHASE_DOXY_QC         = fill0 + fv.QC;
            LR.TPHASE_DOXY(~t_nan)    = d.lr_d(~t_nan,iTPh);
%             LR.TPHASE_DOXY_QC(~t_nan) =  fv.QC;
        elseif strcmp(cal.O.type,'SBE83')
            LR.PHASE_DELAY_DOXY            = fill0 + fv.bio;
            LR.PHASE_DELAY_DOXY_QC         = fill0 + fv.QC;
            LR.PHASE_DELAY_DOXY(~t_nan)    = d.lr_d(~t_nan,iPh83);
            LR.PHASE_DELAY_DOXY_QC(~t_nan) =  fv.QC;
        end
        LR.DOXY                = fill0 + fv.bio;
        LR.DOXY_QC             = fill0 + fv.QC;
        LR.TEMP_DOXY           = fill0 + fv.bio;
        LR.TEMP_DOXY_QC        = fill0 + fv.QC;
%         LR.DOXY_ADJUSTED       = fill0 + fv.bio;
%         LR.DOXY_ADJUSTED_QC    = fill0 + fv.QC;
%         LR.DOXY_ADJUSTED_ERROR = fill0 + fv.bio;
%         INFO.DOXY_SCI_CAL_EQU  = 'not applicable';
%         INFO.DOXY_SCI_CAL_COEF = 'not applicable';
%         INFO.DOXY_SCI_CAL_COM  = 'not applicable';
%         INFO.DOXY_DATA_MODE  = 'R'; %"not applicable" is not acceptable for this field, should be 'R' (per Coriolis)
        
        if strcmp(cal.O.type,'SBE83')
            myOdata = [LR.PRES(~t_nan) LR.TEMP(~t_nan) LR.PSAL(~t_nan) lr_d((~t_nan),iPhase),lr_d((~t_nan),iTo)];
            [ppoxdoxy, O2_uM, O2_T] = Calc_SBE63_O2(myOdata, cal.O);
            LR.DOXY(~t_nan) = O2_uM ./ lr_den(~t_nan) .* 1000; % µmol/kg
        else
            %[S, T, P, Phase, CalPhase, [O2], O2sol, pO2]
            O2 = calc_O2_4ARGO(LR.PSAL(~t_nan), LR.TEMP(~t_nan), ...
                LR.PRES(~t_nan),d.lr_d((~t_nan),iPhase), cal.O); % O2 in µmol/L + more
            LR.DOXY(~t_nan) = O2(:,6) ./ lr_den(~t_nan) .* 1000; % µmol/kg
        end
        tDOXY = abs(LR.DOXY) > crazy_val & ~t_nan; % Unrealistic bad value
        LR.DOXY(tDOXY) = crazy_val; % SET TO crazy bad value
        LR.DOXY_QC(~t_nan)      = 3;
        % JP: QC assignment below not needed - crazy value greater than range limits
        %LR.DOXY_QC(tDOXY) = 4; % set crazy bad value QF to 4
        LR.TEMP_DOXY(~t_nan)    = d.lr_d(~t_nan,iTo);
        LR.TEMP_DOXY_QC(~t_nan) = fv.QC;
        % Save O2sol, pO2?
        clear O2
    end

%% ------------------- Calculate NITRATE ----------------------------------
% CHECK FOR WL_OFFSET IN ISUS NITRATE CAL
% IF IT EXISTS AND IS NOT THE DEFAULT (210), COMMENT
if isfield(cal, 'N')
    if isfield(cal.N, 'WL_offset') && cal.N.WL_offset ~= 210
        disp(['NON STANDARD WAVE LENGTH OFFSET IN NITRATE CAL = ',...
            num2str(cal.N.WL_offset)]);
    end
end
spec = parse_NO3msg(isus_file); 

Pcor_flag=0; % Pcor_flag = 1 to pressure correct ESW, otherwise don't
ncal=cal.N;
NO3 = calc_FLOAT_NO3(spec, ncal,Pcor_flag); 

% OUTPUT: NO3 =   a matrix of nitrate concentrations (umol/L) and other info
%        [SDN, DarkCur,Pres,Temp,Sal,NO3,BL_B,BL_M,RMS ERROR,WL~240,ABS~240]

%% ------------------- Calculate pH -------------------------------------
% parse_pHmsg.m
%% ------------------- Calculate LIGHT ----------------------------------

%% 
dirs.root=path_data(1:25);
dirs.mat=[dirs.root,'matfiles/',msg_file(26:end-14)]; % path to save .mat file

% create directory if it doesn't exist already
if ~exist(dirs.mat)
    mkdir(dirs.mat)
end

WMO='CPF003';
cast_num = regexp(msg_file,'\d+(?=\.msg)','once','match');
save_str=[dirs.mat, WMO,'.', cast_num,'.mat'];
save(save_str,'LR','INFO'); %save(save_str,'LR','HR','INFO');

%     % *********************************************************************
%     % SAVE THE PROFILE AS WMO_ID#.PROFILE.mat
%     % THE *.mat file will contain 3 structures:
%     %   LR      for low resolution data
%     %   HR      for high resolution data (constant profiling)
%     %   info	float info that may be of use for ARGO data stream, also
%     %           used to build ODV compatible text file from 8.mat files
%     % *********************************************************************
%     if exist('AIR_O2', 'var')
%         INFO.AIR_O2   = AIR_O2; % [p t s phase cor_phase uM uMsat pO2]
%     end
%     if exist('AIRCAL_O2', 'var')
%         % [sdn bladderPress P p t s phase cor_phase uM uMsat pO2]
%         INFO.AIRCAL_O2   = AIRCAL_O2;
%     end
%     
%     %         WMO  = INFO.WMO_ID; % string
%     %         if isempty(WMO)
%     %             disp(['NO WMO# FOUND FOR FLOAT! CREATING TEMPORARY ', ...
%     %                   'DATA DIR FOR ', INFO.UW_ID])
%     %             WMO = ['NO_WMO_',INFO.UW_ID]; % CREATE TEMPORARY WMO NAME
%     %         end
%     
%     save_str = [dirs.mat, WMO,'\', WMO,'.', cast_num,'.mat'];
%     if regexp(MBARI_ID_str, ocr_testflt, 'once')
%         save(save_str,'OCR','LR','HR','INFO');
%     else
%         save(save_str,'LR','HR','INFO');
%     end
%     %     if msg_ct == 1
%     %         copyfile(fp_cal, [dirs.mat, WMO,'\']); % copy over cal file
%     %     end