function cc = contour2lines(in)

    if isa(in, 'matlab.graphics.chart.primitive.Contour')
        data = in.ContourMatrix;
    elseif ismatrix(in) & size(in,1)==2
        data = in;
    else
        error('The input is not a valid data type. Must be a Contour handle or a Contour matrix of size (2,n).');
    end

    i = 1;
    idx = 1;
    while i<size(data,2)
        csize = data(2, i);
        cc(idx).level = data(1, i);
        cc(idx).x = data(1, i+(1:csize));
        cc(idx).y = data(2, i+(1:csize));
        i = i+csize+1;
        idx = idx+1;
    end
end


