Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/gmt/plot_tiles_3D.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
bbc69f7867 Ed H*0001 function [rv] = plot_tiles_3D(tdat,vname,tvals,iz, opts)
0afa16fe62 Ed H*0002 
bbc69f7867 Ed H*0003 % Function [rv] = rdnctiles(res,vname,tvals,iz, opts)
0afa16fe62 Ed H*0004 %
                0005 % INPUTS
                0006 %   tdat       tile data as a struct array where:
                0007 %                tdat.gtn is the global tile number
                0008 %                tdat.var is the per-tile variable information
                0009 %   vname      string with variable name
bbc69f7867 Ed H*0010 %   tvals      vector of time ('T') values or [] for all
                0011 %   iz         depth index
0afa16fe62 Ed H*0012 %
bbc69f7867 Ed H*0013 %   opts       struct with the following optional fields
                0014 %      { 'fignum'      'figure' }  ...
                0015 %      { 'tilenums'    '[]'     }  ...
                0016 %      { 'tvname'      '''T'''  }  ...
                0017 %      { 'dblev'       '0'      }  ...
                0018 %      { 'delay'       '0'      }  ...
                0019 %      { 'radius'      '1'      }  ...
                0020 %      { 'caxis'       '[]'     }  ...
                0021 %      { 'colorbar'    '1'      }
0afa16fe62 Ed H*0022 %
                0023 % OUTPUTS
                0024 %   rv         return value (= number of tiles plotted)
                0025 %
                0026 % EXAMPLES
                0027 %
                0028 %   tl = rdnctiles({'state.*.nc' 'grid*'},[],[],[],20)
                0029 %   plot_tiles_3D(tl,'Temp',[])
                0030 %
                0031 %
                0032 %  Ed Hill
                0033 %  For debugging:
                0034 if 1 == 2
                0035   clear all ; close all
                0036   [tdat,att] = rdnctiles({'state.*.nc' 'grid*'},[],[],'bytile');
                0037   vname = 'Temp';
                0038   tvals = [];
                0039   plot_tiles_3D(tdat,vname,tvals)
                0040 end
                0041 
                0042 %====================================================================
                0043 %  Set defaults
                0044 dlev = 0;
bbc69f7867 Ed H*0045 if nargin < 4
                0046   error('There must be at least four arguments!');
0afa16fe62 Ed H*0047 end
bbc69f7867 Ed H*0048 if nargin < 5 || isempty(opts)
                0049   opts = struct();
0afa16fe62 Ed H*0050 end
bbc69f7867 Ed H*0051 
                0052 if not(isstruct(opts))
                0053   error('The "opts" argument must be a struct!');
0afa16fe62 Ed H*0054 end
bbc69f7867 Ed H*0055 opts_content = { ...
                0056     { 'fignum'      'figure' }  ...
                0057     { 'tilenums'    '[]'     }  ...
                0058     { 'tvname'      '''T'''  }  ...
                0059     { 'dblev'       '0'      }  ...
                0060     { 'delay'       '0'      }  ...
                0061     { 'radius'      '1'      }  ...
                0062     { 'caxis'       '[]'     }  ...
                0063     { 'colorbar'    '1'      }  };
                0064 for i = 1:size(opts_content,2)
                0065   if not(isfield(opts,opts_content{i}{1}))
                0066     eval(sprintf( 'opts.%s = %s;',...
                0067                   opts_content{i}{1}, opts_content{i}{2} ));
                0068   end
0afa16fe62 Ed H*0069 end
                0070 
                0071 %====================================================================
                0072 %  Check inputs
                0073 if isempty(vname)  ||  not(ischar(vname)) 
                0074   error('"vname" must be a character string')
                0075 end
                0076 if not(isstruct(tdat))  ...
                0077       || not(isfield(tdat,'gtn'))  ||  not(isfield(tdat,'var'))
                0078   error(['"tdat" must be a struct array with fields ' ...
                0079          '"gtn" and "var"'])
                0080 end
bbc69f7867 Ed H*0081 if not(isempty(opts.tilenums)) && not(isvector(opts.tilenums))
                0082   error(['"opts.tilenums" must be empty or a vector of global' ...
0afa16fe62 Ed H*0083          ' tile numbers']);
                0084 end
                0085 %  Get the valid tile numbers
