load /Volumes/Boss_SSD/Perseverance/prod/Perseverance_InLine_TSG_20260120_20260309_Product_v20260313.mat

date=[datetime(2026,2,7,3,22,0)
datetime(2026,2,8,3,6,0)
datetime(2026,2,9,1,43,0)
datetime(2026,2,10,4,22,0)
datetime(2026,2,11,3,37,0)
datetime(2026,2,16,3,37,0)
datetime(2026,2,18,4,18,0)];

sst=interp1(tsg.dt,tsg.sst,date,'linear')

sss=interp1(tsg.dt,tsg.sss,date,'linear')

lon=interp1(tsg.dt,tsg.lon,date,'linear')

lat=interp1(tsg.dt,tsg.lat,date,'linear')

load /Volumes/Boss_SSD/Perseverance/prod/Perseverance_InLine_ACS57_20260120_20260309_Particulate_v20260310.mat

ap=interp1(acs_part.dt,acs_part.ap,date,'linear')

load /Volumes/Boss_SSD/TaraEuropa/Partner_data/CNR-P/Absorption_spectra_2023_4/FDOM_fit_coefficients_2023_2024.mat

fdom=interp1(acs_part.dt,acs_part.fdom,date,'linear')

cdom=fdom*ones(1,length(wl)).*p_l(:,2)'+ones(7,1)*p_l(:,1)';
wl_CDOM=wl;

cd '/Volumes/Boss_SSD/Perseverance/raw/FLNTU999'
B=dir('FLNTU999_2026012*.csv');
C=dir('FLNTU999_2026013*.csv');
D=dir('FLNTU999_202602*.csv');
E=dir('FLNTU999_202603*.csv');
B=[B;C;D;E];
tt=[];
Turb=[];
Fchl=[];
Lon=[];
Lat=[];
for i=1:length(B)
    A=rd_FLNTU(B(i).name);
    Fchl=[Fchl;A.FLNTU_Chla];
    Turb=[Turb;A.FLNTU_Turb];
    Lon=[Lon;A.lon];
    Lat=[Lat;A.lat];
    tt=[tt;datenum(char(A.dt))];
end
[C,IA,IC] = unique(tt);
Turb_interp=interp1(tt(IA),Turb(IA),datenum(date),'linear');

bbp_700=0.0163*Turb_interp;

%Prepare data for Nils:

for i=1:7
    for j=1:length(lambda.a)
    ag(i,j)=interp1(wl,cdom(i,:),lambda.a(j),'linear');
    end
end
for i=1:7
    bbp(i,:)=bbp_700(i)*(lambda.a/700).^-0.73;
end

save ForNils_IOPs bbp ag ap wavelength -mat

%% Import wind data from text file


%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 3);

% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = ",";

% Specify column names and types
opts.VariableNames = ["date", "WindDirection_deg_", "WindSpeed_m_s_"];
opts.VariableTypes = ["datetime", "double", "double"];

% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";

% Specify variable properties
opts = setvaropts(opts, "date", "InputFormat", "yyyy-MM-dd HH:mm:ss", "DatetimeFormat", "preserveinput");

% Import the data
A = readtimetable("/Volumes/Boss_SSD/Perseverance/raw/Wind_data/data_ptf_vent_SFMRARM_20260120_20260221.csv", opts, "RowTimes", "date");


%% Clear temporary variables
clear opts

wind=interp1(A.date,A.WindSpeed_m_s_,date,'linear')