function [realDidx,imagDidx,realGidx,imagGidx,realD,imagD,realG,imagG] = mu2amidx(ny,blk)

% Copyright 2003-2004 The MathWorks, Inc.

    nblk = length(blk);
    blkidx = cumsum([1;blk]);
    
    realGidx = [];
    imagGidx = [];
    realDidx = [];
    imagDidx = [];
    realG = [];
    imagG = [];
    realD = [];
    imagD = [];

    % USING Dr and Grc (both ny)
    if all(blk==1)
        realD = (1:nblk)';
        realG = nblk+realD;
        realDidx = [1:ny+1:(nblk-1)*ny+nblk]';
        realGidx = realDidx;
    else
        varcnt = 1;
        for i=1:nblk
            if blk(i)==1
                % [DR(i),nvar,sx] = lmivar(1,[1 1]);
                realD = [realD;varcnt];
                varcnt = varcnt + 1;
                realDidx = [realDidx;smidx(ny,blkidx(i),blkidx(i),1)];
                % [GR(i),nvar,sx] = lmivar(1,[1 1]);
                realG = [realG;varcnt];
                varcnt = varcnt + 1;
                realGidx = [realGidx;smidx(ny,blkidx(i),blkidx(i),1)];
            else
                smsize = blk(i)*(blk(i)+1)/2;
                sssize = blk(i)*(blk(i)-1)/2;
                % [DR(i),nvar,sx] = lmivar(1,[blkd(i) 1]);
                realD = [realD;(varcnt:varcnt+smsize-1)'];
                varcnt = varcnt + smsize;
                realDidx = [realDidx;smidx(ny,blkidx(i),blkidx(i),blk(i))];
                % [DI(i),nvar,sx] = lmivar(3,skewdec(blkd(i),nvar));
                imagD = [imagD;(varcnt:varcnt+sssize-1)'];
                varcnt = varcnt + sssize;
                imagDidx = [imagDidx;ssmidx(ny,blkidx(i),blkidx(i),blk(i))];
                % [GR(i),nvar,sx] = lmivar(1,[blkd(i) 1]);
                realG = [realG;(varcnt:varcnt+smsize-1)'];
                varcnt = varcnt + smsize;
                realGidx = [realGidx;smidx(ny,blkidx(i),blkidx(i),blk(i))];
                % [GI(i),nvar,sx] = lmivar(3,skewdec(blkd(i),nvar));
                imagG = [imagG;(varcnt:varcnt+sssize-1)'];
                varcnt = varcnt + sssize;
                imagGidx = [imagGidx;ssmidx(ny,blkidx(i),blkidx(i),blk(i))];
            end
        end
    end

