Bulk copied from 2dlattice.c + use gengetopts Former-commit-id: 27a21038f292dc10bfbb36f3dfd509f2d0871240