function sc = scale(x, d, unit)
if unit=='com'
  sc = scale_compressor(x, d);
elseif unit=='con'
  sc = scale_condenser(x, d);
elseif unit=='val'
  sc = scale_valve(x, d);
elseif unit=='vap'
  sc = scale_evaporator(x, d);
end

function sc = scale_evaporator(x, d)
sc.x = abs([x(1:3);
            sum(x(4:5))*ones(2, 1);
            d.Vvap;
            x(end);
            ]);
           
sc.res = abs([x(3);
              x(3);
              sum(x(4:5))*ones(2, 1);
              x(end);
              ]);

function sc = scale_valve(x, d)
sc.x = abs(x);
sc.res = abs([x(1); x(3)]);

function sc = scale_compressor(x, d)
sc.x = abs(x);
sc.res = abs(x);

function sc = scale_condenser(x, d)
sc.x = abs([x(1:5);
            sum(x(6:10))*ones(5, 1);
            sum(x(11:15))*ones(5, 1);
            sum(x(16:19))*ones(4, 1);
            sum(x(20:21))*ones(2, 1);
            1;
            x(23);
            ]);
            
sc.res = abs([sum(x(11:15))*ones(2*(2+d.ncon_sub), 1);
              sum(x(6:10))*ones(2, 1);
              sum(x(16:21))*ones(6, 1);
              x(23);
              x(1:4);
              ]);
