In this .glsl shader
how can I port the function in line 952 in Godot?
I am not sure about the use of TEMPLATE specifically.

That is not core GLSL, these need to be parsed to work.

I know Bruneton's atmosphere model "Precomputed Atmoshperic Scattering". It is certainly one of the best, also because it works correctly from surface to space. But these days, I would suggest to leave these things to the global illumination (SDFGI) functionality of the engine. Whether that can do atmospheric scattering all the way up I don't know, yet.

For a much more comprehensive implementation that would be easier to port because it is truly stand-alone, see: https://github.com/ebruneton/precomputed_atmospheric_scattering