The invention relates to a system for mechanical ventilation comprising transducers for measurement of airway flow rate, pressure and CO2 and at least one computer that records and analysis the transducer signals. The operator defines physiological specified goals or accepts default values. Specified physiological goals relate to CO2 exchange and to volumes and pressures so as to minimise deleterious effects of ventilation. On the basis of physiological information about the respiratory system characterised according to the principle of volumetric capnography and lung mechanical parameters, the computer performs analytical calculations in order to identify one or more modes of ventilator operation leading to specified goals. Such a mode of operation is implemented manually or automatically in one or more steps. The physiological outcome of resetting is reported and an alarm is issued when the outcome deviates from expectations. The computer may perform repeated automatic measurements and repeat the resetting in order to reach and maintain a status of the patient coherent with specified goals.