%first read file names to obtain the date and time of the measurements
clear all
close all

load('/Volumes/Boss_SSD/Perseverance/prod/Perseverance_InLine_TSG_20260120_20260220_Product_v20260221.mat');
B=dir('./HyperPro136_2026*.raw')
for i=1:length(B)
   yr(i)=2026;
   mo(i)=str2num(B(i).name(17:18));
   dd(i)=str2num(B(i).name(19:20));
   hh(i)=str2num(B(i).name(22:23));
   mm(i)=str2num(B(i).name(24:25));
   ss(i)=str2num(B(i).name(26:27));
   stndate(i)=datetime(yr(i),mo(i),dd(i),hh(i),mm(i),ss(i));
end

for i=1:length(B)
    I=find(abs(stndate(i)-tsg.dt)==min(abs(stndate(i)-tsg.dt)));
    Lon(i)=tsg.lon(I(1));
    Lat(i)=tsg.lat(I(1));
end



%% input high/low map resolution  
%mresol=input('map/bathy resolution :high map & bathy =2, high bathy & low map =1, low all=0')
%if isempty(mresol)
    mresol=0;
%end


figure(1) 
clf
  maxmap=[5 1 0.5]
  bg=1
  

 m_proj('Stereographic','longitude',170,'latitude',-74,'radius',5);

 sondes=[-5000 -3000 -2000 -1000 -500 -250 -0];
 if mresol== 0  % low map and low bathy resolution
     m_coast('patch',[.7 .7 .7],'edgecolor','k');
     m_elev('contour',sondes);
 elseif mresol== 1  % low map and high bathy resolution
     m_coast('patch',[.7 .7 .7],'edgecolor','k');
     m_tbase('contour',sondes','linecolor','k');
 elseif mresol== 2  % high map and high bathy resolution
     m_gshhs_h('save', 'gumby');
     m_usercoast('gumby','patch',[.7 .7 .7],'edgecolor','k');
     m_tbase('contour',sondes,'linecolor','k');
 end
 m_grid;
 II=isfinite(Lat);
 [lon,lat]=m_ll2xy(Lon(II),Lat(II));
 hold on
 scatter(lon,lat,40,yyyymmdd(stndate),'filled')
 hold on
 caxis([min(yyyymmdd(stndate)) max(yyyymmdd(stndate))])
 xlabel('lon');
 ylabel('lat');
 title(sprintf('HTSRB and iSPEX2 stations'));
 colorbar
 grid on

 print('stations.png','-dpng')
