function S = structurizeData(Dsys,INFO)
% Pack varying data into struct arrays for fast interpolation.
nsys = numel(Dsys);
% Grid size, consistent with INFO.GridVectors
SGS = size(Dsys);  SGS = SGS(:,SGS>1);  

% Store varying part of matrices and offsets in struct array S
% of the same size as the grid.
F = {'A','B','C','D','E','dx','x','u','y','uDelay','yDelay','xDelay'};
VARY = ([INFO.A.nv INFO.B.nv INFO.C.nv INFO.D.nv INFO.E.nv ...
   INFO.dx.nv INFO.x.nv INFO.u.nv INFO.y.nv ...
   INFO.uDelay.nv INFO.yDelay.nv INFO.xDelay.nv]>0);
if any(VARY)
   S = cell2struct(cell([SGS sum(VARY)]),F(VARY),numel(SGS)+1);
   for ct=1:nsys
      if VARY(1)
         if INFO.A.nf==0
            S(ct).A = Dsys(ct).a;
         else
            S(ct).A = Dsys(ct).a(INFO.A.iv);
         end
      end
      if VARY(2)
         if INFO.B.nf==0
            S(ct).B = Dsys(ct).b;
         else
            v = Dsys(ct).b(INFO.B.iv);  S(ct).B = v(:);
         end
      end
      if VARY(3)
         if INFO.C.nf==0
            S(ct).C = Dsys(ct).c;
         else
            v = Dsys(ct).c(INFO.C.iv);  S(ct).C = v(:);
         end
      end
      if VARY(4)
         if INFO.D.nf==0
            S(ct).D = Dsys(ct).d;
         else
            v = Dsys(ct).d(INFO.D.iv);  S(ct).D = v(:);
         end
      end
      if VARY(5)
         if INFO.E.nf==0
            S(ct).E = Dsys(ct).e;
         else
            S(ct).E = Dsys(ct).e(INFO.E.iv);
         end
      end
      if VARY(6)
         S(ct).dx = Dsys(ct).dx0(INFO.dx.iv,:);
      end
      if VARY(7)
         S(ct).x = Dsys(ct).x0(INFO.x.iv,:);
      end
      if VARY(8)
         S(ct).u = Dsys(ct).u0(INFO.u.iv,:);
      end
      if VARY(9)
         S(ct).y = Dsys(ct).y0(INFO.y.iv,:);
      end
      % Delays
      Delay = Dsys(ct).Delay;
      if VARY(10)
         S(ct).uDelay = Delay.Input(INFO.uDelay.iv,:);
      end
      if VARY(11)
         S(ct).yDelay = Delay.Output(INFO.yDelay.iv,:);
      end
      if VARY(12)
         S(ct).xDelay = Delay.Internal(INFO.xDelay.iv,:);
      end
   end
else
   S = [];
end
