On the theory of nuclear reactions: (I). Shell-model calculations in the continuum