Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cgcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,13 @@ struct AIRNET_SOLVER
: an_pParent( pParent), an_jac(), an_V1(), an_V2(), an_mdotAbs(nullptr),
an_didLast(nullptr), an_nz( 0)
{ }
~AIRNET_SOLVER() { }
~AIRNET_SOLVER()
{
delete an_mdotAbs;
an_mdotAbs = nullptr;
delete an_didLast;
an_didLast = nullptr;
}

RC an_Calc(int iV);

Expand Down
8 changes: 4 additions & 4 deletions src/cgsolar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int slrCalcJDays[13] = // julian day of year for which to do solar table calcula
//16 14 15 14 14 10 16 15 15 15 14 10 (days of months)
};

#if (SLRCALCS & 1)
#if (0 && SLRCALCS & 1)
static SLLOCDAT* Locsolar = NULL; // Ptr to solar info structure for current calculation.
// Released by slfree from tp_LocDone().
// Address saved by slinit for other slpak calls.
Expand All @@ -97,7 +97,7 @@ RC TOPRAT::tp_LocInit() // location-initializer for CSE
// slpak remembers its location internally.

#if (SLRCALCS & 1)
Locsolar = slinit(RAD(latitude), // latitude (to radians)
slinit(RAD(latitude), // latitude (to radians)
RAD(longitude), // longitude
timeZone, // time zone
elevation); // site altitude (ft)
Expand All @@ -111,7 +111,7 @@ RC TOPRAT::tp_LocInit() // location-initializer for CSE
RC TOPRAT::tp_LocDone() // Free location related dm stuff: Locsolar
{
#if (SLRCALCS & 1)
slfree(&Locsolar); // free solar data struct, null ptr, slpak.cpp. Redundant call ok.
slfree(); // free solar data struct, null ptr, slpak.cpp. Redundant call ok.
#endif
return RCOK;
} // TOPRAT::tp_LocDone
Expand Down Expand Up @@ -384,7 +384,7 @@ void FC makHrSgt( // make solar tables for an hour for current month
* INT(Top.tp_date.month-1), INT(slrCalcJDays[Top.tp_date.month]) );
#endif

// Initialize slpak for a standard day near middle of month. slselect(Locsolar) in effect. Note restored at exit.
// Initialize slpak for a standard day near middle of month. Note restored at exit.

slday( slrCalcJDays[ Top.tp_date.month], // julian date for this month's solar calcs
sltmLST ); // say use local standard time
Expand Down
4 changes: 3 additions & 1 deletion src/cse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ _DLLImpExp int cse( // CSE main function, called by console main(), Windows Wi
pMsgCallBack = _pMsgCallBack;
#endif // CSE_DLL

dmInitMemoryChecking();

isCallBackAbort = 0; // clear abort flag (1 if prior run aborted)

//-- nested entry protection: DLL only has 1 copy of variables even if 2 copies of app loaded
Expand Down Expand Up @@ -1224,7 +1226,7 @@ LOCAL INT cse3( INT argc, const char* argv[])
vrPrintf( vrTimes, "\n\n%sTiming info --\n\n", pfx);
int tmrLimit = (TestOptions & 2) ? TMR_COUNT : TMR_TOTAL + 1;
for (i = 0; i < tmrLimit; i++)
vrTmrDisp( vrTimes, i, pfx); // timer.cpp
tmrVrDisp( vrTimes, i, pfx); // timer.cpp
}

// Output timing info & any remaining log/err msgs to report file -- in particular, input error that prevented unspool above.
Expand Down
1 change: 1 addition & 0 deletions src/cul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4207,6 +4207,7 @@ LOCAL void FC drefAddI( // add deferred reference table entry -- general inner
drfp->i = i; // entry subscr,
drfp->fn = fn; // field number.
drfp->toB = toB; // what is being referenced: rat,
dmfree( DMPP( drfp->toName)); // free any prior toName before overwrite
drfp->toName = strsave( toName); // entry name.
drfp->defO = defO; // default owner from context
// .. get file/line info for error messages using cutok.cpp fcn
Expand Down
20 changes: 20 additions & 0 deletions src/dmpak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ RC dmIncRef( DMP* pp, int erOp/*=ABT*/) // duplicate block or ++ref count (as im
dmRefCount( *pp)++;
return RCOK;
} // dmIncRef
//-----------------------------------------------------------------------------
void dmInitMemoryChecking()
{

#if CSE_COMPILER == CSE_COMPILER_MSVC
#if defined( _DEBUG)
// Get the current bits
int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);

tmp |= _CRTDBG_LEAK_CHECK_DF; // check for memory leaks at program exit

// Set the new bits
_CrtSetDbgFlag(tmp);

int request = -1; // set with debugger to trap specific blocks
if (request != -1)
_CrtSetBreakAlloc(request);
#endif
#endif
} // dmInitMemoryChecking
///////////////////////////////////////////////////////////////////////////////

