Answer to self:
The error was due to inserted test code at begin of file in the same script which calls that function. It appears one cannot call the function within the same script.
Error also occurs when you place code below the function you want to call.
Thank you everybody for helping.