function [C Ceq] = MCHE_constraints_area(x,d,parameters)

global h

hyCase = h.Activedocument;
sol=hyCase.Solver;
f = hyCase.Flowsheet;

sol.CanSolve = 0 ;

x = parameters.scale_x*x ;

%Reset optimization variables
f.MaterialStreams.Item('MR10').PressureValue = x(1) ;
f.MaterialStreams.Item('MR17').PressureValue = x(2) ; 
f.MaterialStreams.Item('MR10').MolarFlowValue = x(3) ;
f.MaterialStreams.Item('C2').MolarFlowValue = x(4) ;
f.MaterialStreams.Item('C3').MolarFlowValue = x(5) ;
f.MaterialStreams.Item('N2').MolarFlowValue = x(6) ;


%Reset disturbances
f.MaterialStreams.Item('NG4').TemperatureValue = d(1) ; % degrees C
f.MaterialStreams.Item('NG4').PressureValue = d(2) ; % kilopascal
f.MaterialStreams.Item('NG4').MolarFlowValue = d(3); %mol/s
f.MaterialStreams.Item('MR10').TemperatureValue = d(1);

rcy = parameters.recycles;
switch rcy
    case('matlab')
        f.MaterialStreams.Item('MR16a').TemperatureValue = x(7) ;
        f.MaterialStreams.Item('MR19a').TemperatureValue = x(8) ;
        f.Operations.Item('RCY-2').IsIgnored = 1;
        f.Operations.Item('RCY-3').IsIgnored = 1;
    case('unisim')
        f.MaterialStreams.Item('MR16a').TemperatureValue = -157 ; %Starting guess for recycle. Should remain near constant.
        f.MaterialStreams.Item('MR19a').TemperatureValue = -95 ; % Use a "too cold" starting point for stream MR19  
        f.Operations.Item('RCY-2').IsIgnored = 0;
        f.Operations.Item('RCY-3').IsIgnored = 0;
end

sol.CanSolve = 1 ;

%Check if recycles are converged!
con1 = strcmp('Converged',f.Operations.Item('RCY-2').RecycleConvergence) ;
con2 = strcmp('Converged',f.Operations.Item('RCY-3').RecycleConvergence) ;

%Inequality constraints:

switch rcy
    case('matlab')
        if f.Operations.Item('MCHE, cold part').Duty.IsKnown==1
            C=zeros(2,1) ;
            C(1) = (f.MaterialStreams.Item('Subcooled NG').TemperatureValue +157.1099)  ; % Maximum temperature of subcooled natural gas
            C(2) = (-1*f.Operations.Item('SPRDSHT-1').Cell('C1').CellValue) ; % Superheating of mixed refrigerant
        else
            C = ones(2,1) ;
        end
    case('unisim')
        if f.Operations.Item('MCHE, cold part').Duty.IsKnown==1 && con1==1 && con2 ==1
            C=zeros(2,1) ;
            C(1) = (f.MaterialStreams.Item('Subcooled NG').TemperatureValue +157.1099)  ; % Maximum temperature of subcooled natural gas
            C(2) = (-1*f.Operations.Item('SPRDSHT-1').Cell('C1').CellValue) ; % Superheating of mixed refrigerant
        else
            C = ones(2,1) ;
        end
end
%Equality constraints

switch rcy
    case('matlab')
        if f.Operations.Item('MCHE, cold part').Duty.IsKnown == 1
            Ceq = [ f.MaterialStreams.Item('MR16').TemperatureValue - f.MaterialStreams.Item('MR16a').TemperatureValue ; 
                    f.MaterialStreams.Item('MR19').TemperatureValue - f.MaterialStreams.Item('MR19a').TemperatureValue ] ; 
        elseif f.Operations.Item('MCHE, cold part').Duty.IsKnown == 0
            Ceq =[1 ; 1 ];
        end
    case('unisim')
        Ceq = [] ;
end
end