; ============================================================
;  AUTOMATED POWER + DISTORTION ANALYSIS (RES, L, Q1, SOURCES)
; ============================================================
 
; ===================== RESISTORS R1–R9 =====================
.meas P_R1   AVG ( V(N001,N002)*I(R1) ) FROM tA TO tB
.meas Vr_R1  RMS V(N001,N002)           FROM tA TO tB
.meas Ir_R1  RMS I(R1)                  FROM tA TO tB
.meas S_R1   PARAM PwrApparent(Vr_R1, Ir_R1)
.meas Q_R1   PARAM PwrReactive(S_R1, P_R1)
.meas D_R1   PARAM sqrt(S_R1*S_R1 - P_R1*P_R1 - Q_R1*Q_R1)
.meas PctD_R1 PARAM 100*D_R1/S_R1
 
.meas P_R2   AVG ( V(N002,N003)*I(R2) ) FROM tA TO tB
.meas Vr_R2  RMS V(N002,N003)           FROM tA TO tB
.meas Ir_R2  RMS I(R2)                  FROM tA TO tB
.meas S_R2   PARAM PwrApparent(Vr_R2, Ir_R2)
.meas Q_R2   PARAM PwrReactive(S_R2, P_R2)
.meas D_R2   PARAM sqrt(S_R2*S_R2 - P_R2*P_R2 - Q_R2*Q_R2)
.meas PctD_R2 PARAM 100*D_R2/S_R2
 
.meas P_R3   AVG ( V(N006,N003)*I(R3) ) FROM tA TO tB
.meas Vr_R3  RMS V(N006,N003)           FROM tA TO tB
.meas Ir_R3  RMS I(R3)                  FROM tA TO tB
.meas S_R3   PARAM PwrApparent(Vr_R3, Ir_R3)
.meas Q_R3   PARAM PwrReactive(S_R3, P_R3)
.meas D_R3   PARAM sqrt(S_R3*S_R3 - P_R3*P_R3 - Q_R3*Q_R3)
.meas PctD_R3 PARAM 100*D_R3/S_R3
 
.meas P_R4   AVG ( V(N006,N012)*I(R4) ) FROM tA TO tB
.meas Vr_R4  RMS V(N006,N012)           FROM tA TO tB
.meas Ir_R4  RMS I(R4)                  FROM tA TO tB
.meas S_R4   PARAM PwrApparent(Vr_R4, Ir_R4)
.meas Q_R4   PARAM PwrReactive(S_R4, P_R4)
.meas D_R4   PARAM sqrt(S_R4*S_R4 - P_R4*P_R4 - Q_R4*Q_R4)
.meas PctD_R4 PARAM 100*D_R4/S_R4
 
.meas P_R5   AVG ( V(N011)*V(N011)/SJ )  FROM tA TO tB
.meas Vr_R5  RMS V(N011)                 FROM tA TO tB
.meas S_R5   PARAM ( Vr_R5*Vr_R5/SJ )
.meas Q_R5   PARAM PwrReactive(S_R5, P_R5)
.meas D_R5   PARAM sqrt(S_R5*S_R5 - P_R5*P_R5 - Q_R5*Q_R5)
.meas PctD_R5 PARAM 100*D_R5/S_R5
 
.meas P_R6   AVG ( V(N007)*V(N007)/SJ )  FROM tA TO tB
.meas Vr_R6  RMS V(N007)                 FROM tA TO tB
.meas S_R6   PARAM ( Vr_R6*Vr_R6/SJ )
.meas Q_R6   PARAM PwrReactive(S_R6, P_R6)
.meas D_R6   PARAM sqrt(S_R6*S_R6 - P_R6*P_R6 - Q_R6*Q_R6)
.meas PctD_R6 PARAM 100*D_R6/S_R6
 
.meas P_R7   AVG ( V(N009)*V(N009)/SJ ) FROM tA TO tB
.meas Vr_R7  RMS V(N009)                FROM tA TO tB
.meas S_R7   PARAM ( Vr_R7*Vr_R7/SJ )
.meas Q_R7   PARAM PwrReactive(S_R7, P_R7)
.meas D_R7   PARAM sqrt(S_R7*S_R7 - P_R7*P_R7 - Q_R7*Q_R7)
.meas PctD_R7 PARAM 100*D_R7/S_R7
 
.meas P_R8   AVG ( V(N006,N010)*I(R8) ) FROM tA TO tB
.meas Vr_R8  RMS V(N006,N010)           FROM tA TO tB
.meas Ir_R8  RMS I(R8)                  FROM tA TO tB
.meas S_R8   PARAM PwrApparent(Vr_R8, Ir_R8)
.meas Q_R8   PARAM PwrReactive(S_R8, P_R8)
.meas D_R8   PARAM sqrt(S_R8*S_R8 - P_R8*P_R8 - Q_R8*Q_R8)
.meas PctD_R8 PARAM 100*D_R8/S_R8
 
.meas P_R9   AVG ( V(N006,N008)*I(R9) ) FROM tA TO tB
.meas Vr_R9  RMS V(N006,N008)           FROM tA TO tB
.meas Ir_R9  RMS I(R9)                  FROM tA TO tB
.meas S_R9   PARAM PwrApparent(Vr_R9, Ir_R9)
.meas Q_R9   PARAM PwrReactive(S_R9, P_R9)
.meas D_R9   PARAM sqrt(S_R9*S_R9 - P_R9*P_R9 - Q_R9*Q_R9)
.meas PctD_R9 PARAM 100*D_R9/S_R9
 
