Calculation of hour angle
I would suggest that this:


  LST = GMST + longitude;


line is wrong. 360 degrees of longitude correspond to 24 hours, so it should be something like:


  LST = GMST + longitude/15.0 ;


Assuming these are all in floating point and you are subsequently handling the potential overflow of time into the next day correctly...