function indx_abs=indx_calc(dims,indx_full)
%
% Call indx_abs=indx_calc(dims,indx_full);
%
% Computes a single-integer absolute index into an array given a 
% "full index" indx_full consisting of ndim columns of indices, one
% for each dimension of an N-dimensional array.  The array size is 
% given in the (1 by N) vector dims.
%
% See also indx_full_calc to go the opposite way (from indx_abs to indx_full).
%
% Example usage:
%   indx_full=indx_full_calc([nD_out,1,1,ntime,1],[]);
%   indx_full(:,2)=SP.ind_max{2}(:); indx_full(:,3)=jtau;
%   indx=indx_calc(BDT.TAU.dims,indx_full); 
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

[nset,ndim]=size(indx_full);
ndim0=length(dims);
if ndim~=ndim0, 
    eval('help indx_calc');
    error('Length of dims must be number of columns of indx_full'); 
end
dim_fac=[1,cumprod(dims(:)')];
indx_abs=ones(nset,1);
for jdim=1:ndim,
    indx_abs=indx_abs + dim_fac(jdim)*(indx_full(:,jdim)-1);
end