// end of dmpak.cpp
1 change: 1 addition & 0 deletions src/dmpak.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ RC dmfree( DMP *pp); // checks stack, no FC
RC dmIncRef( DMP *pp, int erOp=ABT);
RC dmPrivateCopy( DMP *pp, int erOp=ABT);
int dmIsGoodPtr( DMP p, const char* s, int erOp);
void dmInitMemoryChecking();

#ifdef DEBUG2
void FC dmeatmem( USI sz);
Expand Down
47 changes: 18 additions & 29 deletions src/solar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const float SolarConstant = 434.f; // previous value, source unknown

// pointer to current solar/location info thing. Set by slinit() / slselect().
// Used by slday(), sldec, slsurfhr, slha, sldircos, slaniso
LOCAL SLLOCDAT * slloccur;
static SLLOCDAT* slloccur = nullptr;

/*----------------------- LOCAL FUNCTION DECLARATIONS ---------------------*/

Expand Down Expand Up @@ -385,15 +385,14 @@ float slVProfAng( // vertical profile angle
return profAng;
} // slVProfAng
//======================================================================
SLLOCDAT *FC
slinit(/* Allocate, init, and select a SLLOCAT structure */
void slinit(/* Allocate, init, and select a SLLOCAT structure */

float rlat, // latitude, +=N, radians
float rlong, // longitude, +=W (non-standard), radians
float tzn, // time zone (hrs west of GMT. EST=5, PST=8, etc. )
float siteElev) // site elevation (ft above sea level).
// Used only with global/direct functions (eg dirsimx.c, gshift.c)
// SO passing 0 is generally harmless.
float rlat, // latitude, +=N, radians
float rlong, // longitude, +=W (non-standard), radians
float tzn, // time zone (hrs west of GMT. EST=5, PST=8, etc. )
float siteElev) // site elevation (ft above sea level).
// Used only with global/direct functions (eg dirsimx.c, gshift.c)
// SO passing 0 is generally harmless.

/* Returns pointer to SLLOCDAT structure initialized for specified location.
This location is now also the current location for subsequent
Expand All @@ -411,30 +410,20 @@ slinit(/* Allocate, init, and select a SLLOCAT structure */
pSlr->tzn = tzn; /* time zone, hours west of GMT */
pSlr->siteElev = siteElev; /* site elevation, ft */
pSlr->pressureRatio = (float)exp(-0.0001184 * 0.3048 * siteElev);
/* site pressure ratio: nominal ratio of surface pressure to sea level pressure.
Formula appears in Perez code (dirsim.c) and is documented in SERI Consensus
Summary (full reference above), p. 17.
NOTE: needs reconciliation with psychro1.c:psyAltitude. 8-9-90 */
return slselect(
pSlr); // make current: ptr for other slpak fcns. ret ptr, for later slselects and slfree
// site pressure ratio: nominal ratio of surface pressure to sea level pressure.
// Formula appears in Perez code (dirsim.c) and is documented in SERI Consensus
// Summary (full reference above), p. 17.
// NOTE: needs reconciliation with psychro1.c:psyAltitude. 8-9-90

slfree();
slloccur = pSlr; // make current: ptr for other slpak fcns
} // slinit
//======================================================================
SLLOCDAT *FC slselect(/* Sets current solar/location data to that given by arg */

SLLOCDAT *pSlr) /* pointer returned by an earlier slinit call */

