% Basix example code on how to read hourde flux database 
% Ludovic Bariteau - 04/2023
% Happy fluxing!

%% read data
ffile = ['/Volumes/NOAA_Ldisk/Backup_Lacie1TB/FluxDataBase_2_netcdf/NOAA_PSL_ship_flux_synthesis_1hr_v1.0.nc'];
ncdisp(ffile)
[FDB] = read_netcdfFile(ffile);

%% do map of all tracks - use other mapping toolbox if m_map not installed on your machine nor working properly
Lonmin = -180;       % longitudes are 0-360, going E
Lonmax = 180;
Latmin = -80;        % deg N is positive
Latmax = 80;
LatLonLim = [Lonmin Lonmax Latmin Latmax];
Marker=3;

figure;
m_proj('mercator','lon',[LatLonLim(1) LatLonLim(2)],'lat',[LatLonLim(3) LatLonLim(4)]);
m_grid('box','fancy','tickdir','in');
m_coast('linewidth',2,'color',0.5+[0 0 0]);
m_coast('patch',[.7 .7 .7],'edgecolor','none');
hw09=m_line(FDB.lon,FDB.lat,'color','r','linestyle','none','marker','.','markersize',Marker);

%% plot air and sea temperature for ATOMIC
FDBc=find(strcmp(cellstr(FDB.cruise_name),['ATOMIC 2020'])==1);  %identify columns for ATOMIC cruise
ATOMIC_doy=datenum(datetime(FDB.time(FDBc,:),'ConvertFrom','posixtime'))-datenum(FDB.year(FDBc,1),1,0,0,0,0); %converts posixtime to day-of-year
%do plot
figure;plot(ATOMIC_doy,FDB.tair(FDBc,:),'b',ATOMIC_doy,FDB.tsea(FDBc,:),'r');grid;
title('ATOMIC 2020');xlabel('DOY');ylabel('Temperatures (C)')
legend('tair','tsea')

%% display platform and trh insutrment information for ATOMIC
[FDB.platform_name(FDBc,:); FDB.platform_call_sign(FDBc,:); FDB.platform_imo_code(FDBc,:); FDB.platform_ncei_code(FDBc,:)]
FDB.trh_instrument(FDBc,:)
