function [OUT2, INN, OUT, InitPoints, TinitStruc, lines, friends, tim, GenInfo] = computeafsRAY(hObject, MaxLang, RefLevel, MaxFunC, epsFun, epsRand, noiseC, noiseA, h0, s, U, S, V, InitT, calcp)
k = size(U,1);
n = size(V,1);

actpwd = pwd;
cd(calcp);

dlmwrite('wrap/allg.txt',[k;n;s;MaxLang;MaxFunC],'precision','%d');
dlmwrite('wrap/allg.txt',[epsFun;epsRand;noiseC;noiseA;h0],'-append','precision','%e');
dlmwrite('wrap/allg.txt',[RefLevel],'-append','precision','%d');
dlmwrite('wrap/R.txt',V(:,1:s)','precision','%15.15e','delimiter',' ');
dlmwrite('wrap/L.txt',U*S(:,1:s),'precision','%15.15e','delimiter',' ');
dlmwrite('wrap/InitT.txt',InitT,'precision','%15.15e','delimiter',' ');
dlmwrite('wrap/tim.txt',0,'precision','%d');

arch = computer('arch');

set(gcf,'Pointer','Watch');
pause(0.5);
set(hObject,'Enable','on');

if (strcmp(arch,'maci64') == 1) || (strcmp(arch,'maca64') == 1)
    system('./StretchM64.exe 1');
elseif (strcmp(arch,'win32') == 1) || (strcmp(arch,'win64') == 1)
    system('StretchW32.exe 1');
elseif strcmp(arch,'glnx86') == 1
    system('./StretchU32.exe 1');
elseif strcmp(arch,'glnxa64') == 1
    system('./StretchU64.exe 1');
else
    fprintf(2,'No executable version for this type of system.\n');
    GenInfo = -2;
    OUT2 = [];
    INN = [];
    OUT = [];
    InitPoints = [];
    lines = [];
    friends = [];
    tim = 0;
    set(gcf,'Pointer','arrow');
    cd(actpwd);
    return;
end
set(hObject,'Enable','on');

tim = load('wrap/tim.txt');

if tim(1) == 0
    GenInfo = -3;
    OUT2 = [];
    INN = [];
    OUT = [];
    InitPoints = [];
    lines = [];
    friends = [];
    tim = 0;
    cd(actpwd);
    return;
else
    GenInfo = 1;
    AFS = load('wrap/AFS.txt');
    friends = load('wrap/friends.txt');
    
    TinitStruc = AFS(1,6:9);
    for i=1:4
        if TinitStruc(i) == 3
            lines{i}.pts = [AFS(2+i,1:3); AFS(2+i,4:6); AFS(2+i,7:9)];
            lines{i}.friends = friends(i,:);
            lines{i}.id = i;
        else
            lines{i}.pts = [];
            lines{i}.friends = [];
        end
    end
    
    friends = friends(5:end,:);
    
    OUT = AFS(7:end-4,:);
    ind = [1:size(OUT,1) 1];
    
    OUT2 = OUT(:,7:9);
    INN = OUT(:,4:6);
    OUT = OUT(:,1:3);
    
    InitPoints.i1i2 = [AFS(2,1:2); AFS(2,3:4); AFS(2,5:6); AFS(2,7:8)];
    InitPoints.points = AFS(end-3:end,:);
    
    tim = tim(2);
    
    set(gcf,'Pointer','arrow');
    cd(actpwd);
end



