% script to extract an xz slice through a data matrix
% i.e. zonal, looking north
% matrix returned has rows of z and columns of x
%
% function slc = getxz(y_index,flg);
%
% input variables
%   y_index  zonal (latitude) 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 getyz

function slc = getxz(y_index,flg);

global DATA NX NY NZ

% check input arguments

if(y_index > NY | y_index < 1 | y_index ~= round(y_index))
  error('illegal Y index in getxz function');
end

if nargin < 2
  flg = 0;
end

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

else                                 % old style DATA format

  % DATA matrix is set up as NX rows and NY*NZ columns
  slc = DATA(:,[y_index:NY:NY*NZ]);
  slc = slc';
  if flg==2, slc=flipud(slc); end    % flip z

end
