@@ -1132,7 +1132,7 @@ LOCAL RC FC NEAR doIvlExprs( // evaluate and store user-input variable express
11321132 ucl = ~EVXBEGIVL; // all bits except end/post
11331133 }
11341134 else
1135- { Top.isEndOf = Top.ivl ;
1135+ { Top.isEndOf = Top.ivl ; // isEndLvl set for both EVENDIVL and EVPSTIVL stages
11361136 ucl = ivlStage;
11371137 if (ivlStage == EVPSTIVL && Top.ivl == C_IVLCH_D)
11381138 Top.tp_tmrSnapshot (); // update probably copies of timing data
@@ -2003,27 +2003,31 @@ LOCAL void FC NEAR mtrsAccum( // Accumulate metered energy use results: add int
20032003 // compute sum of uses record (last record). .sum record then propogates to D, M, Y.
20042004 if (mtr->ss < MtrB.n ) // don't add the sum record into itself
20052005 { MTR_IVL_SUB& mtrSum = MtrB.p [MtrB.n ].H ;
2006+ mtrSum.mtr_Accum1 ( mtrSub1, ivl, 0 +(firstflg!=0 ));
2007+ #if 0
20062008 if (firstRec)
20072009 memcpy( &mtrSum, mtrSub1, sizeof(MTR_IVL_SUB)); // copy first record
20082010 else // additional records: accumulate ...
20092011 mtrSum.mtr_Accum1( mtrSub1, ivl); // treatment of demand not necessarily sensible.
2012+ #endif
20102013 }
20112014 firstRec = 0 ;
20122015 }
20132016
2014- // accumulate: copy on first call (in lieu of 0'ing destination). Note: doHourGains 0's MTR hour info at start hour.
2015-
2017+ // accumulate: copy on first call (in lieu of 0'ing destination).
2018+ // Note: doHourGains 0's MTR hour info at start hour.
2019+ #if 1
2020+ mtrSub2->mtr_Accum1 ( mtrSub1, ivl, 0 + (firstflg!=0 ));
2021+ #else
20162022 if (firstflg) // if first call for destination interval
2017- {
2018- // memcpy( mtrSub2, mtrSub1, sizeof(MTR_IVL_SUB) ); // copy whole subrecord
2019- if (bTrc && ivl == 2 )
2020- printf ( " \n ivl=2" );
2023+ { // copy selected members
20212024 VCopy( &mtrSub2->clg, NENDUSES-2, &mtrSub1->clg);
20222025 mtrSub2->pv = mtrSub1->pv;
20232026 mtrSub2->allEU = mtrSub1->allEU;
20242027 }
20252028 else // additional calls in interval use accumulation subr (next)
20262029 mtrSub2->mtr_Accum1( mtrSub1, ivl); // adds up uses w/o bt or tot
2030+ #endif
20272031 }
20282032
20292033 // DHWMTRs
@@ -2083,7 +2087,7 @@ LOCAL void FC NEAR mtrsFinalize( // Finalize meters (after post-stage calcs e.g
20832087 mtrSum.dmdCost = mtrSub1->dmdCost ;
20842088 }
20852089 else // additional records: accumulate ...
2086- mtrSum.mtr_Accum1 ( mtrSub1, ivl, 1 ); // treatment of demand not necessarily sensible.
2090+ mtrSum.mtr_Accum1 ( mtrSub1, ivl, 2 ); // treatment of demand not necessarily sensible.
20872091#if 0 && defined( _DEBUG)
20882092 float xTot = VSum<float,double>( &mtrSum.clg, NENDUSES-2);
20892093 if (frDiff( xTot, mtrSum.tot) > .001)
@@ -2093,23 +2097,28 @@ LOCAL void FC NEAR mtrsFinalize( // Finalize meters (after post-stage calcs e.g
20932097 firstRec = 0 ;
20942098 }
20952099
2096- // accumulate: copy on first call (in lieu of 0'ing destination). Note: doHourGains 0's MTR hour info at start hour.
20972100
20982101#if defined( _DEBUG)
20992102 // MTR_IVL_SUB mtrSub2Was( *mtrSub2);
21002103 if (bTrc)
21012104 { float xTot = VSum<float ,double >( &mtrSub1->clg , NENDUSES);
21022105 if (frDiff ( xTot, mtrSub1->tot ) > .001 )
21032106 printf ( " \n Bad sub1" );
2104- if (ivl == 2 )
2105- printf (" ivl=2" );
21062107 }
21072108
21082109#endif
2110+
2111+ // accumulate: copy on first call (in lieu of 0'ing destination). Note: doHourGains 0's MTR hour info at start hour.
2112+ #if 1
2113+ // accumulate to next level, handles dmd
2114+ mtrSub2->mtr_Accum1 ( mtrSub1, ivl, 2 + (firstflg!=0 ));
2115+ #else
21092116 if (firstflg) // if first call for destination interval
21102117 memcpy( mtrSub2, mtrSub1, sizeof(MTR_IVL_SUB) ); // copy whole subrecord
21112118 else // additional calls in interval use accumulation subr (next)
2112- mtrSub2->mtr_Accum1 ( mtrSub1, ivl, 1 ); // finalizes totals, handles dmd
2119+ mtrSub2->mtr_Accum1( mtrSub1, ivl, 2); // finalizes totals, handles dmd
2120+ #endif
2121+
21132122
21142123#if defined( _DEBUG)
21152124 if (1 || bTrc)
@@ -2122,46 +2131,68 @@ LOCAL void FC NEAR mtrsFinalize( // Finalize meters (after post-stage calcs e.g
21222131 }
21232132} // mtrsFinalize
21242133// -----------------------------------------------------------------------------------------------------------
2125- void MTR_IVL_SUB::mtr_Accum1 ( // inner routine for non-first accumulation of one meter -interval into another
2134+ void MTR_IVL_SUB::mtr_Accum1 ( // accumulate of one submeter -interval into another
21262135
21272136 const MTR_IVL_SUB* mtrSub1, // source interval usage/demand/cost substruct in MTR record
21282137 IVLCH ivl, // destination interval: day/month/year. Accumulates from hour/day/month. Not Top.ivl!
21292138 int options /* =0*/ ) // option bits
2130- // 1: do "finalize" accumulation (else end-of-calcs accum)
2131- // accums mtrSub1 into this
2132-
2133- // not called if firstflg -- caller just memcpy's!
2139+ // 1: copy to *this (re firstflg)
2140+ // else accumulate
2141+ // 2: do "finalize" accumulation (after batttery calcs)
2142+ // else end-of-calc
2143+ // accums/copies mtrSub1 into *this
21342144{
21352145#if 1
2136- bool bFinalize = (options & 1 ) != 0 ;
2146+ bool bCopy = (options & 1 ) != 0 ;
2147+ bool bFinalize = (options & 2 ) != 0 ;
21372148
21382149 if (!bFinalize)
21392150 { // end of calcs / before battery
2140- // omit tot (see below), bt included but s/b 0
2141- // Add up uses and cost, and demand cost if month to year
2142- VAccum ( &clg, // add 2nd arg float vector to 1st arg
2143- NENDUSES-2 , // vector length: # end uses w/o pv and bt
2144- &mtrSub1->clg ); // source
2145- pv += mtrSub1->pv ;
2146- allEU += mtrSub1->allEU ;
2151+ // omit all *p (EVPSTIVL) mbrs (tot, bt, cost, dmd, dmdCost, dmdShoy)
2152+ if (bCopy)
2153+ { VCopy ( &clg, NENDUSES-2 , &mtrSub1->clg );
2154+ pv = mtrSub1->pv ;
2155+ allEU = mtrSub1->allEU ;
2156+ }
2157+ else
2158+ { VAccum ( &clg, // add 2nd arg float vector to 1st arg
2159+ NENDUSES-2 , // vector length: # end uses w/o pv and bt
2160+ &mtrSub1->clg ); // source
2161+ pv += mtrSub1->pv ;
2162+ allEU += mtrSub1->allEU ;
2163+ }
21472164 }
21482165 else
21492166 { // after load management (e.g. battery)
21502167 // handle all mbrs w/ *p variability
2151- tot += mtrSub1->tot ;
2152- bt += mtrSub1->bt ;
2153- cost += mtrSub1->cost ;
2154- if (ivl==C_IVLCH_Y) // sum .dmdCost if month-to-year (thru month, largest
2155- // dmdCost is used, not sum, by code just below).
2156- dmdCost += mtrSub1->dmdCost ;
2157-
2158- // keep peak demand, and its cost thru month level
2159-
2160- if (mtrSub1->dmd > dmd) // if source demand (peak use) greater
2161- { dmd = mtrSub1->dmd ; // update largest hourly demand in destination
2162- dmdShoy = mtrSub1->dmdShoy ; // update peak date & time (subhr of year)
2163- if (ivl != C_IVLCH_Y) // thru month level, keep largest demand cost
2164- dmdCost = mtrSub1->dmdCost ; // .. (but for month to year, dmdCost is summed, above).
2168+ if (bCopy)
2169+ { memcpy ( this , mtrSub1, sizeof ( MTR_IVL_SUB));
2170+
2171+ #if 0
2172+ tot = mtrSub1->tot;
2173+ bt = mtrSub1->bt;
2174+ cost = mtrSub1->cost;
2175+ dmd = mtrSub1->dmd;
2176+ dmdCost = mtrSub1->dmdCost;
2177+ dmdShoy = mtrSub1->dmdShoy;
2178+ #endif
2179+ }
2180+ else
2181+ { tot += mtrSub1->tot ;
2182+ bt += mtrSub1->bt ;
2183+ cost += mtrSub1->cost ;
2184+ if (ivl==C_IVLCH_Y) // sum .dmdCost if month-to-year (thru month, largest
2185+ // dmdCost is used, not sum, by code just below).
2186+ dmdCost += mtrSub1->dmdCost ;
2187+
2188+ // keep peak demand, and its cost thru month level
2189+
2190+ if (mtrSub1->dmd > dmd) // if source demand (peak use) greater
2191+ { dmd = mtrSub1->dmd ; // update largest hourly demand in destination
2192+ dmdShoy = mtrSub1->dmdShoy ; // update peak date & time (subhr of year)
2193+ if (ivl != C_IVLCH_Y) // thru month level, keep largest demand cost
2194+ dmdCost = mtrSub1->dmdCost ; // .. (but for month to year, dmdCost is summed, above).
2195+ }
21652196 }
21662197 }
21672198#else
0 commit comments