Reviewing some possible vendor #C code and, uh, this ain't how you integrate I^2*R over time to approximate energy. Variable names changed to protect the ... okay, okay, there are no innocent people involved in this, so I'm leaving the bad variable names in.
iit=io*io;
dii=iit-iir;
if(dii>0) {
sum_iit+=dii;
} else {
sum_iit+=0;
}
Don't worry: it's only safety-related code! Pay no attention to the fire in the corner.
Sheesh.