bbc69f7867 Ed H*0086 if isempty(opts.tilenums)
0afa16fe62 Ed H*0087   tnall = [ tdat.gtn ];
                0088 else
bbc69f7867 Ed H*0089   tnall = intersect(opts.tilenums,[ tdat.gtn ]);
0afa16fe62 Ed H*0090   if isempty(tnall)
                0091     error(['none of the global tile numbers match the' ...
bbc69f7867 Ed H*0092            ' specified "opts.tilenums" values']);
0afa16fe62 Ed H*0093   end
                0094 end
                0095 %  Get the valid time values
                0096 have_times = 0;
                0097 if not(isempty(tvals)) && not(isvector(tvals))
                0098   error(['"tvals" must be empty or a vector of time' ...
                0099          ' values']);
                0100 end
                0101 alltimes = [];
                0102 for itile = 1:tnall
bbc69f7867 Ed H*0103   if isfield(tdat(itile).var,opts.tvname)
0afa16fe62 Ed H*0104     have_times = 1;
bbc69f7867 Ed H*0105     alltimes = union(alltimes,tdat(1).var.(opts.tvname));
0afa16fe62 Ed H*0106   end
                0107 end
4cf7d6e47a Dani*0108 tvals
                0109 alltimes
0afa16fe62 Ed H*0110 if isvector(tvals) && not(isempty(alltimes))
bbc69f7867 Ed H*0111   timelist = intersect(tvals,alltimes);
0afa16fe62 Ed H*0112 else
                0113   if isvector(tvals) && isempty(alltimes)
                0114     error(['none of the specified "tvals" values ' ...
                0115            'exist in "tdat"']);
                0116   end
                0117   if isempty(tvals) && not(isempty(alltimes))
5fa2fc1aad Ed H*0118     timelist = alltimes;
0afa16fe62 Ed H*0119   end
                0120 end
                0121 
                0122 
                0123 %====================================================================
                0124 %  Plot the tiles one-at-a-time in 3D
bbc69f7867 Ed H*0125 
                0126 itime = 1;
                0127 figure(opts.fignum)
4cf7d6e47a Dani*0128 for tval = 1%[ timelist ]
bbc69f7867 Ed H*0129   for itile = [ tnall ]
                0130     
4cf7d6e47a Dani*0131     %itime = find(tval == tdat(itile).var.(opts.tvname));
                0132     itime = 1;
0afa16fe62 Ed H*0133 
bbc69f7867 Ed H*0134     fac = pi/180;
                0135     corn = zeros([ size(tdat(itile).var.XG) 3 ]);
                0136     [ corn(:,:,1), corn(:,:,2), corn(:,:,3) ] = ...
                0137         sph2cart( fac*tdat(itile).var.YG, fac*tdat(itile).var.XG, 1 );
4cf7d6e47a Dani*0138     
bbc69f7867 Ed H*0139     %  plot3( corn(:,:,1), corn(:,:,2), corn(:,:,3), '-o' ), axis equal
                0140     %  plot( tdat(itile).var.XG, tdat(itile).var.YG, '-o' )
                0141     
                0142     cen = zeros([ size(tdat(itile).var.XC) 3 ]);
                0143     [ cen(:,:,1), cen(:,:,2), cen(:,:,3) ] = ...
                0144         sph2cart( fac*tdat(itile).var.XC, fac*tdat(itile).var.YC, 1 );
                0145     
                0146     surf( cen(:,:,1), cen(:,:,2), cen(:,:,3), ...
4cf7d6e47a Dani*0147           squeeze(tdat(itile).var.YC(:,:,1,itime)) )
bbc69f7867 Ed H*0148     if itile == 1
                0149       hold on
                0150       axis equal
                0151       r = opts.radius;
                0152       axis([ -r r -r r -r r ]);
                0153       if not(isempty(opts.caxis))
                0154         caxis(opts.caxis);
                0155       end
                0156       if opts.colorbar ~= 0
                0157         colorbar;
                0158       end
                0159     end
                0160     
0afa16fe62 Ed H*0161   end
bbc69f7867 Ed H*0162   % disp(sprintf('  plotting tile %d',itile));
4cf7d6e47a Dani*0163   %pause(opts.delay);
bbc69f7867 Ed H*0164 
0afa16fe62 Ed H*0165 end
                0166 hold off
bbc69f7867 Ed H*0167