Merge remote-tracking branch 'upstream/dev' into dev-swig-redux

This commit is contained in:
Michael Tryby
2018-12-10 17:17:11 -05:00
3 changed files with 83 additions and 102 deletions

View File

@@ -3,121 +3,91 @@
Project: OWA EPANET Project: OWA EPANET
Version: 2.2 Version: 2.2
Module: main.c Module: main.c
Description: implementation of the CLI for EPANET Description: main stub for a command line executable version of EPANET
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 11/27/2018 Last Updated: 12/07/2018
****************************************************************************** ******************************************************************************
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "epanet2.h" #include "epanet2.h"
#define MAXMSG 255 /* Max. # characters in message text */ void writeConsole(char *s)
#define MAXWARNCODE 99 {
/* text copied here, no more need of include "text.h" */ fprintf(stdout, "\r%s", s);
#define FMT01 "\nEPANET Version %d.%d.%d\n" fflush(stdout);
#define FMT03 "\nUsage:\n %s <input_filename> <report_filename> [<binary_filename>]\n" }
#define FMT09 "\n\nEPANET completed.\n"
#define FMT10 "\nEPANET completed. There are warnings.\n"
#define FMT11 "\nEPANET completed. There are errors.\n"
void writeConsole(char *s);
/*
----------------------------------------------------------------
Entry point used to compile a stand-alone executable.
----------------------------------------------------------------
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
/*-------------------------------------------------------------- /*--------------------------------------------------------------
** Input: argc = number of command line arguments ** Input: argc = number of command line arguments
** *argv[] = array of command line arguments ** *argv[] = array of command line arguments
** Output: none ** Output: none
** Purpose: main program segment ** Purpose: main program stub for command line EPANET
** **
** Command line for stand-alone operation is: ** Command line for stand-alone operation is:
** progname f1 f2 f3 ** progname f1 f2 f3
** where progname = name of executable this code was compiled to, ** where progname = name of executable this code was compiled to,
** f1 = name of input file, ** f1 = name of input file,
** f2 = name of report file (optional, stdout if left blank) ** f2 = name of report file
** f3 = name of binary output file (optional, nullfile if left blank). ** f3 = name of binary output file (optional).
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
char *f1,*f2,*f3; char *f1,*f2,*f3;
char blank[] = ""; char blank[] = "";
char errmsg[MAXMSG+1]=""; char errmsg[256] = "";
int errcode; int errcode;
int version; int version;
int major; int major;
int minor; int minor;
int patch; int patch;
/* get version from DLL and trasform in Major.Minor.Patch format // Check for proper number of command line arguments
instead of hardcoded version */ if (argc < 3)
{
printf(
"\nUsage:\n %s <input_filename> <report_filename> [<binary_filename>]\n",
argv[0]);
return 0;
}
// Get version number and display in Major.Minor.Patch format
ENgetversion(&version); ENgetversion(&version);
major= version/10000; major = version/10000;
minor= (version%10000)/100; minor = (version%10000)/100;
patch= version%100; patch = version%100;
printf(FMT01, major, minor, patch); printf("\n... Running EPANET Version %d.%d.%d\n", major, minor, patch);
/* Check for proper number of command line arguments */ // Assign pointers to file names
if (argc < 2) {
printf(FMT03, argv[0]);
return(1);
}
/* set inputfile name */
f1 = argv[1]; f1 = argv[1];
if (argc > 2) {
/* set rptfile name */
f2 = argv[2]; f2 = argv[2];
} if (argc > 3) f3 = argv[3];
else { else f3 = blank;
/* use stdout for rptfile */
f2 = blank;
}
if (argc > 3) {
/* set binary output file name */
f3 = argv[3];
}
else {
/* NO binary output*/
f3 = blank;
}
/* Call the main control function */ // Run EPANET
errcode = ENepanet(f1,f2,f3,NULL); errcode = ENepanet(f1, f2, f3, &writeConsole);
/* Error/Warning check */ // Blank out the last progress message
if (errcode == 0) { printf("\r ");
/* no errors */
printf(FMT09); // Check for errors/warnings and report accordingly
return(0); if (errcode == 0)
{
printf("\n... EPANET ran successfully.\n");
return 0;
} }
else { else if (errcode < 100)
if (errcode > MAXWARNCODE) printf("\n Fatal Error: "); {
ENgeterror(errcode, errmsg, MAXMSG); printf("\n... EPANET ran with warnings - check the Status Report.\n");
printf("%s\n", errmsg); return 0;
if (errcode > MAXWARNCODE) {
// error //
printf(FMT11);
return(errcode);
} }
else { else
// warning // {
printf(FMT10); ENgeterror(errcode, errmsg, 255);
return(0); printf("\n... EPANET failed with %s.\n", errmsg);
return 100;
} }
} }
} /* End of main */

View File

@@ -799,9 +799,13 @@ void pumpcoeff(Project *pr, int k)
// Adjust head loss coefficients for pump speed // Adjust head loss coefficients for pump speed
h0 = SQR(setting) * pump->H0; h0 = SQR(setting) * pump->H0;
n = pump->N; n = pump->N;
if (ABS(n - 1.0) < TINY) n = 1.0;
r = pump->R * pow(setting, 2.0 - n); r = pump->R * pow(setting, 2.0 - n);
// Compute head loss and its gradient // Compute head loss and its gradient
// ... pump curve is nonlinear
if (n != 1.0)
{
// ... use linear approx. to pump curve for small flows // ... use linear approx. to pump curve for small flows
qa = pow(hyd->RQtol / n / r, 1.0 / (n - 1.0)); qa = pow(hyd->RQtol / n / r, 1.0 / (n - 1.0));
if (q <= qa) if (q <= qa)
@@ -816,6 +820,13 @@ void pumpcoeff(Project *pr, int k)
hloss = h0 + hgrad * hyd->LinkFlow[k] / n; hloss = h0 + hgrad * hyd->LinkFlow[k] / n;
} }
} }
// ... pump curve is linear
else
{
hgrad = r;
hloss = h0 + hgrad * hyd->LinkFlow[k];
}
}
// P and Y coeffs. // P and Y coeffs.
hyd->P[k] = 1.0 / hgrad; hyd->P[k] = 1.0 / hgrad;

View File

@@ -792,8 +792,8 @@ char *geterrmsg(int errcode, char *msg)
*/ */
{ {
switch (errcode) { /* Warnings */ switch (errcode) { /* Warnings */
#define DAT(code,enumer,string) case code: strcpy(msg, string); break; //#define DAT(code,enumer,string) case code: strcpy(msg, string); break;
//#define DAT(code,enumer,string) case code: sprintf(msg, "Error %d: %s", code, string); break; #define DAT(code,enumer,string) case code: sprintf(msg, "Error %d: %s", code, string); break;
#include "errors.dat" #include "errors.dat"
#undef DAT #undef DAT
default: default: