@@ -2891,13 +2891,13 @@ void HPWHLINK::hw_Cleanup()
28912891// duplicate calls OK
28922892{
28932893 delete hw_pHPWH;
2894- hw_pHPWH = NULL ;
2894+ hw_pHPWH = nullptr ;
2895+
28952896 delete[] hw_HSMap;
2896- hw_HSMap = NULL ;
2897- if (hw_pFCSV)
2898- { fclose ( hw_pFCSV);
2899- hw_pFCSV = nullptr ;
2900- }
2897+ hw_HSMap = nullptr ;
2898+
2899+ delete hw_pFCSV; // closes file if open
2900+ hw_pFCSV = nullptr ;
29012901
29022902 hw_pNodePowerExtra_W.clear ();
29032903
@@ -3618,9 +3618,8 @@ RC HPWHLINK::hw_DoSubhrStart( // HPWH subhour start
36183618
36193619#define HPWH_DUMP // define to include debug CSV file
36203620#if defined( HPWH_DUMP)
3621- // #define HPWH_DUMPSMALL // #define to use abbreviated version
3622- // use debug dump mechanism w/o headings to log file
3623- // (dump goes to external CSV file)
3621+ // use debug dump mechanism w/o headings to log file
3622+ // (dump goes to external CSV file)
36243623 hw_bWriteCSV = DbDo (dbdHPWH, dbdoptNOHDGS);
36253624#endif
36263625
@@ -3730,9 +3729,10 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
37303729 {
37313730 double qTXkWh = tk.wtk_qTX / BtuperkWh;
37323731 hw_qTX += qTXkWh; // subhour total (kWh)
3733- double qTXPwr // tick power per node, W
3734- = qTXkWh * 1000 . / (hw_nQTXNodes * Top.tp_tickDurHr );
3735- hw_pNodePowerExtra_W.assign (hw_nQTXNodes, qTXPwr);
3732+ double qTXPwr // tick power (W)
3733+ = qTXkWh * 1000 . / (Top.tp_tickDurHr );
3734+ hw_pNodePowerExtra_W = {qTXPwr, 0 ., 0 ., 0 .}; // bottom 1/4 of tank
3735+
37363736 pNPX = &hw_pNodePowerExtra_W;
37373737 }
37383738
@@ -3876,43 +3876,37 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
38763876
38773877 CSVGen csvGen (CI);
38783878
3879- if (!hw_pFCSV)
3879+ if (hw_pFCSV == nullptr )
3880+ {
3881+ hw_pFCSV = new std::ofstream;
3882+ }
3883+ if (!hw_pFCSV->is_open ())
38803884 {
38813885 // dump file name = <cseFile>_<DHWHEATER name>_hpwh.csv
38823886 // Overwrite pre-existing file
38833887 // >>> thus file contains info from only last RUN in multi-RUN sessions
38843888 const char * nameNoWS = strDeWS (strtmp (hw_pOwner->Name ()));
3885- const char * fName =
3886- strsave (strffix2 (strtprintf (" %s_%s_hpwh" , InputFilePathNoExt, nameNoWS), " .csv" , 1 ));
3887- hw_pFCSV = fopen (fName , " wt" );
3888- if (!hw_pFCSV)
3889+ const char * fName = strffix2 (strtprintf (" %s_%s_hpwh" , InputFilePathNoExt, nameNoWS), " .csv" , 1 );
3890+ hw_pFCSV->open (fName , std::ifstream::out); // implies truncation
3891+ if (!hw_pFCSV->is_open ())
38893892 err (PWRN, " HPWH report failure for '%s'" , fName );
38903893 else
38913894 { // headings
3892- fprintf ( hw_pFCSV, " %s,%s,%s\n " ,
3895+ * hw_pFCSV << strtprintf ( " %s,%s,%s\n " ,
38933896 hw_pOwner->GetDescription (), Top.repHdrL .CStr (), Top.runDateTime .CStr ());
3894- fprintf ( hw_pFCSV, " %s%s %s %s HPWH %s\n " ,
3897+ * hw_pFCSV << strtprintf ( " %s%s %s %s HPWH %s\n " ,
38953898 Top.tp_RepTestPfx (), ProgName, ProgVersion, ProgVariant,
38963899 Top.tp_HPWHVersion .CStr ());
3897- #if defined( HPWH_DUMPSMALL)
3898- fprintf (wh_pFCSV, " minYear,draw( L)\n " );
3899- #else
39003900 WStr s (" mon,day,hr," );
39013901 s += csvGen.cg_Hdgs (dumpUx);
3902- hw_pHPWH->WriteCSVHeading (hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
3903- #endif
3902+ hw_pHPWH->WriteCSVHeading (*hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
39043903 }
39053904 }
3906- if (hw_pFCSV)
3907- {
3908- #if defined( HPWH_DUMPSMALL)
3909- fprintf (wh_pFCSV, " %0.2f,%0.3f\n " , minYear, GAL_TO_L (drawForTick));
3910- #else
3911- WStr s = strtprintf (" %d,%d,%d," ,
3905+ if (hw_pFCSV->is_open ())
3906+ { WStr s = strtprintf (" %d,%d,%d," ,
39123907 Top.tp_date .month , Top.tp_date .mday , Top.iHr + 1 );
39133908 s += csvGen.cg_Values (dumpUx);
3914- hw_pHPWH->WriteCSVRow (hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
3915- #endif
3909+ hw_pHPWH->WriteCSVRow (*hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
39163910 }
39173911 }
39183912#endif // HPWH_DUMP
@@ -4310,7 +4304,6 @@ RC DHWHEATER::wh_Init() // init for run
43104304 RC rc = RCOK;
43114305
43124306 DHWSYS* pWS = wh_GetDHWSYS ();
4313- wh_pFCSV = NULL ;
43144307
43154308 // one-time inits
43164309 wh_balErrCount = 0 ;
0 commit comments