@@ -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
@@ -3620,9 +3620,8 @@ RC HPWHLINK::hw_DoSubhrStart( // HPWH subhour start
36203620
36213621#define HPWH_DUMP // define to include debug CSV file
36223622#if defined( HPWH_DUMP)
3623- // #define HPWH_DUMPSMALL // #define to use abbreviated version
3624- // use debug dump mechanism w/o headings to log file
3625- // (dump goes to external CSV file)
3623+ // use debug dump mechanism w/o headings to log file
3624+ // (dump goes to external CSV file)
36263625 hw_bWriteCSV = DbDo (dbdHPWH, dbdoptNOHDGS);
36273626#endif
36283627
@@ -3735,6 +3734,7 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
37353734 double qTXPwr // tick power (W)
37363735 = qTXkWh * 1000 . / (Top.tp_tickDurHr );
37373736 hw_pNodePowerExtra_W = {qTXPwr, 0 ., 0 ., 0 .}; // bottom 1/4 of tank
3737+
37383738 pNPX = &hw_pNodePowerExtra_W;
37393739 }
37403740
@@ -3878,43 +3878,37 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
38783878
38793879 CSVGen csvGen (CI);
38803880
3881- if (!hw_pFCSV)
3881+ if (hw_pFCSV == nullptr )
3882+ {
3883+ hw_pFCSV = new std::ofstream;
3884+ }
3885+ if (!hw_pFCSV->is_open ())
38823886 {
38833887 // dump file name = <cseFile>_<DHWHEATER name>_hpwh.csv
38843888 // Overwrite pre-existing file
38853889 // >>> thus file contains info from only last RUN in multi-RUN sessions
38863890 const char * nameNoWS = strDeWS (strtmp (hw_pOwner->Name ()));
3887- const char * fName =
3888- strsave (strffix2 (strtprintf (" %s_%s_hpwh" , InputFilePathNoExt, nameNoWS), " .csv" , 1 ));
3889- hw_pFCSV = fopen (fName , " wt" );
3890- if (!hw_pFCSV)
3891+ const char * fName = strffix2 (strtprintf (" %s_%s_hpwh" , InputFilePathNoExt, nameNoWS), " .csv" , 1 );
3892+ hw_pFCSV->open (fName , std::ifstream::out); // implies truncation
3893+ if (!hw_pFCSV->is_open ())
38913894 err (PWRN, " HPWH report failure for '%s'" , fName );
38923895 else
38933896 { // headings
3894- fprintf ( hw_pFCSV, " %s,%s,%s\n " ,
3897+ * hw_pFCSV << strtprintf ( " %s,%s,%s\n " ,
38953898 hw_pOwner->GetDescription (), Top.repHdrL .CStr (), Top.runDateTime .CStr ());
3896- fprintf ( hw_pFCSV, " %s%s %s %s HPWH %s\n " ,
3899+ * hw_pFCSV << strtprintf ( " %s%s %s %s HPWH %s\n " ,
38973900 Top.tp_RepTestPfx (), ProgName, ProgVersion, ProgVariant,
38983901 Top.tp_HPWHVersion .CStr ());
3899- #if defined( HPWH_DUMPSMALL)
3900- fprintf (wh_pFCSV, " minYear,draw( L)\n " );
3901- #else
39023902 WStr s (" mon,day,hr," );
39033903 s += csvGen.cg_Hdgs (dumpUx);
3904- hw_pHPWH->WriteCSVHeading (hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
3905- #endif
3904+ hw_pHPWH->WriteCSVHeading (*hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
39063905 }
39073906 }
3908- if (hw_pFCSV)
3909- {
3910- #if defined( HPWH_DUMPSMALL)
3911- fprintf (wh_pFCSV, " %0.2f,%0.3f\n " , minYear, GAL_TO_L (drawForTick));
3912- #else
3913- WStr s = strtprintf (" %d,%d,%d," ,
3907+ if (hw_pFCSV->is_open ())
3908+ { WStr s = strtprintf (" %d,%d,%d," ,
39143909 Top.tp_date .month , Top.tp_date .mday , Top.iHr + 1 );
39153910 s += csvGen.cg_Values (dumpUx);
3916- hw_pHPWH->WriteCSVRow (hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
3917- #endif
3911+ hw_pHPWH->WriteCSVRow (*hw_pFCSV, s.c_str (), nTCouples, hpwhOptions);
39183912 }
39193913 }
39203914#endif // HPWH_DUMP
@@ -4312,7 +4306,6 @@ RC DHWHEATER::wh_Init() // init for run
43124306 RC rc = RCOK;
43134307
43144308 DHWSYS* pWS = wh_GetDHWSYS ();
4315- wh_pFCSV = NULL ;
43164309
43174310 // one-time inits
43184311 wh_balErrCount = 0 ;
0 commit comments