function status = file_output(t, x, flag);

global y flow alt1

status = 0;

switch (flag)
    case 'init'
        alt1.t            = [];
        
        alt1.L.n          = [];
        alt1.G.n          = [];
        
        alt1.L.H          = [];
        alt1.G.H          = [];
       
        alt1.y.L.T        = [];
        alt1.y.G.T        = [];
       
        alt1.y.L.chempot  = [];
        alt1.y.G.chempot  = [];
        
        alt1.y.L.x        = [];
        alt1.y.G.x        = [];
        
        
        alt1.y.L.V        = [];
        alt1.y.G.V        = [];
                
        alt1.flow.n       = [];
               
        alt1.flow.q.LG    = [];
        alt1.flow.q.LB    = [];
        alt1.flow.H.LB    = [];
        alt1.flow.H.BG    = [];
%         alt1.flow.q.condenser = [];
        alt1.y.P          = [];
        alt1.flow.n_G_res = [];
        
    otherwise       
end

switch (flag)
    case {'init',''}
        alt1.t            = [alt1.t, t(1)];
        
        alt1.L.n          = [alt1.L.n, x(1:2,1)];
        alt1.G.n          = [alt1.G.n, x(3:4,1)];
        
        alt1.L.H          = [alt1.L.H, x(  5,1)];
        alt1.G.H          = [alt1.G.H, x(  6,1)];
       
        alt1.y.L.T        = [alt1.y.L.T,  y.L.T];
        alt1.y.G.T        = [alt1.y.G.T,  y.G.T];
       
        alt1.y.L.chempot  = [alt1.y.L.chempot,  y.L.chempot];
        alt1.y.G.chempot  = [alt1.y.G.chempot,  y.G.chempot];
        
        alt1.y.L.x        = [alt1.y.L.x,  y.L.x];
        alt1.y.G.x        = [alt1.y.G.x,  y.G.x];
                
        alt1.y.L.V        = [alt1.y.L.V, y.L.V];
        alt1.y.G.V        = [alt1.y.G.V, y.G.V];
        
        alt1.flow.n       = [alt1.flow.n, flow.n];
               
        alt1.flow.q.LG    = [alt1.flow.q.LG, flow.q.LG];
        alt1.flow.q.LB    = [alt1.flow.q.LB, flow.q.LB];
        alt1.flow.H.LB    = [alt1.flow.H.LB, flow.H.LB];
        alt1.flow.H.BG    = [alt1.flow.H.BG, flow.H.BG];
%         alt1.flow.q.condenser = [alt1.flow.q.condenser, flow.q.condenser];
        alt1.y.P          = [alt1.y.P,    y.P];
        alt1.flow.n_G_res = [alt1.flow.n_G_res, flow.n_G_res];
           
    otherwise
end
