% TI096_st_loc_ctd_H.m
% Tioga-171, Tioga-177, ... CTD data: Plot Station locations 
% Olga Kosnyreva, AOPE/WHOI, 5/5/2006
%
% I N P U T:
% CTD Stations list.
% Filenames: ti171_ctd_list.mat (or .txt), ti177_ctd_list.mat (or .txt), ...
% Variables:
% 1 - cast#
% 2 - year
% 3 - month
% 4 - day
% 5 - hour
% 6 - minute
% 7 - second
% 8 - decimal latitude
% 9 - decimal longitude

clear;
flops(0);
% Make JPG printfiles.
%saveOption='yes';
saveOption='no';
% ---- MENU: Tioga cruise
% MENU: Depth.
crNum=f_menu_of_numbers_title('Tioga cruise',[171 177]);
if isempty(crNum), return; end
if crNum==171
   path_name='~/tioga_2006/ti171/CTD/process/';
   ctdList=1:29;
   date_str='April (11 - 12), 2006'; 
   cruise_title='R/V Tioga TI171';
   cruise_id='ti171'; 
elseif crNum==177
   path_name='~/tioga_2006/ti177/ctd/process/';
   ctdList=1:29;
   date_str='April (25 - 26), 2006';
   cruise_title='R/V Tioga TI177';
   cruise_id='ti177';
end
%******************
% C O N S T A N T S
%******************
% Print file type.
printFile='ps'; % and PNG
%printFile='jpg';
if strcmp(printFile,'jpg')
   fnt_ax=8;
   fnt_lbl=10;
   fnt_title=9;
   fnt_text=8;
   fnt_text_alex=8;
   fnt_lbl_isobath=7;
   fnt_lbl_name='Symbol';
   color_txt=[0 0 0];
   marker_size=4;
   marker_face_color=[1 0 0];
   marker_edge_color=[0.6 0 0];
   line_width=0.5;
   ocean_color=[0.6 0.86 1];
   d_lat=0.033;
else
   % Font size.
   fnt_ax=8;
   fnt_lbl=10;
   fnt_title=9;
   fnt_text=8;
   fnt_text_alex=8;
   fnt_lbl_isobath=6;
   fnt_lbl_name='Helvetica';
   color_txt=[0 0 0];
   marker_size=3;
   marker_face_color=[1 0 0];
   marker_edge_color=[1 0 0];
   line_width=0.8;
   ocean_color=[1 1 1];
   d_lat=0.029+0.005;
end
%
% Land, ocean, isobaths color .
color_page_title=[0.4 0.4 0.4];
bnd_color=[0.71 0.66 0.43];
land_color=[0.8 0.8 0.66];
isobaths_color=[0.38 0.41 1];
color_lbl=isobaths_color;
fig_color=[1 1 1];
% Draw coast line.
drawCoast='yes';
%drawCoast='no';
%**************************
%* C O N S T A N T S (4)
% dependig on Mapping area.
%**************************
% Map area.
%mapArea='full';
%mapArea='forJPG';
%mapArea='area1';
%mapArea='area2';
mapArea='spec1_Mass';
if strcmp(mapArea,'full')
   latmin = 41;
   latmax = 45.5;
   lonmax = 71;
   lonmin = 65;
elseif strcmp(mapArea,'forJPG')
   latmin = 42;
   latmax = 45.2;
   lonmax = 71;
   lonmin = 65.8-0.2-0.1;
elseif strcmp(mapArea,'area1')
   latmin = 43.1;
   latmax = 44.1;
   lonmin = 68.3;
   lonmax = 70;
elseif strcmp(mapArea,'area2')
   latmin = 43.1;
   latmax = 44.2;
   lonmin = 67.9;
   lonmax = 70.25;
elseif strcmp(mapArea,'spec1_Mass')
   latmin = 41.45;
   latmax = 42.8;
   lonmax = 71+0.1;
   lonmin = 69.7;
else
   latmin = 43.1;
   latmax = 44.2;
   lonmin = 67.9;
   lonmax = 70;
end
%**************************************************************************
%***********************   LOAD CTD DATA LIST   ***************************
%**************************************************************************
p=['load ti' num2str(crNum) '_ctd_list;'];
eval(p);
p=['c_list=ti' num2str(crNum) '_ctd_list;'];
eval(p);
% Column#.
ctd_colSt=1;
ctd_colYear=2;
ctd_colMon=3;
ctd_colDay=4;
ctd_colHour=5;
ctd_colMin=6;
ctd_colLat=8;
ctd_colLon=9;
%*********************************************************************
%*********************************************************************
%******************************
% Set figure, axes properties.
%******************************
figure;
set(gcf,'position',[137 415 342 421],'color',fig_color,...
   'paperPositionMode','auto'); 
