Try using lookup tables. I found this much simpler to set up than trying to use a precise formula to find d/D. You can find all the values you should need from Appendix E: Area, Wetted Perimeter and Hydraulic Radius of Partially Filled Circular Pipes in the Civil Engineering Refernce Manual, 6th Edition, Lindeburg 1998 (or other reference text). If you need more precision, you can interpolate from the values in the table...