/* returns pSlr as convenience (new feature 8-9-90) */
void FC slfree() // Free a SLLOCDAT structure
{
return (slloccur = pSlr); /* set file-global for slpak fcns to use */
} /* slselect */
delete slloccur; // free heap storage occupied by object
slloccur = nullptr;

//======================================================================
void FC slfree( // Free a SLLOCDAT structure

SLLOCDAT **ppSlr) // ptr to ptr. nop if ptr is NULL; ptr is set NULL: redundant calls ok.
{
delete *ppSlr; // free heap storage occupied by object
*ppSlr = NULL; // erase no-longer-valid pointer
} // slfree

//======================================================================
Expand Down
5 changes: 2 additions & 3 deletions src/solar.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ x void FC slhourfromalt(float alt);
#endif
void FC slsdc(float azm, float tilt, float dcos[3]);
float slVProfAng(float relAzm, float cosZen);
SLLOCDAT* FC slinit(float rlat, float rlong, float tzn, float siteElev);
SLLOCDAT* FC slselect(SLLOCDAT* pSlr);
void FC slfree(SLLOCDAT** ppSlr);
void slinit(float rlat, float rlong, float tzn, float siteElev);
void FC slfree();
void FC slday(DOY doy, int timetype, int options = 0);
void FC sldec(float sldec, int timetype);
int slsurfhr(float sdircos[3], int ihr, float* pCosi, float* pAzm = NULL,
Expand Down
22 changes: 14 additions & 8 deletions src/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ struct TMRDATA
int tcalls; // # of calls
LLI tbeg; // time at beg of current timing, ticks
LLI ttot; // total time for timer, ticks
WStr tname; // name of timer
TMRDATA(const char* _tname = "") : tcalls(0), tbeg(0), ttot(0), tname(_tname)
std::string tname; // name of timer
TMRDATA() : tcalls(0), tbeg(0), ttot(0), tname()
{}
};
static WVect< TMRDATA> tmrtab;
//------------------------------------------------------------------------------
void tmrSet(const char* tmrName)
{ tname = tmrName;
tcalls = 0;
tbeg = ttot = 0;
} // TMRDATA::tmrSet
}; // struct TMRDATA
//-----------------------------------------------------------------------------
static std::vector< TMRDATA> tmrtab;
//-----------------------------------------------------------------------------
static double tmrSecsPerTick = -1.;
//-----------------------------------------------------------------------------
static double tmrTicksToSecs(
Expand Down Expand Up @@ -115,7 +121,7 @@ void tmrInit( // Initialize (but do *NOT* start) a timer
{
if (size_t( tmr) >= tmrtab.size())
tmrtab.resize(tmr+5);
new (&tmrtab[ tmr]) TMRDATA(tmrName);
tmrtab[tmr].tmrSet(tmrName);
tmrSetupIf(); // constants etc if needed
} // tmrInit
//========================================================================
Expand Down Expand Up @@ -164,7 +170,7 @@ void tmrdisp( // Display current data for a timer
} // tmrdisp
#endif
//========================================================================
RC vrTmrDisp( // Display current data for a timer
RC tmrVrDisp( // Display current data for a timer

int vrh, // open virtual report to which to display results
int tmr, // Timer number
Expand All @@ -180,6 +186,6 @@ RC vrTmrDisp( // Display current data for a timer
return vrPrintf( vrh, "%s%20s: Time = %-7.2f Calls = %-8ld T/C = %-0.4f\n",
pfx, tmrtab[tmr].tname.c_str(), t, tmrtab[tmr].tcalls, t/nc );

} // vrTmrDisp
} // tmrVrDisp

// end of timer.cpp
2 changes: 1 addition & 1 deletion src/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void tmrStart( int tmr);
void tmrStop( int tmr);
double tmrCurTot( int tmr);
void tmrDisp( FILE *f, int tmr, double delta); // may be if 0'd
RC vrTmrDisp( int vrh, int tmr, const char* pfx="", double delta=0.);
RC tmrVrDisp( int vrh, int tmr, const char* pfx="", double delta=0.);

// End of timer.h