Give external apps access to binary output file (#407)

This commit is contained in:
Lew Rossman
2019-03-05 09:23:49 -05:00
parent b0a0014f19
commit 692955e3d2
3 changed files with 24 additions and 12 deletions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 02/08/2019
Last Updated: 03/05/2019
******************************************************************************
*/
@@ -819,6 +819,11 @@ int DLLEXPORT EN_closeQ(EN_Project p)
if (!p->Openflag) return 102;
closequal(p);
p->quality.OpenQflag = FALSE;
if (p->outfile.OutFile != NULL)
{
fclose(p->outfile.OutFile);
p->outfile.OutFile = NULL;
}
return 0;
}

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 01/01/2019
Last Updated: 03/05/2019
******************************************************************************
*/
@@ -95,6 +95,7 @@ int openhydfile(Project *pr)
{
if (pr->outfile.Hydflag == SCRATCH) return 0;
fclose(pr->outfile.HydFile);
pr->outfile.HydFile = NULL;
}
// Use Hydflag to determine the type of hydraulics file to use.

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 11/27/2018
Last Updated: 03/05/2019
******************************************************************************
*/
@@ -98,12 +98,7 @@ int copyreport(Project* pr, char *filename)
// Copy contents of project's report file
if (rpt->RptFile)
{
c = fgetc(rpt->RptFile);
while (c != EOF)
{
fputc(c, tfile);
c = fgetc(rpt->RptFile);
}
while ((c = fgetc(rpt->RptFile)) != EOF) fputc(c, tfile);
fclose(rpt->RptFile);
}
@@ -539,9 +534,6 @@ int writeresults(Project *pr)
// at each reporting time.
//-----------------------------------------------------------
// Return if no output file
if (outFile == NULL) return 106;
// Return if no nodes or links selected for reporting
// or if no node or link report variables enabled
if (!rpt->Nodeflag && !rpt->Linkflag) return errcode;
@@ -552,6 +544,13 @@ int writeresults(Project *pr)
for (j = LENGTH; j <= FRICTION; j++) nlv += rpt->Field[j].Enabled;
if (nnv == 0 && nlv == 0) return errcode;
// Return if no output file
if (outFile == NULL)
{
outFile = fopen(pr->outfile.OutFname, "r+b");
if (outFile == NULL) return 106;
}
// Allocate memory for output variables:
// m = larger of # node variables & # link variables
// n = larger of # nodes & # links
@@ -592,6 +591,13 @@ int writeresults(Project *pr)
}
}
// Free output file
if (outFile != NULL)
{
fclose(outFile);
outFile = NULL;
}
// Free allocated memory
for (j = 0; j < m; j++) free(x[j]);
free(x);