do_surface_plotMatlabMap.m 5.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
function [Plots]=do_surface_plotMatlabMap(plotOPTS,FVCOM)
%
% Function to display color maps of FVCOM variables (i.e. temperature)
%
%  [Plots]=do_surface_plot(plotOPTS,FVCOM)
%
% DESCRIPTION:
%    Generates maps of variables using m_map toolbox (patch
%
% INPUT:
%   plotOPTS   = structure array with predefined options for generating the
%   maps
%   FVCOM  = data extracted from FVCOM NC file. See read_netCDF_FVCOM for
%   details
%
%   plotOPTS.range_lat: [50.1000 50.4000]
%   plotOPTS.range_lon: [-4.5000 -3.8500]
%   plotOPTS.fig_name: 'co2_S5_slowleak'
%   plotOPTS.mesh: [1x1 struct]
%   plotOPTS.coastline_file: '../mat/tamar3_0coast.mat'
%   plotOPTS.zone: 30
%   plotOPTS.ell: 'grs80'
%   plotOPTS.var_plot: 'PH'
%   plotOPTS.clims: [6 8]
%   plotOPTS.do_mesh: 0
%   plotOPTS.nz_plot: 1
%   plotOPTS.figure: 1
%   plotOPTS.Time_record: 7.3271e+05
%   plotOPTS.nz_plot_vec: 1
%   plotOPTS.data_dec: 5
%   plotOPTS.vel_sca: 5
%   plotOPTS.pause: 0.5000

%
% OUTPUT:
%   Plots = structure array with figure handles
%
% EXAMPLE USAGE
%    [Plots]=do_surface_plot(plotOPTS,FVCOM)
%
% Author(s):
%    Ricardo Torres and Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
%==============================================================================
%
% adds m_map to matlab paths. file is in utilities directory.
% amend according to your m_map installation paths

51 52 53 54 55 56
figure(plotOPTS.figure);
try delete(plotOPTS.PlotoutS(plotOPTS.figure).handles)
catch 
        clf
end

57 58
% generate figure with correct projection lat and lon range ellipsoid and
% zone.
59 60 61
if isfield(plotOPTS,'Lontick')
    MerTick = plotOPTS.Lontick;
else
62
    MerTick = floor(10*(diff(plotOPTS.range_lon)/5))/10;
63 64 65 66
end
if isfield(plotOPTS,'Lattick')
    ParTick = plotOPTS.Lattick;
else
67
    ParTick = floor(10*(diff(plotOPTS.range_lat)/5))/10;
68 69
end

70
axesm('mercator','MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon],'MeridianLabel','on',...
71
    'ParallelLabel','on','MLineLocation',MerTick,'PLineLocation',ParTick,'LabelUnits','dm')
72 73 74 75


% add coastline if present
if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) )
76 77 78 79 80 81
    if isfield (plotOPTS,'PlotoutS') && ~isempty(plotOPTS.PlotoutS(plotOPTS.figure).handles)
    else
%     coast=load(plotOPTS.coastline_file);
    geoshow(plotOPTS.coastline_file,'Color','black')
        
    end
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

end
%------------------------------------------------------------------------------
% Generate maps at a give level
%------------------------------------------------------------------------------
    mstruct = gcm;


[X, Y] = mfwdtran(mstruct,plotOPTS.mesh.lat, plotOPTS.mesh.lon);

 aa=plotOPTS.Time_record;
    fprintf('Time step %i of %i\n',aa,length(FVCOM.Time_record));
    %plot map
    hold on
    ND=ndims(FVCOM.(plotOPTS.var_plot))
    switch ND
        case 2
                Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
        'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),'edgecolor','interp','facecolor','interp');

        case 3
    Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
        'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'edgecolor','interp','facecolor','interp');
    end
    caxis(plotOPTS.clims)
    colorbar h
    % check if mesh elements are required
    if plotOPTS.do_mesh
        %plot vertices
        Plots(plotOPTS.figure).mesh=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
            'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on

    end
%      setm(gca,'MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon])
     tightmap
    %-----------------------------------------------------------------------
    % Only in my case it needs adding 6 because proj automatically determines a
    % reference long in strides of 6deg while m_map doesn't
    %------------------------------------------------------------------------
    pause(plotOPTS.pause)
%     if aa~=length(plotOPTS.Time_record)
%         delete(Plots(plotOPTS.figure).handles(:))
%     end

%  end

 
 
 
 
 
 
%  fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record));
%     %plot map
%     hold on
%     Plots(plotOPTS.figure).handles=patch('Vertices',[lat,lon],'Faces',plotOPTS.mesh.tri,...
%         'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'edgecolor','interp','facecolor','interp');
% 
%     caxis(plotOPTS.clims)
%     colorbar
%     % check if mesh elements are required
%     if plotOPTS.do_mesh
%         %plot vertices
%         Plots(plotOPTS.figure).mesh=patch('Vertices',[lon,lat],'Faces',plotOPTS.mesh.tri,...
%             'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
% 
%     end
%     setm(gca,'MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon])
%     %-----------------------------------------------------------------------
%     % Only in my case it needs adding 6 because proj automatically determines a
%     % reference long in strides of 6deg while m_map doesn't
%     %------------------------------------------------------------------------
%     pause(.2)
%     if aa~=length(plotOPTS.Time_record)
%         delete(Plots(plotOPTS.figure).handles(:))
%     end
% 
% end
% 
return