gdata = readtable("Diel_GPP_log_QC_Revised.csv");
for mission = 1:height(gdata.MissionID)
    if isnan(gdata.StartProf(mission))
        continue
    end
    filename = char(gdata.Filename(mission));
    load(filename, 's'); % .mat file
    idiel = gdata.StartProf(mission):gdata.EndProf(mission);
    lon(mission) = mean(s.lon(idiel),'omitmissing');
    lat(mission) = mean(s.lat(idiel),'omitmissing');
    MissionID(mission) = gdata.MissionID(mission);
    StartProf(mission) = gdata.StartProf(mission);
    Mission(mission) = gdata.Mission(mission);
end
%%

ii = lon == 0;
MissionID(ii) = nan;
StartProf(ii) = nan;
lon(ii) = nan;
lat(ii) = nan;

%%
t = table(lat',lon',MissionID',StartProf',Mission',VariableNames={'lat','lon','MissionID','StartProf','Mission'});

writetable(t,'missionlatlon')