function [trn_img,tst_img] = load_flagged_data(parms, trn_orig, tst_orig)
%
% Add 'flag' features that note the existance of a missing feature
% 
% (C) Gal Chechik 2005
  
  % Init
  [parms,do_force]   = take_from_struct(parms,'do_force', 0);
  n_trn = size(trn_orig,1); 
  [n_tst,n_features] = size(tst_orig); 
  
  % Try to load from file 
  filename = set_filenames('fild',parms);
  vars = {'trn_img','tst_img'};
  [do_calc, trn_img, tst_img] = cond_load(filename, do_force, vars{1:end});
  %trn_img = double(trn_img);
  %tst_img = double(tst_img);
  if(do_calc<1)
    return
  end
  
  data = [trn_orig;tst_orig];
  mask = ~isnan(data);
  
  flagged = zeros(n_trn+n_tst,n_features*2);
  for i=1:n_features
    ii = (i-1)*2 +1 ; 
    flagged(:,ii) = data(:,i);
    flagged(:,ii+1) = mask(:,i);    
  end
  flagged(isnan(flagged))=0;
  
  trn_img = flagged(1:n_trn,:);
  tst_img = flagged(n_trn+1:end,:);

  % Check if useful to sparsify  
  sparse_ratio = nnz(flagged) / numel(flagged);
  if sparse_ratio<0.7
    trn_img = sparse(trn_img);
    tst_img = sparse(tst_img);    
  end

  % Check if can be translated to uint
  % tmp = uint8(trn_img);
  % if (all(all(double(tmp) == trn_img)
  % 	  trn_img = uint(trn_img);
  % 	  tst_img = uint(tst_img);
  %  end
  
  % Save to disk
  fprintf('Save file "%s".\n',filename);
  save(filename,'trn_img','tst_img');
		      

  
  
  return


