Energy spectrum of magnetic quantum wires