%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%                    lat_tsgEXtools                         %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  This  file  is  free software ;  it  is distributed  in  %
%%  the hope that  it  will  be  useful,  but  without  any  %
%%  warranty.  You  can  redistribute  it and/or modify  it  %
%%  under  the  terms  of  the  GNU  General Public License  %
%%  as  published  by  the   Free  Software  Foundation  at  %
%%       http://www.gnu.org/copyleft/gpl.html                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% function load_TSG
%%
%% load TSG data from an .ASC file
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 25/11/2015 AD: creation 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_TSG(fname,myvar,data_interval,time_interval,mycolor)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isempty(mycolor)
mycolor='k-';
end
%%%

%[numdate,lat_tsg,lon_tsg,sst,sss,fluo]=load_TSG(fname);
[numdate,cruise_day,lon_tsg,lat_tsg,sst_tsg,sss_tsg,dens_tsg,fluo_tsg,chla_tsg]=load_TSG(fname);

ii=find(numdate>time_interval(1) & numdate<time_interval(2));
if isempty(ii)
disp('no data in the requested interval')
return
end

if strcmp(myvar,'pos')
lon=lon_tsg(ii);
lat=lat_tsg(ii);
m_plot(lon(1:200:end),lat(1:200:end),mycolor);%'k-');

elseif strcmp(myvar,'sst')
sst=sst_tsg(ii);

sst_min=data_interval(1);
sst_max=data_interval(2);

sst(sst<sst_min)=sst_min;
sst(sst>sst_max)=sst_max;

m_scatter(lon_tsg(ii),lat_tsg(ii),10,sst,'filled','MarkerEdgeColor',mycolor);

caxis([sst_min sst_max])

elseif strcmp(myvar,'sss')
m_scatter(lon_tsg(ii),lat_tsg(ii),10,sss_tsg(ii),'filled','MarkerEdgeColor',mycolor);

elseif strcmp(myvar,'fluo')
pipo=fluo_tsg(ii);
pipo(pipo>0.5)=0.5;
pipo(pipo<0.3)=0.3;

%m_scatter(lon_tsg(ii),lat_tsg(ii),10,fluo_tsg(ii),'filled','MarkerEdgeColor',mycolor);
m_scatter(lon_tsg(ii),lat_tsg(ii),10,pipo,'filled','MarkerEdgeColor',mycolor);
colorbar

%elseif strcmp(myvar,'o2')
%m_scatter(lon_tsg(ii),lat_tsg(ii),10,o2_tsg(ii),'filled','MarkerEdgeColor',mycolor);

elseif strcmp(myvar,'chla')

chl=log(chla_tsg);

chl_min=data_interval(1);
chl_max=data_interval(2);

%chl(chl<0.02)=NaN;
%chl(chl<chl_min)=chl_min;
%chl(chl>0.4)=NaN;
%chl(chl>chl_max)=chl_max;

m_scatter(lon_tsg(ii),lat_tsg(ii),10,chl(ii),'filled','MarkerEdgeColor',mycolor);

caxis([chl_min chl_max])

colorbar

else
disp('data not available')
return

end

return

