function features = makeSVDModes(trials,CV,command)
%%%  features = makeSVDModes(trials,CV)
%%%   trials: ntasks x ntrials cell array of data
%%%   CV.parms contains
%%%           .nlags
%%%           .winSize
%%%           .winShift
%%%   features: ntasks x ntrials cell array of featurized data

if nargin > 2 && strcmp(command,'make')
  features = CV;
  return;
end

nlags = CV.parms.nlags;
winSize = CV.parms.winSize;
winShift = CV.parms.winShift;
meanSubtract = CV.parms.meanSubtract;

global previousFeatures

if isstruct(previousFeatures)
  if nlags == previousFeatures.parms.nlags && ...
	winSize == previousFeatures.parms.winSize && ...
	winShift == previousFeatures.parms.winShift && ...
	meanSubtract == previousFeatures.parms.meanSubtract
    features = previousFeatures.features;
    return;
  end
end

previousFeatures.parms.nlags = nlags;
previousFeatures.parms.winSize = winSize;
previousFeatures.parms.winShift = winShift;
previousFeatures.parms.meanSubtract = meanSubtract;

features = svdize(windowize(lagize(trials,nlags),winSize,winShift),...
    meanSubtract);

previousFeatures.features = features;
