This problem is solved when using another version of the code and the computations were correct. The cause to the problem is"Fix the Azimuth calculation when the azimuth is nearly horizontal. The problem occurred because the calculation in atan2 was using an absolute value of the delta latitude. When it is converted to radians, it was a small number which fell into the conditional section of software that used the absolute value of "dPhi"."The corrected .cpp file is attached as well.