function [result] = scheme2System( fileName )
    links = zeros(100, 100);
    function [n] = getBlockNum(BlockName)
        n = -1;
        for i = 1:size(blocks,2)
            if( strcmp(BlockName, blocks(i).name) )
                n = i;
                return;
            end
        end
    end

    function makeLinks( src )
        s = fgets(f);
        while ~strcmp(strtok(s), '}')
            [s r] = strtok(s);
            if( strcmp(s, 'Branch')) 
                makeLinks(src) 
            elseif( strcmp(s, 'DstBlock') )
                r = strrep(r, ' ', '');%strtok(r);
                r = strrep(r, '"', '');
                r = strtok(r);
                s = fgets(f);
                [s r2] = strtok(s);
                r2 = strtok(r2);
                links( src, getBlockNum(r) ) = str2num(r2);
            end
            s = fgets(f);
        end
    end
    
    f = fopen(fileName, 'r');
    if( f < 0 ) 
        result = 'can not open file';
        return;
    end
    while ~feof(f) && ~strcmp(strtok(fgets(f)), 'System');
    end
    currentBlock = 1;
    while ~feof(f)
        s = fgets(f);
        if( strcmp(strtok(s), 'Block') );
            s = fgets(f);
            [s r] = strtok(s);
            if( ~strcmp(s, 'BlockType') );
                result = 'invalid file format';
                return;
            end
            r = strtok(r);
            blocks(currentBlock).type = r(1,:);
            s = fgets(f);
            [s r] = strtok(s);
            r = strrep(r, ' ', '');%strtok(r);
            r = strrep(r, '"', '');
            r = strtok(r);
            blocks(currentBlock).name = r(1,:);
            blocks(currentBlock).signs = '+';
            if( strcmp(blocks(currentBlock).type, 'Sum') )
                s = fgets(f);
                [s r] = strtok(s);
                while ~strcmp(s, '}')
                    if strcmp(s, 'Inputs')
                        r = strrep(r, '"', '');
                        r = strrep(r, '|', '');
                        r = strtok(r);
                        blocks(currentBlock).signs = r;
                    end
                    s = fgets(f);
                    [s r] = strtok(s);
                end
            elseif strcmp(blocks(currentBlock).type, 'TransferFcn')
                s = fgets(f);
                [s r] = strtok(s);
                while ~strcmp(s, '}')
                    r = strrep(r, '"', '');
                    if strcmp(s, 'Numerator')
                        numerator = poly2sym(eval(r),'s');
                    elseif strcmp(s, 'Denominator')
                        denominator = poly2sym(eval(r),'s');
                    end
                    s = fgets(f);
                    [s r] = strtok(s);
                end
                blocks(currentBlock).fcn = char(numerator/denominator);
            end
            currentBlock = currentBlock + 1;
        elseif strcmp(strtok(s), 'Line');
            s = fgets(f);
            [s r] = strtok(s);
            r = strrep(r, ' ', '');%strtok(r);
            r = strrep(r, '"', '');
            r = strtok(r);
            makeLinks( getBlockNum(r(1,:) ));
        end
    end
    eq = '';
    vars = 'syms ';
    for k = 1:size(blocks,2)
        vars = [vars, blocks(k).name, ' '];
    end
  %  vars
    eval(vars);
    vars = '';
    for k = 1:size(blocks,2)
        if ~strcmp(blocks(k).type, 'Inport')
            vars = strcat(vars, blocks(k).name, ', ');
        end
    end
    for k = 1:size(blocks,2)
        if( strcmp(blocks(k).type, 'Inport'))
            continue
        end
        eq = strcat(eq, blocks(k).name, ' = ');
        for j = 1:size(blocks,2)
            if links(j,k) ~= 0 
                if(strcmp(blocks(k).type, 'Sum'))
                    eq = strcat(eq, ' ',blocks(k).signs(links(j,k)),' ', blocks(j).name);
                elseif(strcmp(blocks(k).type, 'Outport'))
                    eq = strcat(eq, blocks(j).name);
                    outName = blocks(j).name;
                elseif strcmp(blocks(k).type, 'TransferFcn')
                    eq = strcat(eq,'(', blocks(k).fcn, ') * ', blocks(j).name);
                end
            end
        end
        eq = strcat(eq, ',');
    end
    res = eval( strcat( 'solve(eq',', ',vars,')'));
    result = eval( strcat( 'res.',outName));
    fclose(f);
end