Simply the best answers.

How to create mass weighted average function by UDF on a surface? (not on a zone or thread)

The following UDF allows you to compute mass weighted average of temperature based on any surface. You just have to provide surface ID.
#include "udf.h"
#include "surf.h"
#include "cxsurf.h"
#include "cxiface.h"