added a function in C, the fieldtrace.py is too slow