Skip to content

Commit

Permalink
Fix narrowing-conversions (part 2b - floats): slightly different outputs
Browse files Browse the repository at this point in the history
warning: narrowing conversion from 'double' to 'float' [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions]

General approach: change smaller variable to larger type as required by assignment
* mostly float -> unsigned double

--> SOILWAT2 now completed the shift from float to double type and no longer uses float/RealF (but retains minimal support for STEPWAT2)

NOTE:
--> this commit **does** slightly change output of example simulation, e.g., `make bin_run`
--> R's `all.equal()` comparison against v8.0.0

[1] "Component “SURFACEWATER_surfaceWater_cm”: Mean relative difference: 2.571445e-07"
[2] "Component “EVAPSURFACE_evap_total”: Mean relative difference: 0.0001101079"
[3] "Component “EVAPSURFACE_evap_surfaceWater”: Mean relative difference: 0.0001101079"
[4] "Component “AET_evapotr_cm”: Mean relative difference: 7.47542e-06"
[5] "Component “AET_tran_cm”: Mean relative difference: 1.1993e-05"
[6] "Component “AET_esoil_cm”: Mean relative difference: 1.702403e-05"
[7] "Component “AET_esurf_cm”: Mean relative difference: 0.0001101079"
[8] "Component “DEEPSWC_lowLayerDrain_cm”: Mean relative difference: 1.615019e-07"

  [1] "Component “VWCBULK_Lyr_1”: Mean relative difference: 6.787685e-06"
  [2] "Component “VWCBULK_Lyr_2”: Mean relative difference: 4.809277e-06"
  [3] "Component “VWCBULK_Lyr_3”: Mean relative difference: 3.838998e-06"
  [4] "Component “VWCBULK_Lyr_4”: Mean relative difference: 4.390425e-06"
  [5] "Component “VWCBULK_Lyr_5”: Mean relative difference: 4.581049e-06"
  [6] "Component “VWCBULK_Lyr_7”: Mean relative difference: 7.211278e-06"
  [7] "Component “VWCBULK_Lyr_8”: Mean relative difference: 7.279133e-06"
  [8] "Component “VWCMATRIC_Lyr_1”: Mean relative difference: 5.96451e-06"
  [9] "Component “VWCMATRIC_Lyr_2”: Mean relative difference: 4.620794e-06"
 [10] "Component “VWCMATRIC_Lyr_3”: Mean relative difference: 3.212984e-06"
 [11] "Component “VWCMATRIC_Lyr_4”: Mean relative difference: 3.758796e-06"
 [12] "Component “VWCMATRIC_Lyr_5”: Mean relative difference: 3.577111e-06"
 [13] "Component “VWCMATRIC_Lyr_6”: Mean relative difference: 3.718947e-06"
 [14] "Component “VWCMATRIC_Lyr_7”: Mean relative difference: 5.589148e-06"
 [15] "Component “VWCMATRIC_Lyr_8”: Mean relative difference: 5.922433e-06"
 [16] "Component “SWCBULK_Lyr_1”: Mean relative difference: 1.282636e-06"
 [17] "Component “SWCBULK_Lyr_2”: Mean relative difference: 9.888887e-07"
 [18] "Component “SWCBULK_Lyr_3”: Mean relative difference: 4.132047e-07"
 [19] "Component “SWCBULK_Lyr_4”: Mean relative difference: 4.590823e-07"
 [20] "Component “SWCBULK_Lyr_5”: Mean relative difference: 4.672742e-07"
 [21] "Component “SWCBULK_Lyr_6”: Mean relative difference: 2.265474e-07"
 [22] "Component “SWCBULK_Lyr_7”: Mean relative difference: 3.397264e-07"
 [23] "Component “SWCBULK_Lyr_8”: Mean relative difference: 3.46075e-07"
 [24] "Component “SWABULK_Lyr_1”: Mean relative difference: 1.452727e-06"
 [25] "Component “SWABULK_Lyr_2”: Mean relative difference: 2.04562e-06"
 [26] "Component “SWABULK_Lyr_3”: Mean relative difference: 1.441732e-06"
 [27] "Component “SWABULK_Lyr_4”: Mean relative difference: 1.62593e-06"
 [28] "Component “SWABULK_Lyr_5”: Mean relative difference: 2.658106e-06"
 [29] "Component “SWABULK_Lyr_6”: Mean relative difference: 1.432752e-06"
 [30] "Component “SWABULK_Lyr_7”: Mean relative difference: 1.706254e-06"
 [31] "Component “SWABULK_Lyr_8”: Mean relative difference: 1.514629e-06"
 [32] "Component “SWAMATRIC_Lyr_1”: Mean relative difference: 1.098867e-06"
 [33] "Component “SWAMATRIC_Lyr_2”: Mean relative difference: 1.617156e-06"
 [34] "Component “SWAMATRIC_Lyr_3”: Mean relative difference: 1.246417e-06"
 [35] "Component “SWAMATRIC_Lyr_4”: Mean relative difference: 1.463519e-06"
 [36] "Component “SWAMATRIC_Lyr_5”: Mean relative difference: 2.28515e-06"
 [37] "Component “SWAMATRIC_Lyr_6”: Mean relative difference: 9.418853e-07"
 [38] "Component “SWAMATRIC_Lyr_7”: Mean relative difference: 1.066312e-06"
 [39] "Component “SWAMATRIC_Lyr_8”: Mean relative difference: 1.019591e-06"
 [40] "Component “SWA_swa_tree_Lyr_1”: Mean relative difference: 8.801958e-06"
 [41] "Component “SWA_swa_tree_Lyr_2”: Mean relative difference: 8.076203e-06"
 [42] "Component “SWA_swa_tree_Lyr_3”: Mean relative difference: 7.164101e-06"
 [43] "Component “SWA_swa_tree_Lyr_4”: Mean relative difference: 6.993858e-06"
 [44] "Component “SWA_swa_tree_Lyr_5”: Mean relative difference: 8.964629e-06"
 [45] "Component “SWA_swa_tree_Lyr_6”: Mean relative difference: 4.635753e-06"
 [46] "Component “SWA_swa_tree_Lyr_7”: Mean relative difference: 4.582682e-06"
 [47] "Component “SWA_swa_tree_Lyr_8”: Mean relative difference: 4.413898e-06"
 [48] "Component “SWA_swa_shrub_Lyr_1”: Mean relative difference: 3.415307e-06"
 [49] "Component “SWA_swa_shrub_Lyr_2”: Mean relative difference: 3.578671e-06"
 [50] "Component “SWA_swa_shrub_Lyr_3”: Mean relative difference: 2.578715e-06"
 [51] "Component “SWA_swa_shrub_Lyr_4”: Mean relative difference: 3.00194e-06"
 [52] "Component “SWA_swa_shrub_Lyr_5”: Mean relative difference: 3.484284e-06"
 [53] "Component “SWA_swa_shrub_Lyr_6”: Mean relative difference: 1.730354e-06"
 [54] "Component “SWA_swa_shrub_Lyr_7”: Mean relative difference: 1.938897e-06"
 [55] "Component “SWA_swa_shrub_Lyr_8”: Mean relative difference: 1.955346e-06"
 [56] "Component “SWA_swa_forbs_Lyr_1”: Mean relative difference: 8.801958e-06"
 [57] "Component “SWA_swa_forbs_Lyr_2”: Mean relative difference: 8.076203e-06"
 [58] "Component “SWA_swa_forbs_Lyr_3”: Mean relative difference: 7.164101e-06"
 [59] "Component “SWA_swa_forbs_Lyr_4”: Mean relative difference: 6.993858e-06"
 [60] "Component “SWA_swa_forbs_Lyr_5”: Mean relative difference: 8.964629e-06"
 [61] "Component “SWA_swa_forbs_Lyr_6”: Mean relative difference: 4.635753e-06"
 [62] "Component “SWA_swa_forbs_Lyr_7”: Mean relative difference: 4.582682e-06"
 [63] "Component “SWA_swa_forbs_Lyr_8”: Mean relative difference: 4.413898e-06"
 [64] "Component “SWA_swa_grass_Lyr_1”: Mean relative difference: 3.916315e-06"
 [65] "Component “SWA_swa_grass_Lyr_2”: Mean relative difference: 4.144338e-06"
 [66] "Component “SWA_swa_grass_Lyr_3”: Mean relative difference: 2.828872e-06"
 [67] "Component “SWA_swa_grass_Lyr_4”: Mean relative difference: 3.063181e-06"
 [68] "Component “SWA_swa_grass_Lyr_5”: Mean relative difference: 3.815531e-06"
 [69] "Component “SWA_swa_grass_Lyr_6”: Mean relative difference: 1.923957e-06"
 [70] "Component “SWA_swa_grass_Lyr_7”: Mean relative difference: 1.942265e-06"
 [71] "Component “SWA_swa_grass_Lyr_8”: Mean relative difference: 1.957688e-06"
 [72] "Component “SWPMATRIC_Lyr_1”: Mean relative difference: 2.322216e-08"
 [73] "Component “SWPMATRIC_Lyr_2”: Mean relative difference: 3.304662e-08"
 [74] "Component “SWPMATRIC_Lyr_3”: Mean relative difference: 4.519526e-08"
 [75] "Component “SWPMATRIC_Lyr_4”: Mean relative difference: 5.272346e-08"
 [76] "Component “SWPMATRIC_Lyr_5”: Mean relative difference: 5.199723e-08"
 [77] "Component “SWPMATRIC_Lyr_6”: Mean relative difference: 5.36183e-08"
 [78] "Component “SWPMATRIC_Lyr_7”: Mean relative difference: 4.543617e-08"
 [79] "Component “SWPMATRIC_Lyr_8”: Mean relative difference: 5.453246e-08"
 [80] "Component “TRANSP_transp_total_Lyr_2”: Mean relative difference: 0.0001091465"
 [81] "Component “TRANSP_transp_total_Lyr_3”: Mean relative difference: 0.001102536"
 [82] "Component “TRANSP_transp_total_Lyr_5”: Mean relative difference: 0.0001385425"
 [83] "Component “TRANSP_transp_total_Lyr_7”: Mean relative difference: 6.674231e-05"
 [84] "Component “TRANSP_transp_shrub_Lyr_3”: Mean relative difference: 0.001102536"
 [85] "Component “TRANSP_transp_forbs_Lyr_3”: Mean relative difference: 0.0003895598"
 [86] "Component “EVAPSOIL_Lyr_1”: Mean relative difference: 2.030828e-05"
 [87] "Component “EVAPSOIL_Lyr_2”: Mean relative difference: 2.860453e-05"
 [88] "Component “LYRDRAIN_Lyr_1”: Mean relative difference: 1.562113e-07"
 [89] "Component “LYRDRAIN_Lyr_3”: Mean relative difference: 4.696835e-08"
 [90] "Component “LYRDRAIN_Lyr_4”: Mean relative difference: 1.968411e-06"
 [91] "Component “LYRDRAIN_Lyr_5”: Mean relative difference: 1.046047e-07"
 [92] "Component “LYRDRAIN_Lyr_6”: Mean relative difference: 4.128741e-08"
 [93] "Component “HYDRED_total_Lyr_2”: Mean relative difference: 2.929459e-05"
 [94] "Component “HYDRED_total_Lyr_3”: Mean relative difference: 5.243289e-05"
 [95] "Component “HYDRED_total_Lyr_4”: Mean relative difference: 0.0001294331"
 [96] "Component “HYDRED_total_Lyr_5”: Mean relative difference: 0.0001334638"
 [97] "Component “HYDRED_total_Lyr_7”: Mean relative difference: 0.0002744237"
 [98] "Component “HYDRED_tree_Lyr_7”: Mean relative difference: 0.0001287333"
 [99] "Component “HYDRED_shrub_Lyr_2”: Mean relative difference: 4.292582e-05"
