int main(int argc, char* argv[]) { // note that the MAXFNAME defined in constants.h as 259 char blank[] = ""; char* pathinp = blank; char* pathrpt = blank; char* pathout = blank; char* pathrain = blank; int err; if (argc < 3) writecon(FMT01); else { // --- extract file names from command line arguments pathinp = argv[1]; pathrpt = argv[2]; if (argc > 3) pathout = argv[3]; else pathout = blank; if (argc > 4) pathrain = argv[4]; else pathrain = blank; writecon(FMT02); } SWMMRunner swmmrunner(pathinp, pathrpt, pathout, pathrain); err = swmmrunner.Run(); if (err) return 1; return 0; }
void output_openOutFile(Project* project) // // Input: none // Output: none // Purpose: opens a project's binary output file. // { // --- close output file if already opened if (project->Fout.file != NULL) fclose(project->Fout.file); // --- else if file name supplied then set file mode to SAVE else if (strlen(project->Fout.name) != 0) project->Fout.mode = SAVE_FILE; // --- otherwise set file mode to SCRATCH & generate a name else { project->Fout.mode = SCRATCH_FILE; getTempFileName(project,project->Fout.name); } // --- try to open the file if ( (project->Fout.file = fopen(project->Fout.name, "w+b")) == NULL) { writecon(FMT14); project->ErrorCode = ERR_OUT_FILE; } }
void openFiles(char *f1, char *f2, char *f3) // // Input: f1 = name of input file // f2 = name of report file // f3 = name of binary output file // Output: none // Purpose: opens a project's input and report files. // { // --- initialize file pointers to NULL Finp.file = NULL; Frpt.file = NULL; Fout.file = NULL; // --- save file names sstrncpy(Finp.name, f1, MAXFNAME); sstrncpy(Frpt.name, f2, MAXFNAME); sstrncpy(Fout.name, f3, MAXFNAME); // --- check that file names are not identical if (strcomp(f1, f2) || strcomp(f1, f3) || strcomp(f2, f3)) { writecon(FMT11); ErrorCode = ERR_FILE_NAME; return; } // --- open input and report files if ((Finp.file = fopen(f1,"rt")) == NULL) { writecon(FMT12); writecon(f1); ErrorCode = ERR_INP_FILE; return; } if ((Frpt.file = fopen(f2,"wt")) == NULL) { writecon(FMT13); ErrorCode = ERR_RPT_FILE; return; } }
int writereport() /* **------------------------------------------------------ ** Input: none ** Output: returns error code ** Purpose: writes formatted output report to file ** ** Calls strcomp() from the EPANET.C module. **------------------------------------------------------ */ { char tflag; FILE *tfile; int errcode = 0; /* If no secondary report file specified then */ /* write formatted output to primary report file. */ Fprinterr = FALSE; if (Rptflag && strlen(Rpt2Fname) == 0 && RptFile != NULL) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* A secondary report file was specified */ else if (strlen(Rpt2Fname) > 0) { /* If secondary report file has same name as either input */ /* or primary report file then use primary report file. */ if (strcomp(Rpt2Fname,InpFname) || strcomp(Rpt2Fname,Rpt1Fname)) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* Otherwise write report to secondary report file. */ else { /* Try to open file */ tfile = RptFile; tflag = Rptflag; if ((RptFile = fopen(Rpt2Fname,"wt")) == NULL) { RptFile = tfile; Rptflag = tflag; errcode = 303; } /* Write full formatted report to file */ else { Rptflag = 1; writecon(FMT17); writecon(Rpt2Fname); writelogo(); if (Summaryflag) writesummary(); if (Energyflag) writeenergy(); errcode = writeresults(); fclose(RptFile); RptFile = tfile; Rptflag = tflag; } } } /* Special error handler for write-to-file error */ if (Fprinterr) errmsg(309); return(errcode); } /* End of writereport */