How to close a section of a sphere flat while retaining closest shape? I'd like to cap an irregular section of a sphere with a flat surface while not modifying the section shape:



I'd like to get to s.t. like this:



but without the errors (non manifold vertex with 3 points of junctions)
Starting from the section above, I normally would select non manifold (the border) with Alt-Ctrl-Shift-M then create face, fill, or grid fill. But all these create non manifold artifacts. 
Or I could use loop tools; but they modify the shape. My question:
How can create s.t like the second image, that is close the surface optimally, without artifacts and respecting starting shape? Just adding to the outside of the shape so as to keep it closest to the original?
Hope I've been clear... is there a way? Scripting is ok, too...

The blend
This can be accomplished pretty easily with the knife tool.



I first positioned the object how I wanted it, and then pressed k, clicked on one point outside the mesh, then moved the mouse to the opposed side, and clicked to create a cut like the one above. Then all you need to do is delete all the vertices of the sphere to the right of the cut, and the knife tool will have created a smooth edge for your sphere segment.

One possible issue is that the knife tool only does the half of the sphere facing you. In that case, delete the half of the sphere you can't see, and use a mirror modifier to duplicate the side with the knife cut so it makes a full sphere again.

Final result: