% script to extract an yz slice through a data matrix
% i.e. meridional, looking east
% matrix returned has rows of z and columns of y
%
% function slice = getyz(x_index,flg);
%
% input variables
%   x_index  meridional (longitude) index of slice
%   flg      0 defaults to new style DATA format, see readmodel.m
%            1 old style, do not flip z
%            2 old style, flip z
%
% required global variables
%   DATA     input data matrix created with readmodel
%   NX       zonal model dimension
%   NY       meridional model dimension
%   NZ       vertical model dimension
%
% see readmodel getxy getxz

function slc = getyz(x_index,flg);

global DATA NX NY NZ

% check input arguments

if nargin < 2
  flg = 0;
end

if(x_index > NX | x_index < 1 | x_index ~= round(x_index))
  error('illegal X index in getyz function');
end

if flg==0                            % new style DATA format
  
  % DATA matrix is set up as NZ rows and NY*NX columns
  slc = DATA(:,x_index:NX:NX*NY);

else                                 % old style DATA format

  % DATA matrix is set up as NX rows and NY*NZ columns
  slc = DATA(x_index,:);
  slc = reshape(slc,NY,NZ);
  slc=slc';
  if flg, slc = flipud(slc); end

end

% DATA matrix is set up as NY*NZ rows, and NX columns.

