%%%%%%%%%%%%%%%%%%%%%  PMDL1L1  %%%%%%%%%%%%%%
function  pmdL1L1=PMDL1L1 (x, K, sumabs, sumabsu, sumabsv, v, niter, orth, center, varvigin)
if nargin < 9 
center=1;
end
if nargin <8 
orth=0;
end
if nargin < 7 
niter=20;
end
if nargin < 6
v=[]; 
end
if nargin < 5
sumabsv=[];
end
 if nargin<4
sumabsu=[];
 end
if nargin<3
sumabs=0.4;
end
if nargin < 2 
K=1;
end
if center
   meanx=mean(x(~isnan(x)));
   x=x-meanx;
end
  if (orth )
      if isempty(sumabsu) || sumabsu < sqrt(size(x,1))
      orth =0;
      warning('Orth option ignored because sparse PCA results only when sumabsu equals sqrt(nrow(x))')
      end
  end
%%%%%Should be changed acording the size of the data, e.g. sumabsu= sqrt(size(x,1))*sumabs+0.7
  if ( isempty(sumabsu)||isempty(sumabsv))
    sumabsu= sqrt(size(x,1))*sumabs;       
    sumabsv = sqrt(size(x,2))*sumabs;
end
  if (max(abs(mean(x))) > 1e-15) 
      warning('PMDL1L1 was run without first subtracting out the mean of x.')
  end
  if (sumabsu<1 || sumabsu>sqrt(size(x,1))) 
     error ('sumabsu must be between 1 and sqrt(n)')
  end
  if ( (sumabsv<1 || sumabsv>sqrt(size(x,2))))
      error('sumabsv must be between 1 and sqrt(p)')
  end
  v = CheckPMDV(v,x,K);
  if (K>1 && ~orth) 
      out =MultiSMD(x,K,sumabsu,sumabsv,v, niter );
  else if (K>1 && orth) 
          out =MultiSMDOrth(x,K,sumabsu,sumabsv,v, niter);
      else if(K==1) 
              out = SMD(x,sumabsu,sumabsv,v, niter);
          end
      end
  end
  pmdL1L1.u=out.u;
  pmdL1L1.v=out.v;
  pmdL1L1.d=out.d;
  pmdL1L1.vinit=out.vinit;
  pmdL1L1.meanx=meanx;
  pmdL1L1.sumabsu=sumabsu;
  pmdL1L1.sumabsv=sumabsv;
  