close all
clear all
addpath(genpath('/Users/Mau/Documents/MATLABhelp_new/ARGO_PROCESSING-master/')); %

% Convert to ODV compatible files

% INPUTS:
%   WMO_ID  = WMO ID, as a string
%   update_str = "all" or "update"
%                 all    - to process all available msg files
%                 update - only process new msg files
%
%   HR_flag = 1 or 0, 1 to create HR txt files
%
%   dirs       = Either an empty variable or a structure with directory
%                strings where files are located. It must contain these
%                fields at a minimum or be empty. If dirs is empty default
%                paths will be used.
%
%   dirs.msg       = path to float message file directories
%   dirs.mat       = path to *.mat profile files for ARGO NETCDF
%   dirs.cal       = path to *.cal (nitrate) and cal####.mat (working float cal) files
%   dirs.config    = path to config.txt files
%   dirs.NO3config = path to ####.cal nitrate calibration files
%   dirs.temp      = path to temporary working dir
%   dirs.FV        = path to FloatViz files served to web
%   dirs.QCadj     = path to QC adjustment list for all floats
%   dirs.FVlocal   = path to Floatviz file made by matlab go here

CPF_ID='CPF003';
% dirs.mission='ParagonTests/2021-9-16T16-33-30/';
% dirs.mission='ParagonTests/MICRORIDER/2021-10-19T16-3-9/'; 
% dirs.mission='ParagonTests/MICRORIDER/2021-11-16T19-16-49/';

dirs.root=['/Volumes/CPF/',CPF_ID,'/Data/'];

% dirs.mission='ParagonTests/2022-2-23T16-59-6/'; % Paragon Test
% dirs.date=dirs.mission(14:24); % quickfix to attach date to file name.
% 
% dirs.mission='ParagonTests/MICRORIDER/2021-10-19T16-3-9/';
% dirs.date=dirs.mission(25:34); % quickfix to attach date to file name.

files=dir([dirs.root,'ParagonTests/2022-*']);
nf=length(files);

for f=1:nf;

% dirs.mission='ParagonTests/2022-2-23T16-59-6/'; % Paragon Test
dirs.mission=['ParagonTests/',files(f).name,'/'];

% dirs.date=dirs.mission(14:23); % quickfix to attach date to file name.
ddate=regexp(dirs.mission,['(?<year>\d{4})-(?<month>\d+)-(?<day>\d+)'],'names');
dirs.date=[ddate.year,'-',ddate.month,'-',ddate.day]

dirs.msg=[dirs.root,dirs.mission];
dirs.mat=[dirs.root,'matfiles/',dirs.mission];
dirs.cal=[dirs.root,'data_processing/'];

% dirs.temp='/Users/Mau/Documents/MBARIprojects/CPF/CPFPROCESSING/';
dirs.temp=['/Users/Mau/Documents/MBARIprojects/CPF/',CPF_ID,'/Data/CPFVIZ/']; % ?, not sure what is this tmp directory used for
dirs.FV=[dirs.root,'CPFVIZ/']; % NOTE, instead of copying directory tree here, I'm modifying the name of the filename output in argo2odv_LIAR_mc.m
dirs.FVlocal=['/Users/Mau/Documents/MBARIprojects/CPF/',CPF_ID,'/Data/CPFVIZ/']; %local directory to save .txt file locally
dirs.QCadj=['/Users/Mau/Documents/MBARIprojects/CPF/',CPF_ID,'/Data/CAL/QC_LISTS/']; % ?

%% To improve METADATA 
% SHOULD construct an analogous list to FLOAT_LIST 
% this would be a MISSION_LIST
% Now I am "overwriting in argo2odv_LIAR_mc
% MBARI_ID_str = 'CPF003';
% FLT_type = 'CPF';
% PROJ_Name = 'MixingExperiment';
% REGION = 'Monterey Bay';
% But should create a list like 'MBARI_float_list.mat' for each misison

proj_name='Upwelling Experiment'; % 'Mixing Experiment'; % '
region = 'Monterey Bay';
%% 

update_str ='all';
HR_flag = 0;

tf_odv = argo2odv_LIAR_mc(CPF_ID, dirs, update_str, HR_flag, proj_name, region);

end