[100] "Component “HYDRED_shrub_Lyr_4”: Mean relative difference: 0.000355366"
[101] "Component “HYDRED_shrub_Lyr_6”: Mean relative difference: 0.0006086427"
[102] "Component “HYDRED_forbs_Lyr_2”: Mean relative difference: 0.0005192108"
[103] "Component “HYDRED_forbs_Lyr_5”: Mean relative difference: 0.005494505"
[104] "Component “HYDRED_grass_Lyr_3”: Mean relative difference: 0.0001518372"
[105] "Component “HYDRED_grass_Lyr_8”: Mean relative difference: 0.000413736"
[106] "Component “SOILTEMP_Lyr_1_max_C”: Mean relative difference: 5.677091e-08"
[107] "Component “SOILTEMP_Lyr_1_min_C”: Mean relative difference: 3.079511e-07"
[108] "Component “SOILTEMP_Lyr_1_avg_C”: Mean relative difference: 1.23057e-07"
[109] "Component “SOILTEMP_Lyr_2_max_C”: Mean relative difference: 7.236446e-08"
[110] "Component “SOILTEMP_Lyr_2_min_C”: Mean relative difference: 2.34404e-07"
[111] "Component “SOILTEMP_Lyr_2_avg_C”: Mean relative difference: 1.157913e-07"
[112] "Component “SOILTEMP_Lyr_3_max_C”: Mean relative difference: 1.146534e-07"
[113] "Component “SOILTEMP_Lyr_3_min_C”: Mean relative difference: 2.17593e-07"
[114] "Component “SOILTEMP_Lyr_3_avg_C”: Mean relative difference: 1.407808e-07"
[115] "Component “SOILTEMP_Lyr_4_max_C”: Mean relative difference: 1.229199e-07"
[116] "Component “SOILTEMP_Lyr_4_min_C”: Mean relative difference: 1.349336e-07"
[117] "Component “SOILTEMP_Lyr_4_avg_C”: Mean relative difference: 1.324526e-07"
[118] "Component “SOILTEMP_Lyr_5_max_C”: Mean relative difference: 1.473129e-07"
[119] "Component “SOILTEMP_Lyr_5_min_C”: Mean relative difference: 1.475681e-07"
[120] "Component “SOILTEMP_Lyr_5_avg_C”: Mean relative difference: 1.384248e-07"
[121] "Component “SOILTEMP_Lyr_6_max_C”: Mean relative difference: 1.62394e-07"
[122] "Component “SOILTEMP_Lyr_6_min_C”: Mean relative difference: 1.608422e-07"
[123] "Component “SOILTEMP_Lyr_6_avg_C”: Mean relative difference: 1.550766e-07"
[124] "Component “SOILTEMP_Lyr_7_max_C”: Mean relative difference: 1.648383e-07"
[125] "Component “SOILTEMP_Lyr_7_min_C”: Mean relative difference: 1.600763e-07"
[126] "Component “SOILTEMP_Lyr_7_avg_C”: Mean relative difference: 1.601399e-07"
[127] "Component “SOILTEMP_Lyr_8_max_C”: Mean relative difference: 1.654345e-07"
[128] "Component “SOILTEMP_Lyr_8_min_C”: Mean relative difference: 1.691749e-07"
[129] "Component “SOILTEMP_Lyr_8_avg_C”: Mean relative difference: 1.662441e-07"
  • Loading branch information
