diff --git a/run/main.c b/run/main.c index ea0a91c..793fffa 100644 --- a/run/main.c +++ b/run/main.c @@ -12,7 +12,6 @@ */ #include - #include "epanet2.h" void writeConsole(char *s) diff --git a/src/epanet.c b/src/epanet.c index a6df228..29462bc 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -11,17 +11,12 @@ ****************************************************************************** */ -#ifdef _DEBUG - #define _CRTDBG_MAP_ALLOC - #include - #include -#else - #include -#endif - #include +#include #include - +#ifndef __APPLE__ +#include +#endif #include #include @@ -221,24 +216,26 @@ int DLLEXPORT EN_open(EN_Project p, const char *inpFile, const char *rptFile, ERRCODE(netsize(p)); ERRCODE(allocdata(p)); - if (!errcode) { - // Read input data - ERRCODE(getdata(p)); + // 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 + // Write input summary to report file + if (!errcode) + { if (p->report.Summaryflag) writesummary(p); writetime(p, FMT104); p->Openflag = TRUE; @@ -282,7 +279,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 **---------------------------------------------------------------- @@ -843,7 +840,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 3d11608..935d6c4 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -10,15 +10,11 @@ Last Updated: 03/17/2019 ****************************************************************************** */ - -#ifdef _DEBUG - #define _CRTDBG_MAP_ALLOC - #include - #include +#ifndef __APPLE__ +#include #else - #include +#include #endif - #include #include "types.h" diff --git a/src/epanet_py.c b/src/epanet_py.c index e84fdc9..4c16cbf 100644 --- a/src/epanet_py.c +++ b/src/epanet_py.c @@ -26,7 +26,6 @@ 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 c3f91e2..95ac8dd 100755 --- a/src/hash.c +++ b/src/hash.c @@ -11,9 +11,12 @@ ****************************************************************************** */ +#ifndef __APPLE__ +#include +#else #include +#endif #include - #include "hash.h" #define HASHTABLEMAXSIZE 128000 diff --git a/src/hydcoeffs.c b/src/hydcoeffs.c index 4b3583d..b6c002c 100644 --- a/src/hydcoeffs.c +++ b/src/hydcoeffs.c @@ -11,9 +11,13 @@ ****************************************************************************** */ -#include #include #include +#ifndef __APPLE__ +#include +#else +#include +#endif #include #include "types.h" diff --git a/src/hydraul.c b/src/hydraul.c index c442ac6..703f7b7 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -11,9 +11,13 @@ ****************************************************************************** */ -#include #include #include +#ifndef __APPLE__ +#include +#else +#include +#endif #include #include "types.h" diff --git a/src/hydsolver.c b/src/hydsolver.c index 90c93e1..3c0694a 100644 --- a/src/hydsolver.c +++ b/src/hydsolver.c @@ -12,9 +12,13 @@ ****************************************************************************** */ -#include #include #include +#ifndef __APPLE__ +#include +#else +#include +#endif #include #include "types.h" diff --git a/src/hydstatus.c b/src/hydstatus.c index 5905337..f7edb6b 100644 --- a/src/hydstatus.c +++ b/src/hydstatus.c @@ -12,7 +12,6 @@ Last Updated: 11/27/2018 */ #include - #include "types.h" #include "funcs.h" diff --git a/src/inpfile.c b/src/inpfile.c index 994830a..45b5aab 100644 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -13,7 +13,11 @@ 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 4cafa13..fe606d9 100644 --- a/src/input1.c +++ b/src/input1.c @@ -3,30 +3,26 @@ 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 -#include +#ifndef __APPLE__ +#include +#endif #include "types.h" #include "funcs.h" #include "hash.h" #include "text.h" - +#include // Default values #define MAXITER 200 // Default max. # hydraulic iterations @@ -60,7 +56,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 @@ -106,7 +102,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 @@ -357,7 +353,7 @@ int inittanks(Project *pr) */ { Network *net = &pr->network; - + int i, j, n = 0; double a; int errcode = 0, levelerr; @@ -550,7 +546,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++) @@ -648,7 +644,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]; @@ -657,7 +653,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 e4d2d85..2820e35 100644 --- a/src/input2.c +++ b/src/input2.c @@ -10,16 +10,13 @@ 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" @@ -59,7 +56,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 @@ -150,7 +147,7 @@ int readdata(Project *pr) inperr, errsum; // Error code & total error count // Allocate input buffer - parser->X = (double *)calloc(MAXTOKS + 1, sizeof(double)); + parser->X = (double *)calloc(MAXTOKS, sizeof(double)); ERRCODE(MEMCHECK(parser->X)); if (errcode) return errcode; @@ -178,7 +175,7 @@ int readdata(Project *pr) while (fgets(line, MAXLINE, parser->InFile) != NULL) { // Make copy of line and scan for tokens - strncpy(wline, line, MAXLINE); + strcpy(wline, line); parser->Ntokens = gettokens(wline, parser->Tok, MAXTOKS, parser->Comment); // Skip blank lines and those filled with a comment @@ -249,10 +246,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); @@ -400,7 +397,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; @@ -410,7 +407,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) { @@ -421,7 +418,7 @@ int updatepumpparams(Project *pr, int pumpindex) q2 = curve->X[2]; h2 = curve->Y[2]; } - + // Custom pump curve else { @@ -434,7 +431,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) { @@ -464,7 +461,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; @@ -590,7 +587,7 @@ int unlinked(Project *pr) Network *net = &pr->network; int *marked; int i, err, errcode; - + errcode = 0; err = 0; @@ -599,19 +596,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); @@ -641,7 +638,7 @@ int getpatterns(Project *pr) SFloatlist *f; STmplist *tmppattern; Spattern *pattern; - + // Start at head of the list of patterns tmppattern = parser->Patlist; @@ -699,7 +696,7 @@ int getcurves(Project *pr) { Network *net = &pr->network; Parser *parser = &pr->parser; - + int i, j; double x; char errmsg[MAXMSG+1]; @@ -830,14 +827,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) { @@ -871,7 +868,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 @@ -879,7 +876,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment) } } return n; -} +} double hour(char *time, char *units) /* @@ -917,7 +914,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 @@ -936,7 +933,7 @@ double hour(char *time, char *units) else return (y[0] + 12.0); } return -1.0; -} +} int getfloat(char *s, double *y) /* @@ -982,14 +979,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 d00a6e9..fb35da2 100644 --- a/src/input3.c +++ b/src/input3.c @@ -10,16 +10,13 @@ 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 871b4c8..55552ed 100755 --- a/src/mempool.c +++ b/src/mempool.c @@ -15,7 +15,9 @@ */ #include - +#ifndef __APPLE__ +#include +#endif #include "mempool.h" /* diff --git a/src/output.c b/src/output.c index d86fe50..fd92077 100644 --- a/src/output.c +++ b/src/output.c @@ -11,9 +11,13 @@ 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 8355588..fd4cb8d 100644 --- a/src/project.c +++ b/src/project.c @@ -11,18 +11,14 @@ ****************************************************************************** */ -#ifdef _DEBUG -#define _CRTDBG_MAP_ALLOC -#include -#include +#include +#include +#ifndef __APPLE__ +#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 06e1997..de27f63 100644 --- a/src/quality.c +++ b/src/quality.c @@ -11,9 +11,13 @@ 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 0afac47..0805a21 100644 --- a/src/qualreact.c +++ b/src/qualreact.c @@ -13,7 +13,6 @@ Last Updated: 11/27/2018 #include #include - #include "types.h" // Exported functions diff --git a/src/qualroute.c b/src/qualroute.c index 03e3545..72bb66f 100644 --- a/src/qualroute.c +++ b/src/qualroute.c @@ -11,10 +11,13 @@ Last Updated: 11/27/2018 ****************************************************************************** */ -#include #include +#ifndef __APPLE__ +#include +#else +#include +#endif #include - #include "mempool.h" #include "types.h" diff --git a/src/report.c b/src/report.c index dd4ff3d..5605ffb 100644 --- a/src/report.c +++ b/src/report.c @@ -11,10 +11,13 @@ ****************************************************************************** */ -#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 eee5568..7e9945f 100644 --- a/src/rules.c +++ b/src/rules.c @@ -11,9 +11,13 @@ ****************************************************************************** */ -#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 3446384..510bb3e 100755 --- a/src/smatrix.c +++ b/src/smatrix.c @@ -18,11 +18,16 @@ 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 38d6607..4329414 100755 --- a/src/types.h +++ b/src/types.h @@ -14,10 +14,8 @@ #ifndef TYPES_H #define TYPES_H -#include - #include "hash.h" - +#include /* ------------------------------------------- diff --git a/src/util/errormanager.c b/src/util/errormanager.c index b674fe6..5a9876c 100644 --- a/src/util/errormanager.c +++ b/src/util/errormanager.c @@ -10,7 +10,13 @@ // 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 fd9a8d8..64c7c23 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,19 +19,18 @@ 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 917b523..f7120f1 100644 --- a/tests/test_analysis.cpp +++ b/tests/test_analysis.cpp @@ -11,6 +11,7 @@ ****************************************************************************** */ +//#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_project.cpp b/tests/test_project.cpp index 6ae1143..6f0b68c 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -56,47 +56,35 @@ BOOST_AUTO_TEST_CASE(test_save) { int error; - EN_Project ph = NULL; + EN_Project ph_save; - error = EN_createproject(&ph); - BOOST_REQUIRE(error == 0); - - error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT); + 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, DATA_PATH_TMP); + error = EN_saveinpfile(ph_save, "test_reopen.inp"); BOOST_REQUIRE(error == 0); - BOOST_CHECK(boost::filesystem::exists(DATA_PATH_TMP) == true); + BOOST_CHECK(boost::filesystem::exists("test_reopen.inp") == true); - error = EN_close(ph); + error = EN_close(ph_save); BOOST_REQUIRE(error == 0); - - error = EN_deleteproject(&ph); - BOOST_REQUIRE(error == 0); - - BOOST_CHECK(ph == NULL); + EN_deleteproject(&ph_save); } BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save")) { int error; - EN_Project ph = NULL; + EN_Project ph_reopen; - error = EN_createproject(&ph); - BOOST_REQUIRE(error == 0); + EN_createproject(&ph_reopen); + error = EN_open(ph_reopen, "test_reopen.inp", DATA_PATH_RPT, DATA_PATH_OUT); + BOOST_REQUIRE(error == 0); - 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); + error = EN_close(ph_reopen); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph_reopen); } BOOST_AUTO_TEST_CASE(test_run) diff --git a/tests/test_toolkit.hpp b/tests/test_toolkit.hpp index f0da4e7..03ac664 100644 --- a/tests/test_toolkit.hpp +++ b/tests/test_toolkit.hpp @@ -14,12 +14,6 @@ #ifndef TEST_TOOLKIT_HPP #define TEST_TOOLKIT_HPP -// MSVC ONLY -#ifdef _DEBUG - #define _CRTDBG_MAP_ALLOC - #include - #include -#endif #include "epanet2_2.h"