Rob
Ansys Employee

I'm not going to debug the code, but common issues include data being used that's not available and insufficient UDMs being assigned in Fluent (you do this manually). 

As a more general comment, use indents to make blocks easier to read and be careful when assigning number types:

real whatever = 0 ; 

isn't great, 

real whatever = 0.0 ; 

is more appropriate.