  Working with finite numbers of modes to describe, generate and detect optical
fields can be both mathematically economical and physically useful. Such a
modal basis can map directly to various applications in communications, sensing
and processing. But, we need a way to generate and analyze such fields,
including measurement and control of both the relative amplitudes and phases of
the modal components. Here, we show first how to measure all those relative
amplitudes and phases automatically and simultaneously. The method uses a
self-configuring network of 2x2 blocks, such as integrated Mach-Zehnder
interferometers, that can automatically align itself to the optical field by a
sequence of simple one-parameter power minimizations when network elements,
such as phase shifters, are adjusted. The optical field is then directly
deduced from the resulting settings of those elements. We show how the entire
network can be calibrated for such measurements, automatically and with just
two light beams. Then, using the same calibration and running the mesh
backwards, we can also controllably generate an arbitrary multimode field.
Explicit algorithms and formulas are given for operating this system.