dschlaep committed Jul 30, 2024
1 parent c046d74 commit 62237ae
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 96 deletions.
2 changes: 1 addition & 1 deletion include/SW_Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ typedef unsigned short OutPeriod;
* before I got the documentation.
*/
typedef struct {
RealF xinflec, yinflec, range, slope;
double xinflec, yinflec, range, slope;
} tanfunc_t;

/* standardize the test for missing */
Expand Down
4 changes: 2 additions & 2 deletions include/SW_SoilWater.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ void SW_SWC_end_day(SW_SOILWAT *SW_SoilWat, LyrIndex n_layers);
void get_dSWAbulk(
unsigned int i,
SW_VEGPROD *SW_VegProd,
RealF swa_master[][NVEGTYPES][MAX_LAYERS],
RealF dSWA_repart_sum[][MAX_LAYERS]
double swa_master[][NVEGTYPES][MAX_LAYERS],
double dSWA_repart_sum[][MAX_LAYERS]
);

RealD SW_SWRC_SWCtoSWP(
Expand Down
24 changes: 12 additions & 12 deletions include/SW_datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,9 @@ typedef struct {
standingWater[TWO_DAYS]; /* water on soil surface if layer below is
saturated */

RealF swa_master[NVEGTYPES][NVEGTYPES]
[MAX_LAYERS]; // veg_type, crit_val, layer
RealF dSWA_repartitioned_sum[NVEGTYPES][MAX_LAYERS];
double swa_master[NVEGTYPES][NVEGTYPES]
[MAX_LAYERS]; // veg_type, crit_val, layer
double dSWA_repartitioned_sum[NVEGTYPES][MAX_LAYERS];

Bool soiltempError; // soil temperature error indicator
#ifdef SWDEBUG
Expand Down Expand Up @@ -1357,22 +1357,22 @@ typedef struct {
/* Variables from SXW_t (STEPWAT2) used in SOILWAT2 */
// transpXXX: monthly sum of soilwat's transpiration by soil layer
// * these are dynamic arrays that are indexed by Ilp()
RealD transpTotal[MAX_LAYERS][MAX_MONTHS], // total transpiration, i.e., sum
// across vegetation types
double transpTotal[MAX_LAYERS][MAX_MONTHS], // total transpiration, i.e.,
// sum across vegetation types
transpVeg[NVEGTYPES][MAX_LAYERS]
[MAX_MONTHS]; // transpiration as contributed by vegetation
// types
RealF swc[MAX_LAYERS]
[MAX_MONTHS]; // monthly mean SWCbulk for each soil layer
double swc[MAX_LAYERS]
[MAX_MONTHS]; // monthly mean SWCbulk for each soil layer

// fixed monthly array:
RealF ppt_monthly[MAX_MONTHS]; // monthly sum of soilwat's precipitation
RealF temp_monthly[MAX_MONTHS]; // monthly mean soilwat's air temperature
double ppt_monthly[MAX_MONTHS]; // monthly sum of soilwat's precipitation
double temp_monthly[MAX_MONTHS]; // monthly mean soilwat's air temperature

// annual values:
RealF temp, // annual mean soilwat's air temperature
ppt, // annual sum of soilwat's precipitation
aet; // annual sum of soilwat's evapotranspiration
double temp, // annual mean soilwat's air temperature
ppt, // annual sum of soilwat's precipitation
aet; // annual sum of soilwat's evapotranspiration
#endif
} SW_OUT_RUN;

Expand Down
72 changes: 46 additions & 26 deletions include/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,9 @@ extern "C" {
#define fmin(a, b) ((LT((a), (b))) ? (a) : (b))
#endif

/* redefine sqrt for double (default) or float */
#ifdef NO_SQRTF /* the case for Borland's compiler */
#define sqrtf sqrt
#endif

#define sqrt(x) ((sizeof(x) == sizeof(float)) ? sqrtf(x) : sqrt(x))

#define isnull(a) (NULL == (a))

/* --------- Redefine basic types to be more malleable ---- */
typedef float RealF;
typedef double RealD;
typedef int Int;
typedef unsigned int IntU;
Expand All @@ -123,16 +115,6 @@ typedef enum { swFALSE = (1 != 1), swTRUE = (1 == 1) } Bool;

typedef unsigned char byte;

/* an attempt to facilitate integer implementation of real */
/*
typedef long IRealF
typedef double long IRealD
#define IF_GRAIN 10000000L
#define F2I(x) ((IRealF)(x*IF_GRAIN))
#define D2I(x) ((IRealD)(x*ID_GRAIN))
#define I2F(x) ((( RealF)x/IF_GRAIN))
#define I2D(x) ((( RealD)x/ID_GRAIN))
*/

/* --------------------------------------------------*/
/* These are facilities for logging errors. */
Expand All @@ -154,6 +136,7 @@ typedef unsigned char byte;

/* --------------------------------------------------*/
/* --------------------------------------------------*/

/* The following tests account for imprecision in the
floating point representation of either single
or double real numbers. Use these instead of
Expand Down Expand Up @@ -201,10 +184,15 @@ typedef unsigned char byte;
for floats/doubles, which are typically not used with side-effecting
expressions.
*/
#define F_DELTA (10 * FLT_EPSILON)
#define D_DELTA (10 * DBL_EPSILON)


#if defined(STEPWAT)
/* ------ STEPWAT2 uses floats and doubles ------ */
typedef float RealF;

#define F_DELTA (10 * FLT_EPSILON)

// new definitions for these four macros (MUCH MUCH faster, by a factor of about
// 4)... just trying them out for now. The idea behind how these work is that
// both an absolute error and relative error check are being used in conjunction
Expand All @@ -216,13 +204,6 @@ typedef unsigned char byte;
(MAX(F_DELTA, FLT_EPSILON * MAX(fabs(x), fabs(y)))) : \
(MAX(D_DELTA, DBL_EPSILON * MAX(fabs(x), fabs(y)))))

/**< LT tests whether x is less than y while accounting for floating-point
* arithmetic */
#define LT(x, y) ((x) < ((y) - GET_F_DELTA(x, y)))

/**< GT tests whether x is greater than y while accounting for floating-point
* arithmetic */
#define GT(x, y) ((x) > ((y) + GET_F_DELTA(x, y)))

/**< ZRO tests whether x is equal to zero while accounting for floating-point
* arithmetic */
Expand All @@ -232,6 +213,45 @@ typedef unsigned char byte;
#define ZRO(x) \
((sizeof(x) == sizeof(float)) ? (fabs(x) <= F_DELTA) : (fabs(x) <= D_DELTA))


/* redefine sqrt for double (default) or float */
#ifdef NO_SQRTF /* the case for Borland's compiler */
#define sqrtf sqrt
#endif

#define sqrt(x) ((sizeof(x) == sizeof(float)) ? sqrtf(x) : sqrt(x))


#else /* !defined(STEPWAT), i.e., SOILWAT2 and rSOILWAT2 */
/* ------ SOILWAT2 uses doubles (>= v8.1.0) ------ */

// new definitions for these four macros (MUCH MUCH faster, by a factor of about
// 4)... just trying them out for now. The idea behind how these work is that
// both an absolute error and relative error check are being used in conjunction
// with one another. In this for now I'm using F_DELTA for the amount of
// absolute error allowed and FLT_EPSILON for the amount of relative error
// allowed.
#define GET_F_DELTA(x, y) (MAX(D_DELTA, DBL_EPSILON * MAX(fabs(x), fabs(y))))

/**< ZRO tests whether x is equal to zero while accounting for floating-point
* arithmetic */
// for iszero(x) we just use an absolute error check, because a relative error
// check doesn't make sense for any number close enough to zero to be considered
// equal... it would be a waste of time.
#define ZRO(x) (fabs(x) <= D_DELTA)

#endif


/**< LT tests whether x is less than y while accounting for floating-point
* arithmetic */
#define LT(x, y) ((x) < ((y) - GET_F_DELTA(x, y)))

/**< GT tests whether x is greater than y while accounting for floating-point
* arithmetic */
#define GT(x, y) ((x) > ((y) + GET_F_DELTA(x, y)))


/**< EQ tests whether x and y are equal based on a specified tolerance */
#define EQ_w_tol(x, y, tol) (fabs((x) - (y)) <= tol)

Expand Down
56 changes: 28 additions & 28 deletions src/SW_Markov.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* --------------------------------------------------- */
#include "include/SW_Markov.h" // for SW_MKV_construct, SW_MKV_deconst...
#include "include/filefuncs.h" // for LogError, CloseFile, GetALine
#include "include/generic.h" // for RealD, RealF, LOGERROR, swFALSE
#include "include/generic.h" // for RealD, LOGERROR, swFALSE
#include "include/myMemory.h" // for Mem_Calloc, Mem_Copy
#include "include/rands.h" // for RandNorm, RandSeed, RandUni
#include "include/SW_datastructs.h" // for SW_MARKOV, LOG_INFO
Expand Down Expand Up @@ -409,7 +409,7 @@ void SW_MKV_today(
* 1 leave with rain == today's ppt
*/
TimeInt week;
RealF prob, p, x;
double prob, p, x;

#ifdef SWDEBUG
short debug = 0;
Expand Down Expand Up @@ -527,10 +527,10 @@ Bool SW_MKV_read_prob(

FILE *f;
int lineno = 0, day, x, index;
RealF wet, dry, avg, std;
RealF *floatVals[4] = {&wet, &dry, &avg, &std};
double wet, dry, avg, std;
double *doubleVals[4] = {&wet, &dry, &avg, &std};
char inbuf[MAX_FILENAMESIZE];
char dayStr[4] = {'\0'}, inFloatStrs[4][20] = {{'\0'}};
char dayStr[4] = {'\0'}, inDoubleStrs[4][20] = {{'\0'}};

Bool result = swTRUE;

Expand All @@ -550,10 +550,10 @@ Bool SW_MKV_read_prob(
inbuf,
"%3s %19s %19s %19s %19s",
dayStr,
inFloatStrs[0],
inFloatStrs[1],
inFloatStrs[2],
inFloatStrs[3]
inDoubleStrs[0],
inDoubleStrs[1],
inDoubleStrs[2],
inDoubleStrs[3]
);

day = sw_strtoi(dayStr, MyFileName, LogInfo);
Expand All @@ -563,8 +563,8 @@ Bool SW_MKV_read_prob(
}

for (index = 0; index < numFloatInStrings; index++) {
*(floatVals[index]) =
sw_strtof(inFloatStrs[index], MyFileName, LogInfo);
*(doubleVals[index]) =
sw_strtod(inDoubleStrs[index], MyFileName, LogInfo);
if (LogInfo->stopRun) {
result = swFALSE;
goto closeFile;
Expand Down Expand Up @@ -672,12 +672,12 @@ Bool SW_MKV_read_cov(char *InFiles[], SW_MARKOV *SW_Markov, LOG_INFO *LogInfo) {
FILE *f;
int lineno = 0, week, x, index;
char inbuf[MAX_FILENAMESIZE];
RealF t1, t2, t3, t4, t5, t6, cfxw, cfxd, cfnw, cfnd;
RealF *floatVals[] = {
double t1, t2, t3, t4, t5, t6, cfxw, cfxd, cfnw, cfnd;
double *doubleVals[] = {
&t1, &t2, &t3, &t4, &t5, &t6, &cfxw, &cfxd, &cfnw, &cfnd
};
char weekStr[3] = {'\0'}, inFloatStrs[10][20] = {{'\0'}};
const int numFloatVals = 10;
char weekStr[3] = {'\0'}, inDoubleStrs[10][20] = {{'\0'}};
const int numDoubleVals = 10;
Bool result = swTRUE;

char *MyFileName = InFiles[eMarkovCov];
Expand All @@ -695,16 +695,16 @@ Bool SW_MKV_read_cov(char *InFiles[], SW_MARKOV *SW_Markov, LOG_INFO *LogInfo) {
inbuf,
"%2s %19s %19s %19s %19s %19s %19s %19s %19s %19s %19s",
weekStr,
inFloatStrs[0],
inFloatStrs[1],
inFloatStrs[2],
inFloatStrs[3],
inFloatStrs[4],
inFloatStrs[5],
inFloatStrs[6],
inFloatStrs[7],
inFloatStrs[8],
inFloatStrs[9]
inDoubleStrs[0],
inDoubleStrs[1],
inDoubleStrs[2],
inDoubleStrs[3],
inDoubleStrs[4],
inDoubleStrs[5],
inDoubleStrs[6],
inDoubleStrs[7],
inDoubleStrs[8],
inDoubleStrs[9]
);

// Check that text file is ok:
Expand All @@ -727,9 +727,9 @@ Bool SW_MKV_read_cov(char *InFiles[], SW_MARKOV *SW_Markov, LOG_INFO *LogInfo) {
goto closeFile;
}

for (index = 0; index < numFloatVals; index++) {
*(floatVals[index]) =
sw_strtof(inFloatStrs[index], MyFileName, LogInfo);
for (index = 0; index < numDoubleVals; index++) {
*(doubleVals[index]) =
sw_strtod(inDoubleStrs[index], MyFileName, LogInfo);
if (LogInfo->stopRun) {
result = swFALSE;
goto closeFile;
Expand Down
42 changes: 21 additions & 21 deletions src/SW_Site.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,11 @@ void SW_LYR_read(SW_SITE *SW_Site, char *InFiles[], LOG_INFO *LogInfo) {
FILE *f;
LyrIndex lyrno;
int x, k, index;
RealF dmin = 0.0, dmax, evco, trco_veg[NVEGTYPES], psand, pclay,
soildensity, imperm, soiltemp, f_gravel;
double dmin = 0.0, dmax, evco, trco_veg[NVEGTYPES], psand, pclay,
soildensity, imperm, soiltemp, f_gravel;
char inbuf[MAX_FILENAMESIZE];
char inFloatStrs[12][20] = {{'\0'}};
float *inFloatVals[] = {
char inDoubleStrs[12][20] = {{'\0'}};
double *inDoubleVals[] = {
&dmax,
&soildensity,
&f_gravel,
Expand All @@ -1636,7 +1636,7 @@ void SW_LYR_read(SW_SITE *SW_Site, char *InFiles[], LOG_INFO *LogInfo) {
&imperm,
&soiltemp
};
const int numFloatInStrings = 12;
const int numDoubleInStrings = 12;

/* note that Files.read() must be called prior to this. */
char *MyFileName = InFiles[eLayers];
Expand All @@ -1652,18 +1652,18 @@ void SW_LYR_read(SW_SITE *SW_Site, char *InFiles[], LOG_INFO *LogInfo) {
x = sscanf(
inbuf,
"%19s %19s %19s %19s %19s %19s %19s %19s %19s %19s %19s %19s",
inFloatStrs[0],
inFloatStrs[1],
inFloatStrs[2],
inFloatStrs[3],
inFloatStrs[4],
inFloatStrs[5],
inFloatStrs[6],
inFloatStrs[7],
inFloatStrs[8],
inFloatStrs[9],
inFloatStrs[10],
inFloatStrs[11]
inDoubleStrs[0],
inDoubleStrs[1],
inDoubleStrs[2],
inDoubleStrs[3],
inDoubleStrs[4],
inDoubleStrs[5],
inDoubleStrs[6],
inDoubleStrs[7],
inDoubleStrs[8],
inDoubleStrs[9],
inDoubleStrs[10],
inDoubleStrs[11]
);

/* Check that we have 12 values per layer */
Expand All @@ -1679,10 +1679,10 @@ void SW_LYR_read(SW_SITE *SW_Site, char *InFiles[], LOG_INFO *LogInfo) {
goto closeFile;
}

/* Convert float strings to floats */
for (index = 0; index < numFloatInStrings; index++) {
*(inFloatVals[index]) =
sw_strtof(inFloatStrs[index], MyFileName, LogInfo);
/* Convert strings to doubles */
for (index = 0; index < numDoubleInStrings; index++) {
*(inDoubleVals[index]) =
sw_strtod(inDoubleStrs[index], MyFileName, LogInfo);
if (LogInfo->stopRun) {
goto closeFile;
}
Expand Down
10 changes: 5 additions & 5 deletions src/SW_SoilWater.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ the available soilwater of each veg type above so start at bottom move up.
void get_dSWAbulk(
unsigned int i,
SW_VEGPROD *SW_VegProd,
RealF swa_master[][NVEGTYPES][MAX_LAYERS],
RealF dSWA_repart_sum[][MAX_LAYERS]
double swa_master[][NVEGTYPES][MAX_LAYERS],
double dSWA_repart_sum[][MAX_LAYERS]
) {

int j, kv, curr_vegType, curr_crit_rank_index, kv_veg_type,
Expand All @@ -1033,9 +1033,9 @@ void get_dSWAbulk(
double veg_type_in_use, vegFractionSum, newFraction;
double inner_loop_veg_type; // set to inner loop veg type
smallestCritVal = SW_VegProd->critSoilWater[SW_VegProd->rank_SWPcrits[0]];
RealF dSWA_bulk[NVEGTYPES * NVEGTYPES][NVEGTYPES * NVEGTYPES][MAX_LAYERS];
RealF dSWA_bulk_repartioned[NVEGTYPES * NVEGTYPES][NVEGTYPES * NVEGTYPES]
[MAX_LAYERS];
double dSWA_bulk[NVEGTYPES * NVEGTYPES][NVEGTYPES * NVEGTYPES][MAX_LAYERS];
double dSWA_bulk_repartioned[NVEGTYPES * NVEGTYPES][NVEGTYPES * NVEGTYPES]
[MAX_LAYERS];

// need to initialize to 0
for (curr_vegType = 0; curr_vegType < NVEGTYPES; curr_vegType++) {
Expand Down
Loading

0 comments on commit 62237ae

Please sign in to comment.