function cnv_var=split_cnv_load(cnv_var)
%SPLIT_CNV_LOAD - splits a cnv_load structure into up cast and downcast data
% 
%USAGE -	cnv_var=split_cnv_load(cnv_var)
%
%EXPLANATION -	cnv_var returns with two additional data objects, up and down
%		composed of the up and down cast data.
%
%SEE ALSO -	
%

%PROGRAM - 	MATLAB code by c.m.duncombe rae
%
%CREATED -	2008/02/20
%	$Revision: 1.2 $
%	$Date: 2008/02/20 16:13:39 $
%	$Id: split_cnv_load.m,v 1.2 2008/02/20 16:13:39 duncombe Exp duncombe $
%
%CHANGELOG -	
%
%DISCLAIMER -	No responsibility can be accepted for failure or 
%		incorrect operation of this code. No guarantee, express 
%		or implied, is given. 
%

% should do some checking
%	does cnv_var have all the parts that we need? (pressure)
%	if cnv_var has up and dn already, then clear them first.

fld_names=fieldnames(cnv_var);

for i=1:length(cnv_var),
   pressure=cnv_var(i).pressure;
   [x,I]=max(pressure);
   Idn=1:I;
   Iup=I:length(pressure);
   
   % the fieldnames we want are those with the same size as pressure
   for j=1:length(fld_names),
      if size(cnv_var(i).pressure) == size(cnv_var(i).(fld_names{j})),
         up.(fld_names{j})=cnv_var(i).(fld_names{j})(Iup);
         dn.(fld_names{j})=cnv_var(i).(fld_names{j})(Idn);
      end;
   end;
   cnv_var(i).up=up;
   cnv_var(i).dn=dn;
end;

return;