%******************************
% (Use the Matlab function PLOT).
%******************************
%**************************************************************************
%*******************  Draw coast, land, bathymetry  ***********************
%**************************************************************************
% Coast, land, bathymetry: use Isobats and Coastline data and the Matlab function PLOT);
% Landfill: use OPNML and marm_ll_g2s_moody the grid.
if strcmp(drawCoast,'yes')
   %load coast_ecohab.dat;  % Lat: 40 - 45, Long: (-75) - (-69) coast line
   load isobat200.dat;
   load isobat50.dat;
   %ind=find(~isnan(coast_ecohab(:,1)));
   isobat50(:,1)=-isobat50(:,1);
   isobat200(:,1)=-isobat200(:,1);
   hold on;
   %plot(-coast_ecohab(ind,1),coast_ecohab(ind,2),'.','color',bnd_color,'markersize',1);
   hi_1=plot(isobat200(:,1),isobat200(:,2),'-','color',isobaths_color,'linewidth',0.7);
   hi_2=plot(isobat50(:,1),isobat50(:,2),'-','color',isobaths_color,'linewidth',0.7); 
   hold off;
   % Put labels - isobath50.
   r_lbl = find(isobat50(:,2)>41.8 & isobat50(:,2)<42 & isobat50(:,1)<70.2 & isobat50(:,1)>69.8);
   text(isobat50(r_lbl(1),1),isobat50(r_lbl(1),2),'50','horizontalAlignment','center',...
      'verticalAlignment','middle',...
      'Fontsize',fnt_lbl_isobath,'color',color_lbl,'fontAngle','it');
   r_lbl = find(isobat50(:,2)>43 & isobat50(:,2)<43.5 & isobat50(:,1)<66.5 & isobat50(:,1)>66);
   text(isobat50(r_lbl(1),1),isobat50(r_lbl(1),2),'50','horizontalAlignment','center',...
      'verticalAlignment','middle',...
      'Fontsize',fnt_lbl_isobath,'color',color_lbl,'fontAngle','it');
   % Put labels - isobath200.
   r_lbl = find(isobat200(:,2)>42.2 & isobat200(:,2)<42.3 & isobat200(:,1)<69.9 & isobat200(:,1)>69.7);
   text(isobat200(r_lbl(end),1),isobat200(r_lbl(end),2),'200','horizontalAlignment','center',...
      'verticalAlignment','middle',...
      'Fontsize',fnt_lbl_isobath,'color',color_lbl,'fontAngle','it');
   r_lbl = find(isobat200(:,2)>41.5 & isobat200(:,2)<42.2 & isobat200(:,1)<68.5 & isobat200(:,1)>68);
   text(isobat200(r_lbl(1),1),isobat200(r_lbl(1),2),'200','horizontalAlignment','center',...
      'verticalAlignment','middle',...
      'Fontsize',fnt_lbl_isobath,'color',color_lbl,'fontAngle','it');
   % Draw isobaths,  land boundaries, land fill.
   %  load 'structure fields' for MARMAP1 mesh:
   %  mp - cartesian, mm - geographycal coordinate 
   %marm_ll_g2s_moody
   load land_data;
   mm=land_data;
   mm.x=-mm.x;
   mm.lnd(:,1)=-mm.lnd(:,1);
   % Draw land fill.
   hold on;
   lndfill(mm,land_color);
   hold off;
end  % for if strcmp(drawCoast,'yes')
%******************
% CTD latitude and longitude.
%******************
l = c_list(:,ctd_colLat);
g = c_list(:,ctd_colLon);
hold on;
%*****************
% Plot station locations.
%******************
plot(g,l,'ko','markersize',marker_size,...
          'markeredgecolor',marker_edge_color,...
          'markerfacecolor',marker_face_color,...
          'linewidth',line_width);
hold off; 
%*****************
% Put text - stations nombers.
%*****************
for stNum=ctdList
   rsta=find(c_list(:,ctd_colSt)==stNum);
   lat = c_list(rsta,ctd_colLat);
   lon = c_list(rsta,ctd_colLon);
   text(lon,lat+d_lat,[num2str(stNum)],...
      'horizontalAlignment','center','verticalAlignment','middle',...
      'fontsize',fnt_text,'color',color_txt);
end
%*****************
% Set axes properties, labels, title.
%*****************
set(gca,'Fontsize',fnt_ax,'box','on',...
   'tickdir','out','xdir','reverse',...
   'ticklength',get(gca,'ticklength')*0.7,...
   'color',ocean_color);
axis([lonmin lonmax latmin latmax]);    % Range
xlabel('West Longitude','Fontsize',9), ylabel('North Latitude','Fontsize',9);
str1={['Station locations: ' cruise_title]};
str_title(1)={[cruise_title ', ' date_str]};
str_title(2)={['CTD Station Locations']};
title(str_title,'FontSize',fnt_title,'verticalAlignment','bottom',...
    'color',[0 0 1]);
%*****************
% Set axes position.
%*****************
ah=get(gca,'position');
set(gca,'position',[ah(1)+ah(3)*0.015 ah(2)-ah(4)*0.015 ah(3)*1 ah(4)*1 ]);
%*****************
% Calculate relation relyx = axisy/axisx (for PlotBoxAspectRatio) 
%*****************
weg = 111*cos(pi*(latmin+(latmax-latmin)/2)/180);% Weight of one degree longitude
xc = (lonmax-lonmin)*weg;                        % Longitude, km
yc = (latmax-latmin)*111;                        % Latitude, km
relyx = yc/xc;
set(gca,'PlotBoxAspectRatio',[1 relyx*1 1]);
%**************************
% Plot axes box 
% (if it gets invisible).
%**************************
hold on;
plot([lonmax lonmax],[latmin latmax],'-k',...
     [lonmin lonmin],[latmin latmax],'-k',...
     [lonmax lonmin],[latmin latmin],'-k',...
     [lonmax lonmin],[latmax latmax],'-k');
hold off;
%*******************   
% Get print file -png
% (the function fig2jpeg saves a figure in JPEG format).
%*******************
if strcmp(saveOption,'yes')
   p=['print -r100 ' cruise_id '_ctd_stloc.png -dpng'];
   eval(p);
end 
