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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

include(BuildFlags)

target_link_libraries(cse_common_interface INTERFACE fmt)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

find_package(Git QUIET)
Expand All @@ -80,6 +82,7 @@ set(cse_common_source
"${CSE_SOURCE_DIR}/src/strpak.cpp"
"${CSE_SOURCE_DIR}/src/tdpak.cpp"
"${CSE_SOURCE_DIR}/src/xiopak.cpp"
"${CSE_SOURCE_DIR}/src/nummeth.cpp"
)

add_subdirectory(src)
Expand Down
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ add_custom_command(
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)

# Needed to establish dependency for other targets that depend on dtypes.h
add_custom_target(generate_dtypes DEPENDS ${CSE_BINARY_DIR}/src/dtypes.h)
# Needed to establish dependency for other targets that depend on generated RCDEF outputs
add_custom_target(generate_rcdef_outputs DEPENDS
"${CSE_BINARY_DIR}/src/dtypes.h"
"${CSE_BINARY_DIR}/src/rccn.h"
"${CSE_BINARY_DIR}/src/dttab.cpp"
"${CSE_BINARY_DIR}/src/srfd.cpp"
"${CSE_BINARY_DIR}/src/untab.cpp"
)

# Set CSE Version
add_custom_target(version_header
Expand Down
15 changes: 9 additions & 6 deletions src/cnloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ static RC loadsIzxSh2();
static RC loadsSurfaces( BOO subhrly);
static RC loadsXFans();

/*------------------------------- CONSTANTS -------------------------------*/
static constexpr double tol_tF = 1.e-12; // temperature tolerance (degF)

/*------------------------ The MAIN EQUATION story ------------------------*/
// rob 12-89 prelim
Expand Down Expand Up @@ -1647,7 +1649,7 @@ double ZNR::zn_AmfHvacCR( // sensible hvac air requirements w/ add'l radiant hea
// does NOT change ZNR state
// returns dry-air mass flow rate required to hold tza, lbm/hr
{
double amf = (fabs( tza - tSup) < .00001)
double amf = (fabs( tza - tSup) < tol_tF)
? DBL_MAX
: (zn_balC1 - zn_balC2*tza + zn_cxSh*qRad)
/ (zn_dRpCx * (tza - tSup) * Top.tp_airSH);
Expand All @@ -1661,7 +1663,7 @@ double ZNR::zn_AmfHvacCR( // sensible hvac air requirements
// does NOT change ZNR state
// returns dry-air mass flow rate required to hold tza, lbm/hr
{
double amf = (fabs(tza - tSup) < .00001)
double amf = (fabs(tza - tSup) < tol_tF)
? DBL_MAX
: (zn_balC1 - zn_balC2 * tza)
/ (zn_dRpCx * (tza - tSup) * Top.tp_airSH);
Expand Down Expand Up @@ -5905,10 +5907,11 @@ RC RSYS::rs_AllocateZoneAir() // finalize zone air flows
},
this, amfXTarg, .0001*amfXTarg,
tSup, amfX, // x1, f1
rs_asSupAux.as_tdb, 1. / rs_amfReq[1]); // x2, f2
if (ret != 0)
{
warn("RSYS '%s': ASHP aux heat supply temp fail (%d)", Name(), ret);
rs_asSupAux.as_tdb, DBL_MIN); // x2, f2
if (ret != 0) {
tSup = rs_asSup.as_tdb;
oWarn("Failed to solve for ASHP aux heat supply temperature to deliver %g lb/hr.\n"
" Resuming with previous value of tSup=%.2f.", 1. / amfXTarg, tSup);
}
#if defined( _DEBUG)
// check tSup -- should be between noAux and fullAux temps
Expand Down
53 changes: 29 additions & 24 deletions src/cvpak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ p static SI ipv; // ditto right-shifted for use as subscript
p /* note positive value options not used (except check debugpr.c);
p could remove LOTS of code in cvpak, rob grep 10-88. Done 11-91. */
#endif
static USI fmt; // cvin2s "format" argument; see cvpak.h for field definitions.
static USI fmtv; // cvin2s "format" argument; see cvpak.h for field definitions.
static USI mfw; // cvin2s "max field width" argument.
static SI just; // justification: left, rt, rz, squeeze.
static SI ijust; // ditto right-shifted for use as subscript.
Expand Down Expand Up @@ -170,7 +170,7 @@ char * FC cvin2s( // Convert internal format data to external format string in
bool percent = false; // set true if converting a DTPERCENT; shares DTFLOAT code
#endif

fmt = _fmt; // store format arg for use by callees
fmtv = _fmt; // store format arg for use by callees
mfw = _mfw; // .. max field width arg

/* NULL data pointer means do NOTHING */ /* for caller convenience in supporting optional stuff, tentative 9-89.
Expand All @@ -188,19 +188,19 @@ char * FC cvin2s( // Convert internal format data to external format string in
// Allocate temporary string space.
int allocLen = mfw+3+2; // +3: some paranoia space, at least 1 needed.
// +2: for FMTUNITS space or FMTPU ()'s
if (fmt & (FMTUNITS|FMTPU)) // if units to be appended
if (fmtv & (FMTUNITS|FMTPU)) // if units to be appended
allocLen += static_cast<int>(strlen( UNIT::GetSymbol( units)) );
if (allocLen < 13) allocLen = 13; // always enuf for "<unset>\0" or "<expr 99999>\0" 2-27-92
str = strtemp( allocLen); // strpak.c; strtempPop deallocates.

/* Common setup */

#ifdef FMTPVMASK // define in cvpak.h to restore p positive value display options, 11-91
p pv = fmt&FMTPVMASK; // positive value display: null, +, spc
p pv = fmtv&FMTPVMASK; // positive value display: null, +, spc
p ipv = ((USI)pv) >> FMTPVSHIFT; // .. shifted for use as subscript -- frequently used to select formats
p // (shift made unsigned for lint)
#endif
just = fmt&FMTJMASK; // justification: left, rt, rz, squeeze
just = fmtv&FMTJMASK; // justification: left, rt, rz, squeeze
ijust = ((USI)just) >> FMTJSHIFT; // .. shifted for use as subscript
// (shift made unsigned for lint)
lj = just==FMTLJ; // left justify flag
Expand Down Expand Up @@ -328,7 +328,12 @@ p break;
}
val = *(float*)data; // conver float value to print to double
}
valValue: // double, [percent] join here
valValue: // double, [percent] join here
if (std::isnan(val)) {
data = "nan";
goto strjust;
}

val = cvIntoEx( val, units); // convert value to ext units
#ifdef FMTPVMASK
p wsign = !(pv==FMTPVNULL && val >= 0.); // sign width
Expand Down Expand Up @@ -370,7 +375,7 @@ x printf("\n-0");
{
if (!ISNCHOICE( *(void **)data)) // if not a choice (cnglob.h macro)
goto floatCase; // (numbers, UNSET, NANDLES branch)
fmt &= ~(FMTUNITS|FMTPU); // suppress units when number-choice is choice
fmtv &= ~(FMTUNITS|FMTPU); // suppress units when number-choice is choice
}
choiceCase: // float types comes here if NCHOICE found (unexpected)
if (dt & (DTBCHOICB|DTBCHOICN)) // if a choice type
Expand Down Expand Up @@ -443,12 +448,12 @@ x }

/* optionally add units. Note ' " for ft-in done in cvFtIn2s. Suppressed for NCHOICE choice by clearing bits above. */

if (fmt & FMTUNITS)
if (fmtv & FMTUNITS)
{
strcat( str, " ");
strcat( str, UNIT::GetSymbol( units)); // concat units text
}
else if (fmt & FMTPU) // parenthesised units for res loads 2-90
else if (fmtv & FMTPU) // parenthesised units for res loads 2-90
{
strcat( str, "(");
strcat( str, UNIT::GetSymbol( units)); // concat units text
Expand All @@ -471,12 +476,12 @@ static const char ddalpha[]=" kMGTPEZY?????"; // Chars for K format output fiel

LOCAL void FC cvDouble2s() // float / double output conversion case for cvin2s

// converts 'val' to '*str'; uses other global statics including: fmt, mfw, val, str, lj, lz, ppos, .
// converts 'val' to '*str'; uses other global statics including: fmtv, mfw, val, str, lj, lz, ppos, .

// do not call for foot-inch conversion: see cvFtIn2s.
{
SI i;
SI dfw = fmt & FMTDFWMASK; // decimal field width (# decimal places)
SI dfw = fmtv & FMTDFWMASK; // decimal field width (# decimal places)
ki = 0; // say not in K format overflow (cvsd/nexK)

// zero exception
Expand All @@ -495,7 +500,7 @@ p Cvnchars = sprintf( str, sif[lj][ipv], wid, ppos, 0);

// trim trailing zeroes (specified significant digits) option

if (fmt & FMTRTZ) // "trim trailing zeroes" option
if (fmtv & FMTRTZ) // "trim trailing zeroes" option
{
if (cvsd( mfw, dfw)) // convert (returns false if should use cvdd: number too small relative to space)
return; // if converted (returns best fit if overwide; caller checks Cvnchars)
Expand All @@ -509,7 +514,7 @@ p Cvnchars = sprintf( str, sif[lj][ipv], wid, ppos, 0);

// field overflowed (rest of function)

if ((fmt & FMTOVFMASK)==FMTOVFK) // if overlow is to be handled with k format
if ((fmtv & FMTOVFMASK)==FMTOVFK) // if overlow is to be handled with k format
{

// float overflow, K format option (default). Could recode with new fcn nexK()... 4-92
Expand Down Expand Up @@ -581,7 +586,7 @@ p Cvnchars = sprintf( str, sif[lj][ipv], wid, ppos, 0);
//======================================================================
LOCAL void FC cvFtIn2s() // feet-inch length output conversion case for cvin2s

// converts 'val' to '*str'; uses other global statics including: fmt, mfw, val, str, lj, lz, ppos, .
// converts 'val' to '*str'; uses other global statics including: fmtv, mfw, val, str, lj, lz, ppos, .
{
bool biglen = (aval > 178000000.); // true to show feet only: set if > max 32-bit int inches, also set below if too wide.
if (!biglen) // if feet not too big to express inches in int (in sepFtInch): ie normally
Expand All @@ -590,7 +595,7 @@ LOCAL void FC cvFtIn2s() // feet-inch length output conversion case for cv
bool sq = (just==FMTSQ); // squeeze (minimum columns) flag (also 'wid' is 1)
int inch; // inches
#ifdef FMTNOQUINCH // define in cvpak.h to restore feature, 11-91
x SI quinch = !(fmt & FMTNOQUINCH); // 1 for " after inches
x SI quinch = !(fmtv & FMTNOQUINCH); // 1 for " after inches
x ft = sepFtInch( val, &inch); // separate/fix feet, inches
x justInches = (quinch && ft == 0L && inch != 0);
x // true to omit feet; never happens if quinch is off -- prevents ambiguous single numbers.
Expand All @@ -601,8 +606,8 @@ x // true to omit feet; never happens if quinch is off -- prevents ambiguous

// digits after decimal point in INCHES

int indfw = fmt & FMTDFWMASK; // init decimal places for inches (same value as former 'dfw')
if (fmt & FMTRTZ) // with truncating trailing 0's optn,
int indfw = fmtv & FMTDFWMASK; // init decimal places for inches (same value as former 'dfw')
if (fmtv & FMTRTZ) // with truncating trailing 0's optn,
{
// dfw is total sig digs, not digits after .
// Reduce indfw to digits to print AFTER DECIMAL in INCHES.
Expand Down Expand Up @@ -674,7 +679,7 @@ p dinch ); // floating inches
dinch ); // floating inches
#endif
}
if (fmt & FMTRTZ) // trim trailing zeros option
if (fmtv & FMTRTZ) // trim trailing zeros option
{
// rob 10-88 to support FTMRTZ with FMTSQ
Cvnchars =
Expand Down Expand Up @@ -716,7 +721,7 @@ p inch );
x
x // omit zero inches with feet if ALL 3 of these options on (rob 10-88 for text files):
x
x if (fmt & (FMTSQ|FMTRTZ|FMTNOQUINCH)==(FMTSQ|FMTRTZ|FMTNOQUINCH) )
x if (fmtv & (FMTSQ|FMTRTZ|FMTNOQUINCH)==(FMTSQ|FMTRTZ|FMTNOQUINCH) )
x {
x if ( !justInches // if feet shown
x && *(str + Cvnchars-1)=='0' // 0 last
Expand Down Expand Up @@ -761,7 +766,7 @@ x }
DTDBL,
UNNONE, // no units
mfw-1, // save a column for '
fmt );
fmtv );
*(str+Cvnchars++) = '\''; // add foot mark ' to end
*(str+Cvnchars) = '\0';
}
Expand Down Expand Up @@ -809,7 +814,7 @@ LOCAL bool FC cvsd( // Significant-digits (trim trailing 0's, g format) outpu
// and uses local statics including:
// char *str, String into which to store converted value
// double val Value to convert
// fmt cvin2s caller's format argument
// fmtv cvin2s caller's format argument
// wid field width given in cvin2s call, or 1 for FMTSQ
// wsign sign width, 0 or 1
// ik init -1 for nexK
Expand Down Expand Up @@ -851,7 +856,7 @@ x _dfw = nDigB4Pt; // use the digits, not e or k format
#endif

// initial handling of k format overflow format: make value fit if can, if does not round up.
if ((fmt & FMTOVFMASK)==FMTOVFK) // if overlow is to be handled with "k format"
if ((fmtv & FMTOVFMASK)==FMTOVFK) // if overlow is to be handled with "k format"
{
if (_dfw < 3) // needs 3 digits or 2 + k to work in general: 499, 1k, 99k, .1M, etc.
_dfw = min( SI(3), amfw); // so take them if avail; loop below reduces dfw if it helps.
Expand Down Expand Up @@ -894,7 +899,7 @@ p Cvnchars = sprintf( str, gf[ijust][ipv], wid, _dfw, _val); // convert nu
// done if fits field and not 'e' format when k format overflow specified

if (Cvnchars <= amfw+wsign) // note mfw not reduced for k char if any
if ((fmt & FMTOVFMASK) != FMTOVFK || !strchr( str, 'e')) // if not 'k' fmt overflow or sprinf used no 'e'
if ((fmtv & FMTOVFMASK) != FMTOVFK || !strchr( str, 'e')) // if not 'k' fmtv overflow or sprinf used no 'e'
break; // normal termination of loop

// text wider than field (expected for roundup cases) or contains 'e' when k format desired
Expand All @@ -905,7 +910,7 @@ p Cvnchars = sprintf( str, gf[ijust][ipv], wid, _dfw, _val); // convert nu
if (--Cvnchars <= amfw+wsign) // is now 1 char narrower
break; // now it fits!
}
if ((fmt & FMTOVFMASK)==FMTOVFK) // if 'k' overflow format requested
if ((fmtv & FMTOVFMASK)==FMTOVFK) // if 'k' overflow format requested
{
if (nDigAfPt > 0 && _dfw > 3) // first trim digits after point: 123.4k-->.1234M is no gain
{
Expand Down
Loading