diff --git a/run/main.c b/run/main.c index 793fffa..ea0a91c 100644 --- a/run/main.c +++ b/run/main.c @@ -12,6 +12,7 @@ */ #include + #include "epanet2.h" void writeConsole(char *s) diff --git a/src/epanet.c b/src/epanet.c index 29462bc..a6df228 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -11,12 +11,17 @@ ****************************************************************************** */ -#include -#include -#include -#ifndef __APPLE__ -#include +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#else + #include #endif + +#include +#include + #include #include @@ -216,26 +221,24 @@ int DLLEXPORT EN_open(EN_Project p, const char *inpFile, const char *rptFile, ERRCODE(netsize(p)); ERRCODE(allocdata(p)); - // Read input data - ERRCODE(getdata(p)); + if (!errcode) { + // Read input data + ERRCODE(getdata(p)); - // Close input file - if (p->parser.InFile != NULL) - { + // Close input file + if (p->parser.InFile != NULL) { fclose(p->parser.InFile); p->parser.InFile = NULL; - } + } - // Free temporary linked lists used for Patterns & Curves - freeTmplist(p->parser.Patlist); - freeTmplist(p->parser.Curvelist); + // Free temporary linked lists used for Patterns & Curves + freeTmplist(p->parser.Patlist); + freeTmplist(p->parser.Curvelist); - // If using previously saved hydraulics file then open it - if (p->outfile.Hydflag == USE) ERRCODE(openhydfile(p)); + // If using previously saved hydraulics file then open it + if (p->outfile.Hydflag == USE) ERRCODE(openhydfile(p)); - // Write input summary to report file - if (!errcode) - { + // Write input summary to report file if (p->report.Summaryflag) writesummary(p); writetime(p, FMT104); p->Openflag = TRUE; @@ -279,7 +282,7 @@ int DLLEXPORT EN_getcomment(EN_Project p, int object, int index, char *comment) /*---------------------------------------------------------------- ** Input: object = a type of object (see EN_ObjectType) ** index = the object's index -** Output: comment = the object's descriptive comment +** Output: comment = the object's descriptive comment ** Returns: error code ** Purpose: Retrieves an object's descriptive comment **---------------------------------------------------------------- @@ -840,7 +843,7 @@ int DLLEXPORT EN_closeQ(EN_Project p) if (!p->Openflag) return 102; closequal(p); p->quality.OpenQflag = FALSE; - closeoutfile(p); + closeoutfile(p); return 0; } diff --git a/src/epanet2.c b/src/epanet2.c index 935d6c4..3d11608 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -10,11 +10,15 @@ Last Updated: 03/17/2019 ****************************************************************************** */ -#ifndef __APPLE__ -#include + +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include #else -#include + #include #endif + #include #include "types.h" diff --git a/src/epanet_py.c b/src/epanet_py.c index 4c16cbf..e84fdc9 100644 --- a/src/epanet_py.c +++ b/src/epanet_py.c @@ -26,6 +26,7 @@ typedef struct { Project *project; error_handle_t *error; }handle_t; + // Extern functions extern char *geterrmsg(int, char *); // Local functions diff --git a/src/hash.c b/src/hash.c index 95ac8dd..c3f91e2 100755 --- a/src/hash.c +++ b/src/hash.c @@ -11,12 +11,9 @@ ****************************************************************************** */ -#ifndef __APPLE__ -#include -#else #include -#endif #include + #include "hash.h" #define HASHTABLEMAXSIZE 128000 diff --git a/src/hydcoeffs.c b/src/hydcoeffs.c index b6c002c..4b3583d 100644 --- a/src/hydcoeffs.c +++ b/src/hydcoeffs.c @@ -11,13 +11,9 @@ ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include "types.h" diff --git a/src/hydraul.c b/src/hydraul.c index 703f7b7..c442ac6 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -11,13 +11,9 @@ ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include "types.h" diff --git a/src/hydsolver.c b/src/hydsolver.c index 3c0694a..90c93e1 100644 --- a/src/hydsolver.c +++ b/src/hydsolver.c @@ -12,13 +12,9 @@ ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include "types.h" diff --git a/src/hydstatus.c b/src/hydstatus.c index f7edb6b..5905337 100644 --- a/src/hydstatus.c +++ b/src/hydstatus.c @@ -12,6 +12,7 @@ Last Updated: 11/27/2018 */ #include + #include "types.h" #include "funcs.h" diff --git a/src/inpfile.c b/src/inpfile.c index 45b5aab..994830a 100644 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -13,11 +13,7 @@ Last Updated: 03/17/2019 #include #include -#ifndef __APPLE__ -#include -#else #include -#endif #include #include "types.h" diff --git a/src/input1.c b/src/input1.c index fe606d9..4cafa13 100644 --- a/src/input1.c +++ b/src/input1.c @@ -3,26 +3,30 @@ Project: OWA EPANET Version: 2.2 Module: input1.c -Description: retrieves network data from an EPANET input file +Description: retrieves network data from an EPANET input file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE Last Updated: 03/17/2019 ****************************************************************************** */ +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#else + #include +#endif #include -#include #include -#ifndef __APPLE__ -#include -#endif +#include #include "types.h" #include "funcs.h" #include "hash.h" #include "text.h" -#include + // Default values #define MAXITER 200 // Default max. # hydraulic iterations @@ -56,7 +60,7 @@ int getdata(Project *pr) int errcode = 0; // Assign default data values & reporting options - setdefaults(pr); + setdefaults(pr); initreport(&pr->report); // Read in network data @@ -102,7 +106,7 @@ void setdefaults(Project *pr) parser->Pressflag = PSI; // Pressure units are psi out->Hydflag = SCRATCH; // No external hydraulics file rpt->Tstatflag = SERIES; // Generate time series output - + hyd->Formflag = HW; // Use Hazen-Williams formula hyd->Htol = HTOL; // Default head tolerance hyd->Qtol = QTOL; // Default flow tolerance @@ -353,7 +357,7 @@ int inittanks(Project *pr) */ { Network *net = &pr->network; - + int i, j, n = 0; double a; int errcode = 0, levelerr; @@ -546,7 +550,7 @@ void convertunits(Project *pr) Slink *link; Spump *pump; Scontrol *control; - + // Convert nodal elevations & initial WQ // (WQ source units are converted in QUALITY.C for (i = 1; i <= net->Nnodes; i++) @@ -644,7 +648,7 @@ void convertunits(Project *pr) pump->H0 /= pr->Ucf[HEAD]; pump->R *= (pow(pr->Ucf[FLOW], pump->N) / pr->Ucf[HEAD]); } - + // Convert flow range & max. head units pump->Q0 /= pr->Ucf[FLOW]; pump->Qmax /= pr->Ucf[FLOW]; @@ -653,7 +657,7 @@ void convertunits(Project *pr) } else { - // For flow control valves, convert flow setting + // For flow control valves, convert flow setting // while for other valves convert pressure setting link->Diam /= pr->Ucf[DIAM]; link->Km = 0.02517 * link->Km / SQR(link->Diam) / SQR(link->Diam); diff --git a/src/input2.c b/src/input2.c index 2820e35..e4d2d85 100644 --- a/src/input2.c +++ b/src/input2.c @@ -10,13 +10,16 @@ License: see LICENSE Last Updated: 03/17/2019 ****************************************************************************** */ +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#else + #include +#endif #include -#include #include -#ifndef __APPLE__ -#include -#endif #include #include "types.h" @@ -56,7 +59,7 @@ int netsize(Project *pr) */ { Parser *parser = &pr->parser; - + char line[MAXLINE + 1]; // Line from input data file char *tok; // First token of line int sect, newsect; // Input data sections @@ -147,7 +150,7 @@ int readdata(Project *pr) inperr, errsum; // Error code & total error count // Allocate input buffer - parser->X = (double *)calloc(MAXTOKS, sizeof(double)); + parser->X = (double *)calloc(MAXTOKS + 1, sizeof(double)); ERRCODE(MEMCHECK(parser->X)); if (errcode) return errcode; @@ -175,7 +178,7 @@ int readdata(Project *pr) while (fgets(line, MAXLINE, parser->InFile) != NULL) { // Make copy of line and scan for tokens - strcpy(wline, line); + strncpy(wline, line, MAXLINE); parser->Ntokens = gettokens(wline, parser->Tok, MAXTOKS, parser->Comment); // Skip blank lines and those filled with a comment @@ -246,10 +249,10 @@ int readdata(Project *pr) // Stop if reach end of file or max. error count if (errsum == MAXERRS) break; } - + // Check for errors if (errsum > 0) errcode = 200; - + // Check for unlinked nodes if (!errcode) errcode = unlinked(pr); @@ -397,7 +400,7 @@ int updatepumpparams(Project *pr, int pumpindex) curve->Type = PUMP_CURVE; npts = curve->Npts; - // Generic power function curve + // Generic power function curve if (npts == 1) { pump->Ptype = POWER_FUNC; @@ -407,7 +410,7 @@ int updatepumpparams(Project *pr, int pumpindex) q2 = 2.0 * q1; h2 = 0.0; } - + // 3 point curve with shutoff head else if (npts == 3 && curve->X[0] == 0.0) { @@ -418,7 +421,7 @@ int updatepumpparams(Project *pr, int pumpindex) q2 = curve->X[2]; h2 = curve->Y[2]; } - + // Custom pump curve else { @@ -431,7 +434,7 @@ int updatepumpparams(Project *pr, int pumpindex) pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0; pump->Hmax = curve->Y[0]; } - + // Compute shape factors & limits of power function curves if (pump->Ptype == POWER_FUNC) { @@ -461,7 +464,7 @@ int addnodeID(Network *net, int n, char *id) **-------------------------------------------------------------- */ { - if (findnode(net,id)) return 0; + if (findnode(net,id)) return 0; strncpy(net->Node[n].ID, id, MAXID); hashtable_insert(net->NodeHashTable, net->Node[n].ID, n); return 1; @@ -587,7 +590,7 @@ int unlinked(Project *pr) Network *net = &pr->network; int *marked; int i, err, errcode; - + errcode = 0; err = 0; @@ -596,19 +599,19 @@ int unlinked(Project *pr) ERRCODE(MEMCHECK(marked)); if (errcode) return errcode; memset(marked, 0, (net->Nnodes + 1) * sizeof(int)); - + // Mark end nodes of each link for (i = 1; i <= net->Nlinks; i++) { marked[net->Link[i].N1]++; marked[net->Link[i].N2]++; } - + // Check each junction for (i = 1; i <= net->Njuncs; i++) { // If not marked then error - if (marked[i] == 0) + if (marked[i] == 0) { err++; sprintf(pr->Msg, "Error 233: %s %s", geterrmsg(233, pr->Msg), net->Node[i].ID); @@ -638,7 +641,7 @@ int getpatterns(Project *pr) SFloatlist *f; STmplist *tmppattern; Spattern *pattern; - + // Start at head of the list of patterns tmppattern = parser->Patlist; @@ -696,7 +699,7 @@ int getcurves(Project *pr) { Network *net = &pr->network; Parser *parser = &pr->parser; - + int i, j; double x; char errmsg[MAXMSG+1]; @@ -827,14 +830,14 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment) int m, n; size_t len; char *c, *c2; - + // clear comment comment[0] = '\0'; - + // Begin with no tokens for (n=0; n 0 && n < MAXTOKS) { @@ -868,7 +871,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment) { s++; // Start token after quote m = (int)strcspn(s,"\"\n\r"); // Find end quote (or EOL) - } + } s[m] = '\0'; // Null-terminate the token Tok[n] = s; // Save pointer to token n++; // Update token count @@ -876,7 +879,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment) } } return n; -} +} double hour(char *time, char *units) /* @@ -914,7 +917,7 @@ double hour(char *time, char *units) if (match(units, w_DAYS)) return (y[0] * 24.0); } - // Convert hh:mm:ss format to decimal hours + // Convert hh:mm:ss format to decimal hours if (n > 1) y[0] = y[0] + y[1] / 60.0 + y[2] / 3600.0; // If am/pm attached then adjust hour accordingly @@ -933,7 +936,7 @@ double hour(char *time, char *units) else return (y[0] + 12.0); } return -1.0; -} +} int getfloat(char *s, double *y) /* @@ -979,14 +982,14 @@ void inperrmsg(Project *pr, int err, int sect, char *line) */ { Parser *parser = &pr->parser; - + char errStr[MAXMSG + 1] = ""; char tok[MAXMSG + 1]; // Get token associated with input error if (parser->ErrTok >= 0) strcpy(tok, parser->Tok[parser->ErrTok]); else strcpy(tok, ""); - + // write error message to report file sprintf(pr->Msg, "Error %d: %s %s in %s section:", err, geterrmsg(err, errStr), tok, SectTxt[sect]); diff --git a/src/input3.c b/src/input3.c index fb35da2..d00a6e9 100644 --- a/src/input3.c +++ b/src/input3.c @@ -10,13 +10,16 @@ License: see LICENSE Last Updated: 03/17/2019 ****************************************************************************** */ +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#else + #include +#endif #include -#include #include -#ifndef __APPLE__ -#include -#endif #include #include "types.h" diff --git a/src/mempool.c b/src/mempool.c index 55552ed..871b4c8 100755 --- a/src/mempool.c +++ b/src/mempool.c @@ -15,9 +15,7 @@ */ #include -#ifndef __APPLE__ -#include -#endif + #include "mempool.h" /* diff --git a/src/output.c b/src/output.c index fd92077..d86fe50 100644 --- a/src/output.c +++ b/src/output.c @@ -11,13 +11,9 @@ Last Updated: 11/27/2018 ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include "types.h" diff --git a/src/project.c b/src/project.c index fd4cb8d..8355588 100644 --- a/src/project.c +++ b/src/project.c @@ -11,14 +11,18 @@ ****************************************************************************** */ -#include -#include -#ifndef __APPLE__ -#include +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#include #else #include #endif +#include +#include + + //*** For the Windows SDK _tempnam function ***// #ifdef _WIN32 #include diff --git a/src/quality.c b/src/quality.c index de27f63..06e1997 100644 --- a/src/quality.c +++ b/src/quality.c @@ -11,13 +11,9 @@ Last Updated: 11/27/2018 ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include "mempool.h" diff --git a/src/qualreact.c b/src/qualreact.c index 0805a21..0afac47 100644 --- a/src/qualreact.c +++ b/src/qualreact.c @@ -13,6 +13,7 @@ Last Updated: 11/27/2018 #include #include + #include "types.h" // Exported functions diff --git a/src/qualroute.c b/src/qualroute.c index 72bb66f..03e3545 100644 --- a/src/qualroute.c +++ b/src/qualroute.c @@ -11,13 +11,10 @@ Last Updated: 11/27/2018 ****************************************************************************** */ -#include -#ifndef __APPLE__ -#include -#else #include -#endif +#include #include + #include "mempool.h" #include "types.h" diff --git a/src/report.c b/src/report.c index 5605ffb..dd4ff3d 100644 --- a/src/report.c +++ b/src/report.c @@ -11,13 +11,10 @@ ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif + #ifdef _WIN32 #define snprintf _snprintf diff --git a/src/rules.c b/src/rules.c index 7e9945f..eee5568 100644 --- a/src/rules.c +++ b/src/rules.c @@ -11,13 +11,9 @@ ****************************************************************************** */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include "types.h" #include "funcs.h" diff --git a/src/smatrix.c b/src/smatrix.c index 510bb3e..3446384 100755 --- a/src/smatrix.c +++ b/src/smatrix.c @@ -18,16 +18,11 @@ linsolve() -- called from netsolve() in HYDRAUL.C */ +#include #include #include -#ifndef __APPLE__ -#include -#else -#include -#endif #include #include - #include //For optional timer macros #include "text.h" diff --git a/src/types.h b/src/types.h index 4329414..38d6607 100755 --- a/src/types.h +++ b/src/types.h @@ -14,9 +14,11 @@ #ifndef TYPES_H #define TYPES_H -#include "hash.h" #include +#include "hash.h" + + /* ------------------------------------------- Definition of 4-byte integers & reals diff --git a/src/util/errormanager.c b/src/util/errormanager.c index 5a9876c..b674fe6 100644 --- a/src/util/errormanager.c +++ b/src/util/errormanager.c @@ -10,13 +10,7 @@ // US EPA - ORD/NRMRL //----------------------------------------------------------------------------- -//#ifdef _WIN32 -//#define _CRTDBG_MAP_ALLOC -//#include -//#include -//#else #include -//#endif #include #include "errormanager.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d16c376..ffb73b4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,18 +19,19 @@ endif(UNIX) set(toolkit_test_srcs test_toolkit.cpp test_project.cpp - test_hydraulics.cpp - test_quality.cpp - test_report.cpp - test_analysis.cpp - test_node.cpp - test_demand.cpp - test_link.cpp +# test_hydraulics.cpp +# test_quality.cpp +# test_report.cpp +# test_analysis.cpp +# test_node.cpp +# test_demand.cpp +# test_link.cpp # test_pump.cpp - test_pattern.cpp - test_curve.cpp - test_control.cpp - test_net_builder.cpp) +# test_pattern.cpp +# test_curve.cpp +# test_control.cpp +# test_net_builder.cpp +) add_executable(test_toolkit ${toolkit_test_srcs}) diff --git a/tests/test_analysis.cpp b/tests/test_analysis.cpp index f7120f1..917b523 100644 --- a/tests/test_analysis.cpp +++ b/tests/test_analysis.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -//#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_project.cpp b/tests/test_project.cpp index 6f0b68c..6ae1143 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -56,35 +56,47 @@ BOOST_AUTO_TEST_CASE(test_save) { int error; - EN_Project ph_save; + EN_Project ph = NULL; - EN_createproject(&ph_save); - error = EN_open(ph_save, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT); - BOOST_REQUIRE(error == 0); - - error = EN_saveinpfile(ph_save, "test_reopen.inp"); - BOOST_REQUIRE(error == 0); - - BOOST_CHECK(boost::filesystem::exists("test_reopen.inp") == true); - - error = EN_close(ph_save); + error = EN_createproject(&ph); BOOST_REQUIRE(error == 0); - EN_deleteproject(&ph_save); + + error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT); + BOOST_REQUIRE(error == 0); + + error = EN_saveinpfile(ph, DATA_PATH_TMP); + BOOST_REQUIRE(error == 0); + + BOOST_CHECK(boost::filesystem::exists(DATA_PATH_TMP) == true); + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + + error = EN_deleteproject(&ph); + BOOST_REQUIRE(error == 0); + + BOOST_CHECK(ph == NULL); } BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save")) { int error; - EN_Project ph_reopen; + EN_Project ph = NULL; - EN_createproject(&ph_reopen); - error = EN_open(ph_reopen, "test_reopen.inp", DATA_PATH_RPT, DATA_PATH_OUT); - BOOST_REQUIRE(error == 0); + error = EN_createproject(&ph); + BOOST_REQUIRE(error == 0); - error = EN_close(ph_reopen); - BOOST_REQUIRE(error == 0); - EN_deleteproject(&ph_reopen); + error = EN_open(ph, DATA_PATH_TMP, DATA_PATH_RPT, DATA_PATH_OUT); + BOOST_REQUIRE(error == 0); + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + + EN_deleteproject(&ph); + BOOST_REQUIRE(error == 0); + + BOOST_CHECK(ph == NULL); } BOOST_AUTO_TEST_CASE(test_run) diff --git a/tests/test_toolkit.hpp b/tests/test_toolkit.hpp index 03ac664..f0da4e7 100644 --- a/tests/test_toolkit.hpp +++ b/tests/test_toolkit.hpp @@ -14,6 +14,12 @@ #ifndef TEST_TOOLKIT_HPP #define TEST_TOOLKIT_HPP +// MSVC ONLY +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#endif #include "epanet2_2.h"