.meas P_R10   AVG ( V(N004,N005)*I(R10) ) FROM tA TO tB
.meas Vr_R10  RMS V(N004,N005)            FROM tA TO tB
.meas Ir_R10  RMS I(R10)                  FROM tA TO tB
.meas S_R10   PARAM PwrApparent(Vr_R10, Ir_R10)
.meas Q_R10   PARAM PwrReactive(S_R10, P_R10)
.meas D_R10   PARAM sqrt(S_R10*S_R10 - P_R10*P_R10 - Q_R10*Q_R10)
.meas PctD_R10 PARAM 100*D_R10/S_R10
 
.meas P_R11   AVG ( V(N008)*V(N008)/SJ ) FROM tA TO tB
.meas Vr_R11  RMS V(N008)                FROM tA TO tB
.meas S_R11   PARAM ( Vr_R11*Vr_R11/SJ )
.meas Q_R11   PARAM PwrReactive(S_R11, P_R11)
.meas D_R11   PARAM sqrt(S_R11*S_R11 - P_R11*P_R11 - Q_R11*Q_R11)
.meas PctD_R11 PARAM 100*D_R11/S_R11
 
; ===================== INDUCTORS L1–L3 =====================
.meas P_L1  AVG ( V(N007,N001)*I(L1) ) FROM tA TO tB
.meas Vr_L1 RMS V(N007,N001)           FROM tA TO tB
.meas Ir_L1 RMS I(L1)                  FROM tA TO tB
.meas S_L1  PARAM PwrApparent(Vr_L1, Ir_L1)
.meas Q_L1  PARAM PwrReactive(S_L1, P_L1)
.meas D_L1  PARAM sqrt(S_L1*S_L1 - P_L1*P_L1 - Q_L1*Q_L1)
.meas PctD_L1 PARAM 100*D_L1/S_L1
 
.meas P_L2  AVG ( V(N008,N003)*I(L2) ) FROM tA TO tB
.meas Vr_L2 RMS V(N008,N003)           FROM tA TO tB
.meas Ir_L2 RMS I(L2)                  FROM tA TO tB
.meas S_L2  PARAM PwrApparent(Vr_L2, Ir_L2)
.meas Q_L2  PARAM PwrReactive(S_L2, P_L2)
.meas D_L2  PARAM sqrt(S_L2*S_L2 - P_L2*P_L2 - Q_L2*Q_L2)
.meas PctD_L2 PARAM 100*D_L2/S_L2
 
.meas P_L3  AVG ( V(N009,N010)*I(L3) ) FROM tA TO tB
.meas Vr_L3 RMS V(N009,N010)           FROM tA TO tB
.meas Ir_L3 RMS I(L3)                  FROM tA TO tB
.meas S_L3  PARAM PwrApparent(Vr_L3, Ir_L3)
.meas Q_L3  PARAM PwrReactive(S_L3, P_L3)
.meas D_L3  PARAM sqrt(S_L3*S_L3 - P_L3*P_L3 - Q_L3*Q_L3)
.meas PctD_L3 PARAM 100*D_L3/S_L3
 
; ===================== FOGAL / SCR Q1 =====================
; Q1 N006 N002 N005 0
.meas P_Q1  AVG ( V(N006)*IC(Q1) + V(N002)*IB(Q1) + V(N005)*IE(Q1) ) FROM tA TO tB
.meas Vr_Q1 RMS ( V(N006) + V(N002) + V(N005) )
.meas Ir_Q1 RMS ( IC(Q1) + IB(Q1) + IE(Q1) )
.meas S_Q1  PARAM PwrApparent(Vr_Q1, Ir_Q1)
.meas Q_Q1  PARAM PwrReactive(S_Q1, P_Q1)
.meas D_Q1  PARAM sqrt(S_Q1*S_Q1 - P_Q1*P_Q1 - Q_Q1*Q_Q1)
.meas PctD_Q1 PARAM 100*D_Q1/S_Q1
 
; ===================== SOURCES =====================
; Vgen N012 N011
.meas P_Vgen  AVG ( V(N012,N011)*I(Vgen) ) FROM tA TO tB
.meas Vr_Vgen RMS V(N012,N011)             FROM tA TO tB
.meas Ir_Vgen RMS I(Vgen)                  FROM tA TO tB
.meas S_Vgen  PARAM PwrApparent(Vr_Vgen, Ir_Vgen)
.meas Q_Vgen  PARAM PwrReactive(S_Vgen, P_Vgen)
.meas D_Vgen  PARAM sqrt(S_Vgen*S_Vgen - P_Vgen*P_Vgen - Q_Vgen*Q_Vgen)
.meas PctD_Vgen PARAM 100*D_Vgen/S_Vgen
 
; ===================== GRAND TOTALS =====================
.meas P_grand PARAM P_R1+P_R2+P_R3+P_R4+P_R5+P_R6+P_R7+P_R8+P_R9+P_R10+P_R11+P_L1+P_L2+P_L3+P_Vgen+P_Q1
.meas S_grand PARAM S_R1+S_R2+S_R3+S_R4+S_R5+S_R6+S_R7+S_R8+S_R9+S_R10+S_R11+S_L1+S_L2+S_L3+S_Vgen+S_Q1
.meas Q_grand PARAM Q_R1+Q_R2+Q_R3+Q_R4+Q_R5+Q_R6+Q_R7+Q_R8+Q_R9+Q_R10+Q_R11+Q_L1+Q_L2+Q_L3+Q_Vgen+Q_Q1
 
; Distortion grand total
.meas D_grand PARAM sqrt(S_grand*S_grand - P_grand*P_grand - Q_grand*Q_grand)
.meas Pct_real       PARAM 100*P_grand/S_grand
.meas Pct_react      PARAM 100*Q_grand/S_grand
.meas Pct_distortion PARAM 100*D_grand/S_grand
.meas PF_grand       PARAM P_grand/S_grand