New function clearreport added (see issue #383)

The newly added `gettitle` and `settitle` functions were moved from the Reporting Functions section to the Project (formerly System) Functions section of epanet2.c and epanet.c.
This commit is contained in:
Lew Rossman
2019-02-08 12:07:56 -05:00
parent 140c95214e
commit 36b78f28d3
12 changed files with 211 additions and 141 deletions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 01/11/2019
Last Updated: 02/08/2019
******************************************************************************
*/
@@ -32,7 +32,7 @@
/********************************************************************
System Functions
Project Functions
********************************************************************/
@@ -237,6 +237,79 @@ int DLLEXPORT EN_open(EN_Project p, const char *inpFile, const char *rptFile,
return errcode;
}
int DLLEXPORT EN_gettitle(EN_Project p, char *line1, char *line2, char *line3)
/*----------------------------------------------------------------
** Input: None
** Output: line1, line2, line3 = project's title lines
** Returns: error code
** Purpose: retrieves the title lines of the project
**----------------------------------------------------------------
*/
{
if (!p->Openflag) return 102;
strcpy(line1, p->Title[0]);
strcpy(line2, p->Title[1]);
strcpy(line3, p->Title[2]);
return 0;
}
int DLLEXPORT EN_settitle(EN_Project p, char *line1, char *line2, char *line3)
/*----------------------------------------------------------------
** Input: line1, line2, line3 = project's title lines
** Returns: error code
** Purpose: sets the title lines of the project
**----------------------------------------------------------------
*/
{
if (!p->Openflag) return 102;
strncpy(p->Title[0], line1, TITLELEN);
strncpy(p->Title[1], line2, TITLELEN);
strncpy(p->Title[2], line3, TITLELEN);
return 123;
}
int DLLEXPORT EN_getcount(EN_Project p, int object, int *count)
/*----------------------------------------------------------------
** Input: object = type of object to count (see EN_CountType)
** Output: count = number of objects of the specified type
** Returns: error code
** Purpose: Retrieves number of network objects of a given type
**----------------------------------------------------------------
*/
{
Network *net = &p->network;
*count = 0;
if (!p->Openflag) return 102;
switch (object)
{
case EN_NODECOUNT:
*count = net->Nnodes;
break;
case EN_TANKCOUNT:
*count = net->Ntanks;
break;
case EN_LINKCOUNT:
*count = net->Nlinks;
break;
case EN_PATCOUNT:
*count = net->Npats;
break;
case EN_CURVECOUNT:
*count = net->Ncurves;
break;
case EN_CONTROLCOUNT:
*count = net->Ncontrols;
break;
case EN_RULECOUNT:
*count = net->Nrules;
break;
default:
return 251;
}
return 0;
}
int DLLEXPORT EN_saveinpfile(EN_Project p, const char *filename)
/*----------------------------------------------------------------
** Input: filename = name of file to which project is saved
@@ -791,6 +864,19 @@ int DLLEXPORT EN_report(EN_Project p)
return errcode;
}
int DLLEXPORT EN_clearreport(EN_Project p)
/*----------------------------------------------------------------
** Input: none
** Output: none
** Returns: error code
** Purpose: clears the contents of a project's report file
**----------------------------------------------------------------
*/
{
if (!p->Openflag) return 102;
return clearreport(p);
}
int DLLEXPORT EN_resetreport(EN_Project p)
/*----------------------------------------------------------------
** Input: none
@@ -870,48 +956,6 @@ int DLLEXPORT EN_getversion(int *version)
return 0;
}
int DLLEXPORT EN_getcount(EN_Project p, int object, int *count)
/*----------------------------------------------------------------
** Input: object = type of object to count (see EN_CountType)
** Output: count = number of objects of the specified type
** Returns: error code
** Purpose: Retrieves number of network objects of a given type
**----------------------------------------------------------------
*/
{
Network *net = &p->network;
*count = 0;
if (!p->Openflag) return 102;
switch (object)
{
case EN_NODECOUNT:
*count = net->Nnodes;
break;
case EN_TANKCOUNT:
*count = net->Ntanks;
break;
case EN_LINKCOUNT:
*count = net->Nlinks;
break;
case EN_PATCOUNT:
*count = net->Npats;
break;
case EN_CURVECOUNT:
*count = net->Ncurves;
break;
case EN_CONTROLCOUNT:
*count = net->Ncontrols;
break;
case EN_RULECOUNT:
*count = net->Nrules;
break;
default:
return 251;
}
return 0;
}
int DLLEXPORT EN_geterror(int errcode, char *errmsg, int maxLen)
/*----------------------------------------------------------------
** Input: errcode = an error or warnng code
@@ -991,37 +1035,6 @@ int DLLEXPORT EN_getstatistic(EN_Project p, int type, double *value)
return 0;
}
int DLLEXPORT EN_gettitle(EN_Project p, char *titleline1, char *titleline2, char *titleline3)
/*----------------------------------------------------------------
** Input: None
** Output: titleline1-3 = project's title lines
** Returns: error code
** Purpose: retrieves the title lines of the project
**----------------------------------------------------------------
*/
{
if (!p->Openflag) return 102;
strcpy(titleline1, p->Title[0]);
strcpy(titleline2, p->Title[1]);
strcpy(titleline3, p->Title[2]);
return 0;
}
int DLLEXPORT EN_settitle(EN_Project p, char *titleline1, char *titleline2, char *titleline3)
/*----------------------------------------------------------------
** Input: titleline1-3 = project's title lines
** Returns: error code
** Purpose: sets the title lines of the project
**----------------------------------------------------------------
*/
{
if (!p->Openflag) return 102;
strncpy(p->Title[0], titleline1, TITLELEN);
strncpy(p->Title[1], titleline2, TITLELEN);
strncpy(p->Title[2], titleline3, TITLELEN);
return 123;
}
/********************************************************************
Analysis Options Functions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 01/09/2019
Last Updated: 02/08/2019
******************************************************************************
*/
#ifndef __APPLE__
@@ -47,7 +47,7 @@ void removetmpfiles()
/********************************************************************
System Functions
Project Functions
********************************************************************/
@@ -102,6 +102,21 @@ int DLLEXPORT ENopen(const char *inpFile, const char *rptFile, const char *outFi
return errcode;
}
int DLLEXPORT ENgettitle(char *line1, char *line2, char *line3)
{
return EN_gettitle(_defaultProject, line1, line2, line3) ;
}
int DLLEXPORT ENsettitle(char *line1, char *line2, char *line3)
{
return EN_settitle(_defaultProject, line1, line2, line3) ;
}
int DLLEXPORT ENgetcount(int object, int *count)
{
return EN_getcount(_defaultProject, object, count);
}
int DLLEXPORT ENsaveinpfile(const char *filename)
{
return EN_saveinpfile(_defaultProject, filename);
@@ -174,6 +189,8 @@ int DLLEXPORT ENwriteline(char *line) { return EN_writeline(_defaultProject, lin
int DLLEXPORT ENreport() { return EN_report(_defaultProject); }
int DLLEXPORT ENclearreport() { return EN_clearreport(_defaultProject); }
int DLLEXPORT ENresetreport() { return EN_resetreport(_defaultProject); }
int DLLEXPORT ENsetreport(char *format) { return EN_setreport(_defaultProject, format); }
@@ -185,11 +202,6 @@ int DLLEXPORT ENsetstatusreport(int level)
int DLLEXPORT ENgetversion(int *version) { return EN_getversion(version); }
int DLLEXPORT ENgetcount(int object, int *count)
{
return EN_getcount(_defaultProject, object, count);
}
int DLLEXPORT ENgeterror(int errcode, char *errmsg, int maxLen)
{
return EN_geterror(errcode, errmsg, maxLen);
@@ -203,16 +215,6 @@ int DLLEXPORT ENgetstatistic(int type, EN_API_FLOAT_TYPE *value)
return errcode;
}
int DLLEXPORT ENgettitle(char *titleline1, char *titleline2, char *titleline3)
{
return EN_gettitle(_defaultProject, titleline1, titleline2, titleline3) ;
}
int DLLEXPORT ENsettitle(char *titleline1, char *titleline2, char *titleline3)
{
return EN_settitle(_defaultProject, titleline1, titleline2, titleline3) ;
}
/********************************************************************
Analysis Options Functions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/10/2018
Last Updated: 02/08/2019
******************************************************************************
*/
@@ -84,6 +84,18 @@ int EXPORT_PY_API proj_open(Handle ph, const char *inpFile, const char *rptFile,
return error_set(pr->error, EN_open(pr->project, inpFile, rptFile, binOutFile));
}
int EXPORT_PY_API proj_gettitle(Handle ph, char *line1, char *line2, char *line3)
{
handle_t *pr = (handle_t *)ph;
return error_set(pr->error, EN_gettitle(pr->project, line1, line2, line3));
}
int EXPORT_PY_API proj_settitle(Handle ph, const char *line1, const char *line2, const char *line3)
{
handle_t *pr = (handle_t *)ph;
return error_set(pr->error, EN_settitle(pr->project, line1, line2, line3));
}
int EXPORT_PY_API proj_savefile(Handle ph, const char *filename)
{
handle_t *pr = (handle_t *)ph;
@@ -213,6 +225,12 @@ int EXPORT_PY_API rprt_writeresults(Handle ph)
return error_set(pr->error, EN_report(pr->project));
}
int EXPORT_PY_API rprt_clear(Handle ph)
{
handle_t *pr = (handle_t *)ph;
return error_set(pr->error, EN_clearreport(pr->project));
}
int EXPORT_PY_API rprt_reset(Handle ph)
{
handle_t *pr = (handle_t *)ph;

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 11/27/2018
Last Updated: 02/08/2019
******************************************************************************
*/
#ifndef FUNCS_H
@@ -108,6 +108,7 @@ int checkrules(Project *, long);
// ------- REPORT.C -----------------
int clearreport(Project *);
int writereport(Project *);
void writelogo(Project *);
void writesummary(Project *);

View File

@@ -57,6 +57,21 @@ static int checklimits(Report *, double *, int, int);
static char *fillstr(char *, char, int);
static int getnodetype(Network *, int);
int clearreport(Project *pr)
/*
**------------------------------------------------------
** Input: none
** Output: returns error code
** Purpose: clears contents of a project's report file
**------------------------------------------------------
*/
{
Report *rpt = &pr->report;
if (rpt->RptFile == NULL) return 0;
if (freopen(rpt->Rpt1Fname, "w", rpt->RptFile) == NULL) return 303;
writelogo(pr);
return 0;
}
int writereport(Project *pr)
/*